2 Replies Latest reply: Apr 9, 2012 10:37 PM by 801313 RSS

    Having trouble getting my annotation to process

      I have an annotation that I'm working with from an annotation tutorial:

      package com.tjacobs.annotation
      public @interface Complexity {
           public enum Level {
           Level value() default Level.MEDIUM;

      Here is the processor I built to handle it:

      public class ComplexityProcessor extends AbstractProcessor {

      public ComplexityProcessor() {

      public boolean process(Set<? extends TypeElement> annotations,
      RoundEnvironment roundEnv) {
           for (Element elem : roundEnv.getElementsAnnotatedWith(Complexity.class)) {
      Complexity complexity = elem.getAnnotation(Complexity.class);
      String message = "annotation found in " + elem.getSimpleName()
      + " with complexity " + complexity.value();
      processingEnv.getMessager().printMessage(javax.tools.Diagnostic.Kind.NOTE, message);
      try {
                          JavaFileObject jfo = processingEnv.getFiler().createSourceFile("Foo");
                          BufferedWriter bw = new BufferedWriter(jfo.openWriter());
                     } catch (IOException e) {
                          // TODO Auto-generated catch block

      return true; // no further processing of this annotation type

      I created a file "Processor" in META-INF/services with the following content:


      I jarred up the processor class and the META_INF/services, added it as an annotation processor in eclipse.

      Then I created a test class

      public class AnnoTest {

           * @param args
           public static void main(String[] args) {
                // TODO Auto-generated method stub



      But I'm not seeing any generated output. What am I doing wrong?

      Edited by: tjacobs01 on Apr 5, 2012 12:09 PM