Slide 1

Slide 1 text

Jake Wharton AutoValue Extensions

Slide 2

Slide 2 text

AutoValue @AutoValue public abstract class Payment {
 public abstract long id();
 public abstract long amount();
 public abstract Currency currency();
 public abstract String note();
 }X

Slide 3

Slide 3 text

AutoValue @AutoValue
 public abstract class Payment { 
 public static Payment create(
 long id, long amount, Currency currency, String note) {
 return new AutoValue_Payment(id, amount, currency, note);
 }Z
 
 public abstract long id();
 public abstract long amount();
 public abstract Currency currency();
 public abstract String note();
 }X

Slide 4

Slide 4 text

AutoValue @AutoValue
 public abstract class Payment { 
 public static Payment create(
 long id, long amount, Currency currency, String note) {
 return new AutoValue_Payment(id, amount, currency, note);
 }Z
 
 public abstract long id();
 public abstract long amount();
 public abstract Currency currency();
 public abstract String note();
 }X

Slide 5

Slide 5 text

AutoValue Extensions @AutoValue
 public abstract class Payment { 
 public static Payment create(
 long id, long amount, Currency currency, String note) {
 return new AutoValue_Payment(id, amount, currency, note);
 }Z
 
 public abstract long id();
 public abstract long amount();
 public abstract Currency currency();
 public abstract String note();
 }X final class AutoValue_Payment extends Payment {
 private final long id;
 private final long amount;
 private final Currency currency;
 private final String note;
 
 AutoValue_Payment(long id, long amount, Currency currency, String note) {
 this.id = id;
 this.amount = amount;
 this.currency = currency;
 this.note = note;
 }Q
 
 @Override public long id() {
 return id;
 }Y
 @Override public long amount() {
 return amount;
 }Z
 @Override public Currency currency() {
 return currency;
 }U
 @Override public String note() {
 return note;
 }W
 
 @Override public String toString() {
 return "Payment{" +
 "id=" + id +
 ", amount=" + amount +
 ", currency=" + currency +
 ", note='" + note + '\'' +
 '}';
 }E
 
 @Override public boolean equals(Object o) {
 if (this == o) return true;
 if (!(o instanceof Payment)) return false;
 Payment other = (Payment) o;
 return id == other.id
 && amount == other.amount
 && currency.equals(other.currency)
 && note.equals(other.note);
 }R
 
 @Override public int hashCode() {
 int result = (int) (id ^ (id >>> 32));
 result = 31 * result + (int) (amount ^ (amount >>> 32));
 result = 31 * result + currency.hashCode();
 result = 31 * result + note.hashCode();
 return result;
 }T
 }X

Slide 6

Slide 6 text

@AutoValue public abstract class Payment {
 public abstract long id();
 public abstract long amount();
 public abstract Currency currency();
 public abstract String note();
 }X AutoValue Extensions

Slide 7

Slide 7 text

@AutoValue public abstract class Payment {
 public abstract long id();
 public abstract long amount();
 public abstract Currency currency();
 public abstract String note();
 }X Ok, awesome! Now how do I use it with ? Parcelable AutoValue Extensions

Slide 8

Slide 8 text

@AutoValue public abstract class Payment {
 public abstract long id();
 public abstract long amount();
 public abstract Currency currency();
 public abstract String note();
 }X Ok, awesome! Now how do I use it with ? Parcelable Gson AutoValue Extensions

Slide 9

Slide 9 text

@AutoValue public abstract class Payment {
 public abstract long id();
 public abstract long amount();
 public abstract Currency currency();
 public abstract String note();
 }X Ok, awesome! Now how do I use it with ? Parcelable Gson Cursors AutoValue Extensions

Slide 10

Slide 10 text

@AutoValue public abstract class Payment {
 public abstract long id();
 public abstract long amount();
 public abstract Currency currency();
 public abstract String note();
 }X Ok, awesome! Now how do I use it with ? Parcelable Gson Cursors (whatever) AutoValue Extensions

