Skip to content

Commit 317c08a

Browse files
committed
added support for Gradles incremental annotation processing
this fixes #6
1 parent 7c842cb commit 317c08a

File tree

5 files changed

+20
-6
lines changed

5 files changed

+20
-6
lines changed

.idea/modules/enum-mapper-processor/enum-mapper-processor_main.iml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

enum-mapper-processor/build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ dependencies {
66
compile project(':enum-mapper-lib')
77

88
compile 'com.squareup:javapoet:1.11.1'
9+
compile 'com.google.auto:auto-common:0.10'
910
// unfortunately lib and processor are in the same artifact
1011
// see: https://github.com/google/auto/issues/632
1112
compileOnly 'com.google.auto.service:auto-service:1.0-rc4'
12-
compile 'com.google.auto:auto-common:0.10'
13+
14+
// https://github.com/tbroyer/gradle-incap-helper
15+
final INCAP_VERSION = '0.1'
16+
compileOnly("net.ltgt.gradle.incap:incap:${INCAP_VERSION}")
17+
annotationProcessor("net.ltgt.gradle.incap:incap-processor:${INCAP_VERSION}")
1318

1419
testCompile 'com.google.testing.compile:compile-testing:0.15'
1520
testCompile 'com.google.truth:truth:0.40'

enum-mapper-processor/src/main/java/com/tmtron/enums/processor/EnumsAnnotationProcessor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
import com.google.auto.common.BasicAnnotationProcessor;
1919
import com.google.auto.service.AutoService;
2020

21+
import net.ltgt.gradle.incap.IncrementalAnnotationProcessor;
22+
import net.ltgt.gradle.incap.IncrementalAnnotationProcessorType;
23+
2124
import java.util.Collections;
2225

2326
import javax.annotation.processing.Processor;
@@ -27,6 +30,7 @@
2730
* This class will register the annotation processor/s.
2831
*/
2932
@AutoService(Processor.class)
33+
@IncrementalAnnotationProcessor(IncrementalAnnotationProcessorType.AGGREGATING)
3034
public class EnumsAnnotationProcessor extends BasicAnnotationProcessor {
3135

3236
@Override

enum-mapper-processor/src/main/java/com/tmtron/enums/processor/MapAllEnumsProcessingStep.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ public Set<? extends Class<? extends Annotation>> annotations() {
5454
@Override
5555
public Set<Element> process(SetMultimap<Class<? extends Annotation>, Element> elementsByAnnotation) {
5656
try {
57-
Map<Class<? extends Annotation>, Collection<Element>> annotationsMap =
58-
elementsByAnnotation.asMap();
57+
Map<Class<? extends Annotation>, Collection<Element>> annotationsMap = elementsByAnnotation.asMap();
5958
// the annotations() method tells the framework which annotations to accept
6059
if (annotationsMap.keySet().size() > 2) throw new RuntimeException("Too many annotations");
6160

enum-mapper-processor/src/main/java/com/tmtron/enums/processor/WriteMapperFull.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,13 @@ private void addStagedBuilderInterfaces(TypeSpec.Builder mapperFullTypeBuilder
129129
private TypeSpec.Builder createFullMapperTypeSpecBuilder() {
130130
// LauncherAge_MapperFull
131131
ClassName className = ClassName.bestGuess(enumsClassTypeElement.getQualifiedName() + "_MapperFull");
132-
TypeSpec.Builder result = TypeSpec.classBuilder(className).addModifiers(Modifier.PUBLIC,
133-
Modifier.FINAL);
132+
TypeSpec.Builder result = TypeSpec.classBuilder(className).addModifiers(Modifier.PUBLIC, Modifier.FINAL);
133+
134+
/*
135+
* We must add the originating elements in order to use Gradles "Incremental annotation processing"
136+
* https://docs.gradle.org/4.8-rc-2/userguide/java_plugin.html#sec:incremental_annotation_processing
137+
*/
138+
annotatedElements.forEach(result::addOriginatingElement);
134139
// @Generated annotation
135140
result.addAnnotation(
136141
createGeneratedAnnotation(EnumsAnnotationProcessor.class)

0 commit comments

Comments
 (0)