title: Custom annotation processor - Java
body: <p>I have created a custom annotation and annotation processor using Abstract Processor. Which means I want to do annotation processing a before compile time.
  I exported my custom annotation and processor as a Jar and trying to use it with a simple java test program.
  I am sure that at compile time it finds my java processor class but somehow I am not getting o/p that I am expecting on console.
  Below is the code of the process method in my processor.</p>
  
  <p>Also, I am purposely using <code>@SupportedSourceVersion(SourceVersion.RELEASE_6)</code> so that I get a version warning which confirms that when I execute a test class it finds my annotation processor.</p>
  
  <p>Here is the <a href="https://github.com/yogeshdixit41/CustomAnnotationandProcessorJava" rel="nofollow">GitHub link</a> to my full project which also has the packaged Jar that I have created. </p>
  
  <pre><code>public boolean process(Set&lt;? extends TypeElement&gt; annotations, RoundEnvironment roundEnv) {
      // TODO Auto-generated method stub
  
      processingEnv.getMessager().printMessage(Kind.NOTE, "Hello compile time message");
  
      for (Element elem : roundEnv.getElementsAnnotatedWith(Contract.class)) {
          if(elem.getKind() != ElementKind.METHOD)
          {
              processingEnv.getMessager().printMessage(Kind.NOTE, "Error");
              return true;
          }
  
          System.out.println("Hello ... Inside for ");
          Contract contract = elem.getAnnotation(Contract.class);
          String message = "annotation found in " + elem.getSimpleName()
                         + " with complexity " + contract.pre_cond();
          processingEnv.getMessager().printMessage(Kind.NOTE, message);
      }
      return true; // no further processing of this annotation type
  }  
  </code></pre>
  
  <p>Below is the test class that I am using,</p>
  
  <pre><code>import annotations.Contract;
  
  public class AnnotationTest {
  
  
  public AnnotationTest()
  {
      super();
  }
  
  @Contract(pre_cond = { "var &gt; 0" })
  public static void testMethod(int var)
  {
      System.out.println("hello1");
  }
  
  public static void main(String args[])
  {
      testMethod(1);
      System.out.println("hello");
  }
  </code></pre>
  
  <p>I am compiling the above test class using <code>javac -cp newcontractlib.jar AnnotationTest.java</code> command and I just get the version warning and no messages from my process method.</p>