0% found this document useful (0 votes)
55 views91 pages

NYCAndroidMeetup AutoValueExtensions ForExport PDF

The document describes the creation of an immutable value type called Payment in Java. It shows how to define the Payment class as final, include private final fields for the properties (id, amount, currency, note), add a constructor to initialize the fields, and include getter methods to access the field values. It also adds toString(), equals() and hashCode() methods to define object equality and hashing behavior based on the field values. The end result is an immutable value class that can be used like a primitive type in Java.

Uploaded by

DRUPEN DRUPEN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views91 pages

NYCAndroidMeetup AutoValueExtensions ForExport PDF

The document describes the creation of an immutable value type called Payment in Java. It shows how to define the Payment class as final, include private final fields for the properties (id, amount, currency, note), add a constructor to initialize the fields, and include getter methods to access the field values. It also adds toString(), equals() and hashCode() methods to define object equality and hashing behavior based on the field values. The end result is an immutable value class that can be used like a primitive type in Java.

Uploaded by

DRUPEN DRUPEN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 91

AutoValue Extensions

Jake Wharton
Value Types?
Value Types?
Everything is mutable in Java.
Value Types?
Basically everything is mutable in Java.
Value Types?
Basically everything is mutable in Java.

"Beans" with getters and setters


Value Types?
Basically everything is mutable in Java.

"Beans" with getters and setters

Collections
Value Types?
Basically everything is mutable in Java.

"Beans" with getters and setters

Collections

Arrays
Value Types?
Basically everything is mutable in Java.

"Beans" with getters and setters

Collections

Arrays

Mutator methods
Value Types?
Basically everything is mutable in Java.

"Beans" with getters and setters

Collections

Arrays

Mutator methods

