rharter / auto-value-gson

AutoValue Extension to add Gson De/Serializer support
Apache License 2.0
607 stars 103 forks source link

Originating element not set #233

Closed gavra0 closed 4 years ago

gavra0 commented 4 years ago

With e.g.

@GenerateTypeAdapter
@AutoValue
public abstract class Foo {
    abstract String bar();
    @SerializedName("Baz") abstract String baz();
    abstract int quux();
    abstract String with_underscores();

    // The public static method returning a TypeAdapter<Foo> is what
    // tells auto-value-gson to create a TypeAdapter for Foo.
    public static TypeAdapter<Foo> typeAdapter(Gson gson) {
        return new Foo_GsonTypeAdapter(gson);
    }
}

and dependencies

implementation group: 'com.google.auto.value', name: 'auto-value-annotations', version: '1.7'
annotationProcessor("com.ryanharter.auto.value:auto-value-gson:1.1.1")
implementation("com.ryanharter.auto.value:auto-value-gson-runtime:1.1.1")

incremental annotation processing fails because it does not pass the originating element when generating com.example.myapplication.Foo_GsonTypeAdapter.

Both Gradle Java compilation and KAPT fail to run incrementally.

The issue seems to be that AutoValueGsonExtension.generateClass does not set originating element for the TypeSpec.Builder it is using to write the class.

rharter commented 4 years ago

@ZacSweers was just looking into that prior to a release. @ZacSweers, does it look like that might be the issue?

ZacSweers commented 4 years ago

On it!

ZacSweers commented 4 years ago

I think my confusion was that we were hiding this behind autovalue's guard of originating elements, but I guess the rules are different if we're not generating it into a nested type anymore?