Slide 11

Slide 11 text

@AutoValue public abstract class Payment {
 public abstract long id();
 public abstract long amount();
 public abstract Currency currency();
 public abstract String note();
 }X Ok, awesome! Now how do I use it with ? Parcelable Gson Cursors (whatever) AutoValue Extensions

Slide 12

Slide 12 text

AutoValue @AutoValue public abstract class Payment3{
 public abstract long id();
 public abstract long amount();
 public abstract Currency currency();
 public abstract String note();
 }X AutoValue Extensions

Slide 13

Slide 13 text

AutoValue Extensions @AutoValue public abstract class Payment1implements2Parcelable3{3
 public abstract long id();
 public abstract long amount();
 public abstract Currency currency();
 public abstract String note();
 }X /* abstract properties */

Slide 14

Slide 14 text

AutoValue Extensions @AutoValue public abstract class Payment1implements2Parcelable3{3 /* abstract properties */ }X final class AutoValue_Payment1extends2Payment { /* value type implementation */ }Y

Slide 15

Slide 15 text

AutoValue Extensions final class AutoValue_Payment1extends2$AutoValue_Payment { /* parcelable implementation */ }Z abstract class $AutoValue_Payment1extends2Payment { /* value type implementation */ }Y @AutoValue public abstract class Payment1implements2Parcelable { /* abstract properties */ }X

Slide 16

Slide 16 text

final class AutoValue_Payment1extends2$AutoValue_Payment { /* parcelable implementation */ }Z /* abstract properties */ abstract class $AutoValue_Payment1extends2Payment { /* value type implementation */ }Y AutoValue Extensions @AutoValue public abstract class Payment1implements2Parcelable3{3
 public abstract long id();
 public abstract long amount();
 public abstract Currency currency();
 public abstract String note();
 }X /* abstract properties */

Slide 17

Slide 17 text

final class AutoValue_Payment1extends2$AutoValue_Payment { /* parcelable implementation */ }Z /* abstract properties */ abstract class $AutoValue_Payment1extends2Payment { /* value type implementation */ }Y AutoValue Extensions @AutoValue public abstract class Payment1implements2Parcelable3{3
 public abstract long id();
 public abstract long amount();
 public abstract Currency currency();
 @Redacted public abstract String note();
 }X /* abstract properties */

Slide 18

Slide 18 text

AutoValue Extensions final class AutoValue_Payment1extends2$AutoValue_Payment { /* parcelable implementation */ }Z abstract class $AutoValue_Payment1extends2Payment { /* value type implementation */ }Y @AutoValue public abstract class Payment1implements2Parcelable { /* abstract properties */ }X

Slide 19

Slide 19 text

AutoValue Extensions final class AutoValue_Payment1extends2$AutoValue_Payment { /* parcelable implementation */ }Z abstract class $AutoValue_Payment1extends2$$AutoValue_Payment { /* value type implementation (without toString) */ }Y abstract class $$AutoValue_Payment1extends2Payment { /* redacted toString implementation */ }Y @AutoValue public abstract class Payment1implements2Parcelable { /* abstract properties */ }X

Slide 20

Slide 20 text

AutoValue Extensions final class AutoValue_Payment1extends2$AutoValue_Payment { /* parcelable implementation */ }Z abstract class $AutoValue_Payment1extends2$$AutoValue_Payment { /* value type implementation (without toString) */ }Y abstract class $$AutoValue_Payment1extends2Payment { /* redacted toString implementation */ }Y @AutoValue public abstract class Payment1implements2Parcelable { /* abstract properties */ }X

Slide 21

Slide 21 text

