1313import javax .lang .model .type .DeclaredType ;
1414import javax .lang .model .type .TypeKind ;
1515import javax .lang .model .type .TypeMirror ;
16+ import javax .tools .Diagnostic ;
1617import javax .tools .FileObject ;
1718import javax .tools .JavaFileObject ;
1819import javax .tools .StandardLocation ;
2425import java .util .Set ;
2526import java .util .stream .Collectors ;
2627
28+ import static io .javaoperatorsdk .operator .ControllerUtils .CONTROLLERS_RESOURCE_PATH ;
29+
2730@ SupportedAnnotationTypes (
2831 "io.javaoperatorsdk.operator.api.Controller" )
2932@ SupportedSourceVersion (SourceVersion .RELEASE_8 )
@@ -37,7 +40,7 @@ public class ControllerAnnotationProcessor extends AbstractProcessor {
3740 public synchronized void init (ProcessingEnvironment processingEnv ) {
3841 super .init (processingEnv );
3942 try {
40- resource = processingEnv .getFiler ().createResource (StandardLocation .CLASS_OUTPUT , "" , "javaoperatorsdk/controllers" );
43+ resource = processingEnv .getFiler ().createResource (StandardLocation .CLASS_OUTPUT , "" , CONTROLLERS_RESOURCE_PATH );
4144 } catch (IOException e ) {
4245 throw new RuntimeException (e );
4346 }
@@ -50,13 +53,10 @@ public synchronized void init(ProcessingEnvironment processingEnv) {
5053
5154 @ Override
5255 public boolean process (Set <? extends TypeElement > annotations , RoundEnvironment roundEnv ) {
53- System .out .println ("annotatedElements:" );
5456 try {
5557 for (TypeElement annotation : annotations ) {
5658 Set <? extends Element > annotatedElements
5759 = roundEnv .getElementsAnnotatedWith (annotation );
58- System .out .println ("annotatedElements:" );
59- System .out .println (annotatedElements );
6060 annotatedElements .stream ().filter (element -> element .getKind ().equals (ElementKind .CLASS ))
6161 .map (e -> (TypeElement ) e )
6262 .forEach (e -> this .generateDoneableClass (e , printWriter ));
@@ -78,7 +78,14 @@ private void generateDoneableClass(TypeElement controllerClassSymbol, PrintWrite
7878 final String doneableClassName = customerResourceTypeElement .getSimpleName () + "Doneable" ;
7979 final String destinationClassFileName = customerResourceTypeElement .getQualifiedName () + "Doneable" ;
8080 final TypeName customResourceType = TypeName .get (resourceType );
81+
8182 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+ );
8289 printWriter .println (controllerClassSymbol .getQualifiedName () + "," + customResourceType .toString ());
8390 return ;
8491 }
0 commit comments