Non-scalar "constants"
Value Types
public class Payment {
public long id();
public long amount();
public String note();
}X
Value Types
public final class Payment {
public long id();
public long amount();
public String note();
}X
Value Types
public final class Payment {
private final long id;

public long id() {


return id;
}Y
public long amount();
public String note();
}X
Value Types
public final class Payment {
private final long id;
private final long amount;

public long id() {


return id;
}Y
public long amount() {
return amount;
}Z
public String note();
}X
Value Types
public final class Payment {
private final long id;
private final long amount;
private final String note;

public long id() {


return id;
}Y
public long amount() {
return amount;
}Z
public String note() {
return note;
}W
}X
Value Types
public final class Payment {
private final long id;
private final long amount;
private final String note;

public Payment(long id, long amount, String note) {


this.id = id;
this.amount = amount;
this.note = note;
}Q

public long id() {


return id;
}Y
public long amount() {
return amount;
}Z
public String note() {
return note;
}W
}X
Value Types
public final class Payment {
private final long id;
private final long amount;
private final String note;

public Payment(long id, long amount, String note) {


this.id = id;
this.amount = amount;
this.note = note;
}Q

public long id() {


return id;
}Y
public long amount() {
return amount;
}Z
public String note() {
return note;
}W

@Override public String toString() {


return "Payment{" +
"id=" + id +
", amount=" + amount +
", note='" + note + '\'' +
'}';
}E
}X
Value Types
public final class Payment {
private final long id;
private final long amount;
private final String note;

public Payment(long id, long amount, String note) {


this.id = id;
this.amount = amount;
this.note = note;
}Q

public long id() {


return id;
}Y
public long amount() {
return amount;
}Z
public String note() {
return note;
}W

@Override public String toString() {


return "Payment{" +
"id=" + id +
", amount=" + amount +
", 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
&& 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 + note.hashCode();
return result;
}T
}X
Value Types
public final class Payment {
private final long id;
private final long amount;
private final String note;

public Payment(long id, long amount, String note) {


this.id = id;
this.amount = amount;
this.note = note;

public Currency currency();


}Q

public long id() {


return id;
}Y
public long amount() {
return amount;
}Z
public String note() {
return note;
}W

@Override public String toString() {


return "Payment{" +
"id=" + id +
", amount=" + amount +
", 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
&& 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 + note.hashCode();
return result;
}T
}X
Value Types
public final class Payment {
private final long id;
private final long amount;
private final Currency currency;
private final String note;

public Payment(long id, long amount, Currency currency, String note) {


this.id = id;
this.amount = amount;
this.currency = currency;
this.note = note;
}Q

public long id() {


return id;
}Y
public long amount() {
return amount;
}Z
public Currency currency() {
return currency;
}U
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
Value Types
public final class Payment {
private final long id;
private final long amount;
1 Field
private final Currency currency;
private final String note;

Constructor Parameter

public Payment(long id, long amount, Currency currency, String note) {


this.id = id;
this.amount = amount;
2
this.currency = currency;
this.note = note;
}Q

Constructor Statement

public long id() {

}Y
return id; 3
public long amount() {
return amount;
}Z

Method Signature
public Currency currency() {

}U
return currency;
4
public String note() {
return note;
}W

@Override public String toString() {


return "Payment{" +
"id=" + id +
", amount=" + amount +
5 Method Statement
", currency=" + currency +
", note='" + note + '\'' +
'}';

}E

@Override public boolean equals(Object o) {


if (this == o) return true;
6 toString() Expression
if (!(o instanceof Payment)) return false;
Payment other = (Payment) o;

equals() Expression
return id == other.id
&& amount == other.amount
&& currency.equals(other.currency)
&& note.equals(other.note);
7
}R

@Override public int hashCode() {

hashCode() Expression
int result = (int) (id ^ (id >>> 32));
result = 31 * result + (int) (amount ^ (amount >>> 32));
result = 31 * result + currency.hashCode();
result = 31 * result + note.hashCode();
8
return result;
}T
}X
Value Types
public final class Payment {
private final long id;
private final long amount;
private final Currency currency;
private final String note;

public Payment(long id, long amount, Currency currency, String note) {


this.id = id;
this.amount = amount;
this.currency = currency;
this.note = note;
}Q

public long id() {


return id;
}Y
public long amount() {
return amount;
}Z
public Currency currency() {
return currency;
}U
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
public final class Payment {
private final long id;
private final long amount;

Value Types
private final Currency currency;
private final String note;

public Payment(long id, long amount, Currency currency, String note) {
this.id = id;
this.amount = amount;
this.currency = currency;
this.note = note;
}Q

public long id() {

public class Payment { }Y


return id;

public long amount() {


public long id(); }Z
return amount;

public long amount(); public Currency currency() {


return currency;

public Currency currency();


}U
public String note() {
return note;
public String note();
}W

}X @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
AutoValue!
public class Payment {
public long id();
public long amount();
public Currency currency();
public String note();
}X
AutoValue!
@AutoValue
public class Payment {
public long id();
public long amount();
public Currency currency();
public String note();
}X
AutoValue!
@AutoValue
public abstract class Payment {
public abstract long id();
public abstract long amount();
public abstract Currency currency();
public abstract String note();
}X
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
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
final class AutoValue_Payment extends Payment {
private final long id;
private final long amount;

AutoValue!
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() {
@AutoValue return id;
public abstract class Payment { }Y
@Override public long amount() {

return amount;
public static Payment create( }Z
long id, long amount, Currency currency, String note) { @Override public Currency currency() {
return new AutoValue_Payment(id, amount, currency, note); return currency;
}U
}Z @Override public String note() {
return note;
public abstract long id(); }W
public abstract long amount();
@Override public String toString() {
public abstract Currency currency(); return "Payment{" +
public abstract String note(); "id=" + id +
}X ", 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
AutoValue!

github.com/google/auto
AutoValue Extensions
@AutoValue
public abstract class Payment {
public abstract long id();
public abstract long amount();
public abstract Currency currency();
public abstract String note();
}X
AutoValue Extensions
@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
@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
@AutoValue
public abstract class Payment {
public abstract long id();
public abstract long amount();
public abstract Currency currency();
public abstract String note();
}X

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

Parcelable
Gson
Ok, awesome! Now how do I use it with Cursors ?
(whatever)
AutoValue Extensions
@AutoValue
public abstract class Payment {
public abstract long id();
public abstract long amount();
public abstract Currency currency();
public abstract String note();
}X Parcelable
Gson
Cursors
Ok, awesome! Now how do I use it with (whatever) ?
AutoValue Extensions
@AutoValue
public abstract class Payment3{
public abstract long id();
public abstract long amount();
public abstract Currency currency();
public abstract String note();
}X
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 */
AutoValue Extensions
final class AutoValue_Payment1extends2Payment {
/* value type implementation */
}Y

@AutoValue
public abstract class Payment1implements2Parcelable3{3
/* abstract properties */
}X
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
AutoValue Extensions
@AutoValue
final class AutoValue_Payment1extends2$AutoValue_Payment {
public
/* parcelable
abstract class
implementation
Payment1implements2Parcelable3{3
*/
}Zpublic abstract long id();
public
/* abstract
abstract
properties
long amount();
*/
abstract
public abstract
class $AutoValue_Payment1extends2Payment
Currency currency(); {
public
/* value
abstract
type implementation
String note();
*/
}Y/* abstract properties */
}X
AutoValue Extensions
@AutoValue
final class AutoValue_Payment1extends2$AutoValue_Payment {
public
/* parcelable
abstract class
implementation
Payment1implements2Parcelable3{3
*/
}Zpublic abstract long id();
public
/* abstract
abstract
properties
long amount();
*/
abstract
public abstract
class $AutoValue_Payment1extends2Payment
Currency currency(); {
@Redacted
/* value type
public
implementation
abstract String
*/ note();
}Y/* abstract properties */
}X
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
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
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
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
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
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
Available Extensions
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
Extension API
Extension API
public abstract class AutoValueExtension {
public boolean applicable(Context context) {
return false;
}

public boolean mustBeFinal(Context context) {


return false;
}

public Set<String> consumeProperties(Context context) {


return Collections.emptySet();
}

public abstract String generateClass(Context context,


String className, String classToExtend, boolean isFinal);
}
Extension API
public abstract class AutoValueExtension {
public boolean applicable(Context context) {
return false;
}X

public boolean mustBeFinal(Context context) {


return false;
}

public Set<String> consumeProperties(Context context) {


return Collections.emptySet();
}

public abstract String generateClass(Context context,


String className, String classToExtend, boolean isFinal);
}
Extension API
public boolean applicable(Context context)
Extension API
public boolean applicable(Context context)

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

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

@AutoValue
Parcelable extension public abstract class Payment {} false

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

@AutoValue
Parcelable extension public abstract class Payment {} false

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

@AutoValue
Parcelable extension public abstract class Payment {} false

@AutoValue
Parcelable extension public abstract class Payment implements Parcelable {} true

@AutoValue

Redacted extension public abstract class Payment {


public abstract String note();
}
Extension API
public boolean applicable(Context context)

@AutoValue
Parcelable extension public abstract class Payment {} false

@AutoValue
Parcelable extension public abstract class Payment implements Parcelable {} true

@AutoValue

Redacted extension public abstract class Payment {


public abstract String note(); false
}
Extension API
public boolean applicable(Context context)

@AutoValue
Parcelable extension public abstract class Payment {} false

@AutoValue
Parcelable extension public abstract class Payment implements Parcelable {} true

@AutoValue

Redacted extension public abstract class Payment {


public abstract String note(); false
}

@AutoValue

Redacted extension public abstract class Payment {


@Redacted public abstract String note();
}
Extension API
public boolean applicable(Context context)

@AutoValue
Parcelable extension public abstract class Payment {} false

@AutoValue
Parcelable extension public abstract class Payment implements Parcelable {} true

@AutoValue

Redacted extension public abstract class Payment {


public abstract String note(); false
}

@AutoValue

Redacted extension public abstract class Payment {


@Redacted public abstract String note(); true
}
Extension API
public boolean applicable(Context context)

false true
Extension API
public boolean applicable(Context context)

false true

final class AutoValue_Payment1extends2Payment { final class AutoValue_Payment1extends2$AutoValue_Payment {


/* value type implementation */ /* value type implementation */
}Y }Y

@AutoValue abstract class $AutoValue_Payment1extends2Payment {


public abstract class Payment1{3 /* extension implementation */
/* abstract properties */ }Y
}X
@AutoValue
public abstract class Payment1{3
/* abstract properties */
}X
Extension API
public abstract class AutoValueExtension {
public boolean applicable(Context context) {
return false;
}X

public boolean mustBeFinal(Context context) {


return false;
}

public Set<String> consumeProperties(Context context) {


return Collections.emptySet();
}

public abstract String generateClass(Context context,


String className, String classToExtend, boolean isFinal);
}
Extension API
public abstract class AutoValueExtension {
public boolean applicable(Context context) {
return false;
}

public boolean mustBeFinal(Context context) {


return false;
}

public Set<String> consumeProperties(Context context) {


return Collections.emptySet();
}

public abstract String generateClass(Context context,


String className, String classToExtend, boolean isFinal);
}
Extension API
public boolean mustBeFinal(Context context)
Extension API
public boolean mustBeFinal(Context context)

Parcelable extension true


Extension API
public boolean mustBeFinal(Context context)

Parcelable extension true

All* other extensions false


Extension API
public boolean mustBeFinal(Context context)

false true
Extension API
public boolean mustBeFinal(Context context)

false true

final class AutoValue_Payment1extends2$AutoValue_Payment { final class AutoValue_Payment1extends2$AutoValue_Payment {


/* value type implementation */ /* extension implementation */
}Y }Y

abstract class $AutoValue_Payment1extends2Payment { abstract class $AutoValue_Payment1extends2Payment {


/* extension implementation */ /* value type implementation */
}Y }Y

@AutoValue @AutoValue
public abstract class Payment1{3 public abstract class Payment1{3
/* abstract properties */ /* abstract properties */
}X }X
Extension API
public boolean mustBeFinal(Context context)

false true

final class AutoValue_Payment1extends2$AutoValue_Payment { final class AutoValue_Payment1extends2$AutoValue_Payment {


/* value type implementation */ /* extension implementation */
}Y }Y

abstract class $AutoValue_Payment1extends2Payment { abstract class $AutoValue_Payment1extends2Payment {


/* extension implementation */ /* value type implementation */
}Y }Y

@AutoValue @AutoValue
public abstract class Payment1{3 public abstract class Payment1{3
/* abstract properties */ /* abstract properties */
}X }X
Extension API
public abstract class AutoValueExtension {
public boolean applicable(Context context) {
return false;
}

public boolean mustBeFinal(Context context) {


return false;
}

public Set<String> consumeProperties(Context context) {


return Collections.emptySet();
}

public abstract String generateClass(Context context,


String className, String classToExtend, boolean isFinal);
}
Extension API
public abstract class AutoValueExtension {
public boolean applicable(Context context) {
return false;
}

public boolean mustBeFinal(Context context) {


return false;
}

public Set<String> consumeProperties(Context context) {


return Collections.emptySet();
}

public abstract String generateClass(Context context,


String className, String classToExtend, boolean isFinal);
}
Extension API
public Set<String> consumeProperties(Context context)
Extension API
public Set<String> consumeProperties(Context context)

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

@AutoValue
public abstract class Payment implements Parcelable {
public abstract String note();
}

Extension []
Extension API
public Set<String> consumeProperties(Context context)

@AutoValue
public abstract class Payment implements Parcelable {
public abstract String note();
}

Extension []

[ "note", "describeContents" ]
Extension API
public Set<String> consumeProperties(Context context)

@AutoValue @AutoValue
public abstract class Payment implements Parcelable { public abstract class Payment implements Parcelable {
public abstract String note(); public abstract String note();
} }

Extension [] Extension [ "describeContents" ]

[ "note", "describeContents" ] [ "note" ]


Extension API
public abstract class AutoValueExtension {
public boolean applicable(Context context) {
return false;
}

public boolean mustBeFinal(Context context) {


return false;
}

public Set<String> consumeProperties(Context context) {


return Collections.emptySet();
}

public abstract String generateClass(Context context,


String className, String classToExtend, boolean isFinal);
}
Extension API
public abstract class AutoValueExtension {
public boolean applicable(Context context) {
return false;
}

public boolean mustBeFinal(Context context) {


return false;
}

public Set<String> consumeProperties(Context context) {


return Collections.emptySet();
}

public abstract String generateClass(Context context,


String className, String classToExtend, boolean isFinal);
}
Building Extensions
Building Extensions
Model it after the existing extensions
Building Extensions
Model it after the existing extensions

Try to play nice with other extensions


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
1.2-SNAPSHOT?!?
1.2-SNAPSHOT?!?

Big
Bang
1.2-SNAPSHOT?!?

Big
Bang

AutoValue 1.1 released


(10 months ago)
1.2-SNAPSHOT?!?
Extensions merged
(9 months ago)

Big
Bang

AutoValue 1.1 released


(10 months ago)
1.2-SNAPSHOT?!?
Extensions merged
(9 months ago)

Big
Bang

AutoValue 1.1 released


(10 months ago)
1.2-SNAPSHOT?!?
Extensions merged
(9 months ago)

Big Heat death


Bang of universe

AutoValue 1.1 released AutoValue 1.2 released


(10 months ago) ??????
AutoValue Extensions
twitter.com/ jakewharton
google.com/+ jakewharton
jakewharton .com

You might also like