AutoValue Extensions final class AutoValue_Payment1extends2$AutoValue_Payment { /* parcelable implementation */ }Z abstract class $AutoValue_Payment1extends2$$AutoValue_Payment { /* value type implementation (without toString) */ }Y abstract class $$AutoValue_Payment1extends2Payment { /* redacted toString implementation */ }Y @AutoValue public abstract class Payment1implements2Parcelable { /* abstract properties */ }X

Slide 22

Slide 22 text

AutoValue Extensions final class AutoValue_Payment1extends2$AutoValue_Payment { /* parcelable implementation */ }Z abstract class $AutoValue_Payment1extends2$$AutoValue_Payment { /* value type implementation (without toString) */ }Y abstract class $$AutoValue_Payment1extends2Payment { /* redacted toString implementation */ }Y @AutoValue public abstract class Payment1implements2Parcelable { /* abstract properties */ }X

Slide 23

Slide 23 text

AutoValue Extensions final class AutoValue_Payment1extends2$AutoValue_Payment { /* parcelable implementation */ }Z abstract class $AutoValue_Payment1extends2$$AutoValue_Payment { /* value type implementation (without toString) */ }Y abstract class $$AutoValue_Payment1extends2Payment { /* redacted toString implementation */ }Y @AutoValue public abstract class Payment1implements2Parcelable { /* abstract properties */ }X

Slide 24

Slide 24 text

Available Extensions • Parcelable: github.com/rharter/auto-value-parcel • Redacted: github.com/square/auto-value-redacted • Gson: github.com/rharter/auto-value-gson • Moshi: github.com/rharter/auto-value-moshi • Cursor: github.com/gabrielittner/auto-value-cursor • "with"ers: github.com/gabrielittner/auto-value-with

Slide 25

Slide 25 text

Extension API

Slide 26

Slide 26 text

Extension API public abstract class AutoValueExtension {
 public boolean applicable(Context context) {
 return false;
 }
 
 public boolean mustBeFinal(Context context) {
 return false;
 }
 
 public Set consumeProperties(Context context) {
 return Collections.emptySet();
 }
 
 public abstract String generateClass(Context context, String className, String classToExtend, boolean isFinal);
 }

Slide 27

Slide 27 text

Extension API public abstract class AutoValueExtension {
 public boolean applicable(Context context) {
 return false;
 }X
 
 public boolean mustBeFinal(Context context) {
 return false;
 }
 
 public Set consumeProperties(Context context) {
 return Collections.emptySet();
 }
 
 public abstract String generateClass(Context context, String className, String classToExtend, boolean isFinal);
 }

Slide 28

Slide 28 text

Extension API public boolean applicable(Context context)

Slide 29

Slide 29 text

Extension API public boolean applicable(Context context) Parcelable extension @AutoValue public abstract class Payment {}

Slide 30

Slide 30 text

Extension API public boolean applicable(Context context) Parcelable extension @AutoValue public abstract class Payment {} false

Slide 31

Slide 31 text

Extension API public boolean applicable(Context context) Parcelable extension Parcelable extension @AutoValue public abstract class Payment {} @AutoValue public abstract class Payment implements Parcelable {} false

Slide 32

Slide 32 text

Extension API public boolean applicable(Context context) Parcelable extension Parcelable extension @AutoValue public abstract class Payment {} @AutoValue public abstract class Payment implements Parcelable {} false true

Slide 33

Slide 33 text

Extension API public boolean applicable(Context context) Parcelable extension Parcelable extension Redacted extension @AutoValue public abstract class Payment {} @AutoValue public abstract class Payment implements Parcelable {} @AutoValue public abstract class Payment { public abstract String note(); } false true

Slide 34

Slide 34 text

Extension API public boolean applicable(Context context) Parcelable extension Parcelable extension Redacted extension @AutoValue public abstract class Payment {} @AutoValue public abstract class Payment implements Parcelable {} @AutoValue public abstract class Payment { public abstract String note(); } false true false

Slide 35

Slide 35 text

