|
33 | 33 | import java.lang.annotation.Annotation; |
34 | 34 | import java.util.ArrayList; |
35 | 35 | import java.util.Collections; |
| 36 | +import java.util.Comparator; |
36 | 37 | import java.util.HashSet; |
37 | 38 | import java.util.List; |
38 | 39 | import java.util.Optional; |
|
43 | 44 | import javax.annotation.processing.ProcessingEnvironment; |
44 | 45 | import javax.annotation.processing.Processor; |
45 | 46 | import javax.annotation.processing.SupportedAnnotationTypes; |
46 | | -import javax.annotation.processing.SupportedOptions; |
47 | 47 | import javax.lang.model.element.AnnotationMirror; |
48 | 48 | import javax.lang.model.element.Element; |
49 | 49 | import javax.lang.model.element.ElementKind; |
50 | 50 | import javax.lang.model.element.ExecutableElement; |
51 | 51 | import javax.lang.model.element.TypeElement; |
52 | 52 | import javax.lang.model.type.TypeKind; |
53 | 53 | import javax.lang.model.type.TypeMirror; |
| 54 | +import net.ltgt.gradle.incap.IncrementalAnnotationProcessor; |
| 55 | +import net.ltgt.gradle.incap.IncrementalAnnotationProcessorType; |
54 | 56 |
|
55 | 57 | /** |
56 | 58 | * Javac annotation processor (compiler plugin) for value types; user code never references this |
|
61 | 63 | */ |
62 | 64 | @AutoService(Processor.class) |
63 | 65 | @SupportedAnnotationTypes(AUTO_VALUE_NAME) |
64 | | -@SupportedOptions("com.google.auto.value.OmitIdentifiers") |
| 66 | +@IncrementalAnnotationProcessor(IncrementalAnnotationProcessorType.DYNAMIC) |
65 | 67 | public class AutoValueProcessor extends AutoValueOrOneOfProcessor { |
| 68 | + private static final String OMIT_IDENTIFIERS_OPTION = "com.google.auto.value.OmitIdentifiers"; |
| 69 | + |
66 | 70 | public AutoValueProcessor() { |
67 | 71 | this(AutoValueProcessor.class.getClassLoader()); |
68 | 72 | } |
@@ -112,6 +116,28 @@ public synchronized void init(ProcessingEnvironment processingEnv) { |
112 | 116 | } |
113 | 117 | } |
114 | 118 |
|
| 119 | + @Override |
| 120 | + public Set<String> getSupportedOptions() { |
| 121 | + AutoValueExtension.IncrementalExtensionType incrementalType = |
| 122 | + extensions.stream() |
| 123 | + .map(e -> e.incrementalType(processingEnv)) |
| 124 | + .min(Comparator.naturalOrder()) |
| 125 | + .orElse(AutoValueExtension.IncrementalExtensionType.ISOLATING); |
| 126 | + switch (incrementalType) { |
| 127 | + case ISOLATING: |
| 128 | + return ImmutableSet.of( |
| 129 | + OMIT_IDENTIFIERS_OPTION, |
| 130 | + IncrementalAnnotationProcessorType.ISOLATING.getProcessorOption()); |
| 131 | + case AGGREGATING: |
| 132 | + return ImmutableSet.of( |
| 133 | + OMIT_IDENTIFIERS_OPTION, |
| 134 | + IncrementalAnnotationProcessorType.AGGREGATING.getProcessorOption()); |
| 135 | + case UNKNOWN: |
| 136 | + return ImmutableSet.of(OMIT_IDENTIFIERS_OPTION); |
| 137 | + } |
| 138 | + throw new AssertionError(incrementalType); |
| 139 | + } |
| 140 | + |
115 | 141 | private static String generatedSubclassName(TypeElement type, int depth) { |
116 | 142 | return generatedClassName(type, Strings.repeat("$", depth) + "AutoValue_"); |
117 | 143 | } |
@@ -201,8 +227,7 @@ void processType(TypeElement type) { |
201 | 227 | AutoValueTemplateVars vars = new AutoValueTemplateVars(); |
202 | 228 | vars.finalSubclass = TypeSimplifier.simpleNameOf(finalSubclass); |
203 | 229 | vars.types = processingEnv.getTypeUtils(); |
204 | | - vars.identifiers = |
205 | | - !processingEnv.getOptions().containsKey("com.google.auto.value.OmitIdentifiers"); |
| 230 | + vars.identifiers = !processingEnv.getOptions().containsKey(OMIT_IDENTIFIERS_OPTION); |
206 | 231 | defineSharedVarsForType(type, methods, vars); |
207 | 232 | defineVarsForType(type, vars, toBuilderMethods, propertyMethods, builder); |
208 | 233 |
|
|
0 commit comments