gsonvalue icon indicating copy to clipboard operation
gsonvalue copied to clipboard

Support gradle's incremental java compiler

Open evant opened this issue 7 years ago • 2 comments

https://docs.gradle.org/4.7-rc-1/userguide/java_plugin.html#sec:incremental_annotation_processing

evant avatar Apr 03 '18 14:04 evant

Note: this breaks builders that aren't nested in their parent class. Is this worth it? Should there be a flag? Or just remove support for this?

evant avatar Apr 07 '18 19:04 evant

Actually, it looks like I'll have to rethink how the annotations work for it to be processed correctly. The processor needs to process an annotation on the target class in all cases.

Proposal: have a single top-level @GsonValue annotation on the class. This will support all methods of construction as long as it's not ambiguous how the class should be created. Have an optional @GsonValue.Creator annotation to disambiguate multiple methods of creation.

@GsonValue
public class MyClass {
   public final int arg;

   public MyClass(int arg) {
       this.arg = arg;
   }
}
@GsonValue
public class MyClass {
   public final int arg;

   private MyClass(int arg) {
       this.arg = arg;
   }

   public static class Builder {
        ...
        public MyClass build();
   }
}
@GsonValue
public class MyClass {
   public final int arg;

   MyClass(int arg) {
       this.arg = arg;
   }

   @GsonValue.Creator
   public static MyClass create(int arg) {
      return new MyClass(arg);
   }
}

Builders outside the class won't be supported.

evant avatar Apr 07 '18 22:04 evant