Extension API public boolean applicable(Context context) Parcelable extension Parcelable extension Redacted extension Redacted extension @AutoValue public abstract class Payment {} @AutoValue public abstract class Payment implements Parcelable {} @AutoValue public abstract class Payment { public abstract String note(); } @AutoValue public abstract class Payment { @Redacted public abstract String note(); } false true false

Slide 36

Slide 36 text

Extension API public boolean applicable(Context context) Parcelable extension Parcelable extension Redacted extension Redacted extension @AutoValue public abstract class Payment {} @AutoValue public abstract class Payment implements Parcelable {} @AutoValue public abstract class Payment { public abstract String note(); } @AutoValue public abstract class Payment { @Redacted public abstract String note(); } false true false true

Slide 37

Slide 37 text

Extension API public boolean applicable(Context context) false true

Slide 38

Slide 38 text

Extension API public boolean applicable(Context context) false true final class AutoValue_Payment1extends2Payment { /* value type implementation */ }Y @AutoValue public abstract class Payment1{3 /* abstract properties */ }X final class AutoValue_Payment1extends2$AutoValue_Payment { /* value type implementation */ }Y abstract class $AutoValue_Payment1extends2Payment { /* extension implementation */ }Y @AutoValue public abstract class Payment1{3 /* abstract properties */ }X

Slide 39

Slide 39 text

Extension API public abstract class AutoValueExtension {
 public boolean applicable(Context context) {
 return false;
 }X
 
 public boolean mustBeFinal(Context context) {
 return false;
 }
 
 public Set consumeProperties(Context context) {
 return Collections.emptySet();
 }
 
 public abstract String generateClass(Context context, String className, String classToExtend, boolean isFinal);
 }

Slide 40

Slide 40 text

Extension API public abstract class AutoValueExtension {
 public boolean applicable(Context context) {
 return false;
 }
 
 public boolean mustBeFinal(Context context) {
 return false;
 }
 
 public Set consumeProperties(Context context) {
 return Collections.emptySet();
 }
 
 public abstract String generateClass(Context context, String className, String classToExtend, boolean isFinal);
 }

Slide 41

Slide 41 text

Extension API public boolean mustBeFinal(Context context)

Slide 42

Slide 42 text

Extension API public boolean mustBeFinal(Context context) Parcelable extension true

Slide 43

Slide 43 text

Extension API public boolean mustBeFinal(Context context) Parcelable extension true All* other extensions false

Slide 44

Slide 44 text

Extension API public boolean mustBeFinal(Context context) false true

Slide 45

Slide 45 text

Extension API public boolean mustBeFinal(Context context) false true final class AutoValue_Payment1extends2$AutoValue_Payment { /* extension implementation */ }Y abstract class $AutoValue_Payment1extends2Payment { /* value type implementation */ }Y @AutoValue public abstract class Payment1{3 /* abstract properties */ }X final class AutoValue_Payment1extends2$AutoValue_Payment { /* value type implementation */ }Y abstract class $AutoValue_Payment1extends2Payment { /* extension implementation */ }Y @AutoValue public abstract class Payment1{3 /* abstract properties */ }X

Slide 46

Slide 46 text

Extension API public boolean mustBeFinal(Context context) false true final class AutoValue_Payment1extends2$AutoValue_Payment { /* extension implementation */ }Y abstract class $AutoValue_Payment1extends2Payment { /* value type implementation */ }Y @AutoValue public abstract class Payment1{3 /* abstract properties */ }X final class AutoValue_Payment1extends2$AutoValue_Payment { /* value type implementation */ }Y abstract class $AutoValue_Payment1extends2Payment { /* extension implementation */ }Y @AutoValue public abstract class Payment1{3 /* abstract properties */ }X

Slide 47

Slide 47 text

Extension API public abstract class AutoValueExtension {
 public boolean applicable(Context context) {
 return false;
 }
 
 public boolean mustBeFinal(Context context) {
 return false;
 }
 
 public Set consumeProperties(Context context) {
 return Collections.emptySet();
 }
 
 public abstract String generateClass(Context context, String className, String classToExtend, boolean isFinal);
 }

