forked from kelloggm/object-construction-checker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't fail when we can't find an AutoValue Builder setter method (#111)
Before, we would fail with a `RuntimeException` if we couldn't match what we thought was an AutoValue property to a corresponding setter in the builder. But, we don't currently handle AutoValue extensions (see #110), and adding full and proper handling will be pretty non-trivial. So, instead of failing for these cases, just tolerate them. Add a test case using the AutoValue Parcel extension to expose the problem, along with some stub Android classes so we don't need to pull in a full Android dependence.
- Loading branch information
Showing
5 changed files
with
74 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
object-construction-checker/tests/autovalue/FooParcelable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import com.google.auto.value.AutoValue; | ||
import android.os.Parcelable; | ||
|
||
/** | ||
* Test for support of AutoValue Parcel extension. This test currently passes, but only because we ignore cases | ||
* where we cannot find a matching setter for a method we think corresponds to an AutoValue property. | ||
* See https://github.com/kelloggm/object-construction-checker/issues/110 | ||
*/ | ||
@AutoValue | ||
abstract class FooParcelable implements Parcelable { | ||
abstract String name(); | ||
|
||
static Builder builder() { | ||
return new AutoValue_FooParcelable.Builder(); | ||
} | ||
|
||
@AutoValue.Builder | ||
abstract static class Builder { | ||
|
||
abstract Builder setName(String value); | ||
|
||
abstract FooParcelable build(); | ||
} | ||
|
||
public static void buildSomethingWrong() { | ||
Builder b = builder(); | ||
// :: error: finalizer.invocation.invalid | ||
b.build(); | ||
} | ||
|
||
public static void buildSomethingRight() { | ||
Builder b = builder(); | ||
b.setName("Frank"); | ||
b.build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package android.os; | ||
|
||
/** | ||
* stub to avoid bringing in Android dependence | ||
*/ | ||
public final class Parcel { | ||
|
||
public String readString() { return ""; } | ||
|
||
public void writeString(String val) {} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
object-construction-checker/tests/autovalue/Parcelable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package android.os; | ||
|
||
/** | ||
* stub to avoid bringing in Android dependence | ||
*/ | ||
public interface Parcelable { | ||
public interface Creator<T> { | ||
|
||
public T createFromParcel(Parcel source); | ||
|
||
public T[] newArray(int size); | ||
} | ||
|
||
public int describeContents(); | ||
|
||
public void writeToParcel(Parcel dest, int flags); | ||
} |