13
13
import javax .lang .model .type .DeclaredType ;
14
14
import javax .lang .model .type .TypeKind ;
15
15
import javax .lang .model .type .TypeMirror ;
16
+ import javax .tools .Diagnostic ;
16
17
import javax .tools .FileObject ;
17
18
import javax .tools .JavaFileObject ;
18
19
import javax .tools .StandardLocation ;
24
25
import java .util .Set ;
25
26
import java .util .stream .Collectors ;
26
27
28
+ import static io .javaoperatorsdk .operator .ControllerUtils .CONTROLLERS_RESOURCE_PATH ;
29
+
27
30
@ SupportedAnnotationTypes (
28
31
"io.javaoperatorsdk.operator.api.Controller" )
29
32
@ SupportedSourceVersion (SourceVersion .RELEASE_8 )
@@ -37,7 +40,7 @@ public class ControllerAnnotationProcessor extends AbstractProcessor {
37
40
public synchronized void init (ProcessingEnvironment processingEnv ) {
38
41
super .init (processingEnv );
39
42
try {
40
- resource = processingEnv .getFiler ().createResource (StandardLocation .CLASS_OUTPUT , "" , "javaoperatorsdk/controllers" );
43
+ resource = processingEnv .getFiler ().createResource (StandardLocation .CLASS_OUTPUT , "" , CONTROLLERS_RESOURCE_PATH );
41
44
} catch (IOException e ) {
42
45
throw new RuntimeException (e );
43
46
}
@@ -50,13 +53,10 @@ public synchronized void init(ProcessingEnvironment processingEnv) {
50
53
51
54
@ Override
52
55
public boolean process (Set <? extends TypeElement > annotations , RoundEnvironment roundEnv ) {
53
- System .out .println ("annotatedElements:" );
54
56
try {
55
57
for (TypeElement annotation : annotations ) {
56
58
Set <? extends Element > annotatedElements
57
59
= roundEnv .getElementsAnnotatedWith (annotation );
58
- System .out .println ("annotatedElements:" );
59
- System .out .println (annotatedElements );
60
60
annotatedElements .stream ().filter (element -> element .getKind ().equals (ElementKind .CLASS ))
61
61
.map (e -> (TypeElement ) e )
62
62
.forEach (e -> this .generateDoneableClass (e , printWriter ));
@@ -78,7 +78,14 @@ private void generateDoneableClass(TypeElement controllerClassSymbol, PrintWrite
78
78
final String doneableClassName = customerResourceTypeElement .getSimpleName () + "Doneable" ;
79
79
final String destinationClassFileName = customerResourceTypeElement .getQualifiedName () + "Doneable" ;
80
80
final TypeName customResourceType = TypeName .get (resourceType );
81
+
81
82
if (!generatedDoneableClassFiles .add (destinationClassFileName )) {
83
+ processingEnv .getMessager ().printMessage (Diagnostic .Kind .NOTE ,
84
+ String .format (
85
+ "%s already exist! adding the mapping to the %s" ,
86
+ destinationClassFileName ,
87
+ CONTROLLERS_RESOURCE_PATH )
88
+ );
82
89
printWriter .println (controllerClassSymbol .getQualifiedName () + "," + customResourceType .toString ());
83
90
return ;
84
91
}
0 commit comments