Slide 48

Slide 48 text

Extension API public abstract class AutoValueExtension {
 public boolean applicable(Context context) {
 return false;
 }
 
 public boolean mustBeFinal(Context context) {
 return false;
 }
 
 public Set consumeProperties(Context context) {
 return Collections.emptySet();
 }
 
 public abstract String generateClass(Context context, String className, String classToExtend, boolean isFinal);
 }

Slide 49

Slide 49 text

Extension API public Set consumeProperties(Context context)

Slide 50

Slide 50 text

Extension API public Set consumeProperties(Context context) @AutoValue public abstract class Payment implements Parcelable { public abstract String note(); }

Slide 51

Slide 51 text

Extension API public Set consumeProperties(Context context) @AutoValue public abstract class Payment implements Parcelable { public abstract String note(); } Extension [ ]

Slide 52

Slide 52 text

Extension API public Set consumeProperties(Context context) @AutoValue public abstract class Payment implements Parcelable { public abstract String note(); } Extension [ ] [ "note", "describeContents" ]

Slide 53

Slide 53 text

Extension API public Set consumeProperties(Context context) @AutoValue public abstract class Payment implements Parcelable { public abstract String note(); } Extension [ ] [ "note", "describeContents" ] @AutoValue public abstract class Payment implements Parcelable { public abstract String note(); } Extension [ "describeContents" ] [ "note" ]

Slide 54

Slide 54 text

Extension API public abstract class AutoValueExtension {
 public boolean applicable(Context context) {
 return false;
 }
 
 public boolean mustBeFinal(Context context) {
 return false;
 }
 
 public Set consumeProperties(Context context) {
 return Collections.emptySet();
 }
 
 public abstract String generateClass(Context context, String className, String classToExtend, boolean isFinal);
 }

Slide 55

Slide 55 text

Extension API public abstract class AutoValueExtension {
 public boolean applicable(Context context) {
 return false;
 }
 
 public boolean mustBeFinal(Context context) {
 return false;
 }
 
 public Set consumeProperties(Context context) {
 return Collections.emptySet();
 }
 
 public abstract String generateClass(Context context, String className, String classToExtend, boolean isFinal);
 }

Slide 56

Slide 56 text

Building Extensions

Slide 57

Slide 57 text

Building Extensions • Model it after the existing extensions

Slide 58

Slide 58 text

Building Extensions • Model it after the existing extensions • Try to play nice with other extensions

Slide 59

Slide 59 text

Building Extensions • Model it after the existing extensions • Try to play nice with other extensions • JavaPoet: github.com/square/javapoet • Truth: github.com/google/truth • compile-testing: github.com/google/compile-testing • auto/service: github.com/google/auto

Slide 60

Slide 60 text

1.2-SNAPSHOT?!?

Slide 61

Slide 61 text

1.2-SNAPSHOT?!? Big Bang (not to scale)

Slide 62

Slide 62 text

1.2-SNAPSHOT?!? Big Bang AutoValue 1.1 released (10 months ago) (not to scale)

Slide 63

Slide 63 text

1.2-SNAPSHOT?!? Big Bang AutoValue 1.1 released (10 months ago) Extensions merged (9 months ago) (not to scale)

Slide 64

Slide 64 text

1.2-SNAPSHOT?!? Big Bang AutoValue 1.1 released (10 months ago) Extensions merged (9 months ago) (not to scale)

Slide 65

Slide 65 text

1.2-SNAPSHOT?!? Big Bang Heat death of universe AutoValue 1.1 released (10 months ago) Extensions merged (9 months ago) AutoValue 1.2 released ?????? (not to scale)

Slide 66

Slide 66 text

jakewharton jakewharton jakewharton twitter.com/ google.com/+ .com AutoValue Extensions