5
5
import javax .annotation .processing .Filer ;
6
6
import javax .annotation .processing .Messager ;
7
7
import javax .annotation .processing .ProcessingEnvironment ;
8
+ import javax .lang .model .SourceVersion ;
8
9
import javax .lang .model .element .Element ;
9
10
import javax .lang .model .element .TypeElement ;
10
11
import javax .lang .model .type .DeclaredType ;
15
16
import javax .tools .JavaFileObject ;
16
17
import java .io .IOException ;
17
18
18
- import static io .dinject .javalin .generator .Constants .GENERATED ;
19
+ import static io .dinject .javalin .generator .Constants .GENERATED_8 ;
20
+ import static io .dinject .javalin .generator .Constants .GENERATED_9 ;
19
21
import static io .dinject .javalin .generator .Constants .JAVALIN3_CONTEXT ;
20
22
import static io .dinject .javalin .generator .Constants .OPENAPIDEFINITION ;
21
23
@@ -25,7 +27,7 @@ public class ProcessingContext {
25
27
private final Filer filer ;
26
28
private final Elements elements ;
27
29
private final Types types ;
28
- private final boolean generatedAvailable ;
30
+ private final String generatedAnnotation ;
29
31
private final boolean openApiAvailable ;
30
32
private final boolean javalin3 ;
31
33
@@ -36,10 +38,18 @@ public class ProcessingContext {
36
38
this .filer = env .getFiler ();
37
39
this .elements = env .getElementUtils ();
38
40
this .types = env .getTypeUtils ();
39
- this .generatedAvailable = isTypeAvailable (GENERATED );
40
41
this .openApiAvailable = isTypeAvailable (OPENAPIDEFINITION );
41
42
this .javalin3 = isTypeAvailable (JAVALIN3_CONTEXT );
42
43
this .docContext = new DocContext (env , openApiAvailable );
44
+ boolean jdk8 = env .getSourceVersion ().compareTo (SourceVersion .RELEASE_8 ) <= 0 ;
45
+ this .generatedAnnotation = generatedAnnotation (jdk8 );
46
+ }
47
+
48
+ private String generatedAnnotation (boolean jdk8 ) {
49
+ if (jdk8 ) {
50
+ return isTypeAvailable (GENERATED_8 ) ? GENERATED_8 : null ;
51
+ }
52
+ return isTypeAvailable (GENERATED_9 ) ? GENERATED_9 : null ;
43
53
}
44
54
45
55
private boolean isTypeAvailable (String canonicalName ) {
@@ -51,7 +61,11 @@ TypeElement getTypeElement(String canonicalName) {
51
61
}
52
62
53
63
boolean isGeneratedAvailable () {
54
- return generatedAvailable ;
64
+ return generatedAnnotation != null ;
65
+ }
66
+
67
+ String getGeneratedAnnotation () {
68
+ return generatedAnnotation ;
55
69
}
56
70
57
71
boolean isOpenApiAvailable () {
0 commit comments