• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

CompileTime Annotion with Eclipse

 
Marshal
Posts: 4491
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have written a simple compile-time Annotation Processor to ensure that a field annotated with @TypeChecker is of type String.

I packaged it up according to specifications, including having a file named META-INF/services/javax.annotation.processing.Processor which contains the name of the Annotation Processor:
   jar -tf lib\TypeCheckerProcessor.jar
   META-INF/MANIFEST.MF
   com/mcleodnet/TypeCheckerProcessor.class
   META-INF/services/javax.annotation.processing.Processor


When I compile from the comand line using this class:
the Annotation Processor code runs, and produces the expected error message:
   javac -cp lib\TypeCheckerProcessor.jar -d bin src\com\mcleodnet\TestClass.java
   error: Field 'myStringField' in class 'TestClass' must be type String
   1 error


After configuring Ecplise to perform annoation processing for my Annotation Processor, I am expecting Eclipse to show the error in the editor, but it is not working (I see no indication that the Annotation Processor ran).

My Eclipse configuration related to annotation processing:





Has anyone else worked with annotation processing with Eclipse that might be able to help me understand why it is not working?
 
Ron McLeod
Marshal
Posts: 4491
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, it turns out that Eclipse was running the Annotation Processor, but I was looking in the wrong place for the results.



My goal is to have something like the red wavey line in the editor, and actually have the build fail, so I still have some more digging to do.
 
Ron McLeod
Marshal
Posts: 4491
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I finally got it!



This is what I found:
   - I needed to include the reference to the errored element is printMessage method to have it flagged in the editor.

   - I got rid of returning false when a error was found - this halted compliation and caused further errors/warnings not to be found/displayed.

   - I got rid of explictly checking for elements annotated with TypeChecker - this was redundant since the Annotation Processor would only be called for classes which have this annotation due to its @SupportedAnnotationTypes("com.mcleodnet.TypeChecker") annotation.

   - I got rid of checking to see if element was non-field type - this was redundant since TypeChecker is defined as @Target(ElementType.FIELD), so it could only be applicable for fields.

 
reply
    Bookmark Topic Watch Topic
  • New Topic