• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

CompileTime Annotion with Eclipse  RSS feed

 
Bartender
Posts: 2038
273
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • 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
Bartender
Posts: 2038
273
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • 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
Bartender
Posts: 2038
273
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • 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.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!