I am using java 6 api annotation processing. I have completed the following excellent tutorial on creating an annotation processor that displays a message at build time:
http://kerebus.com/2011/02/using-java-6-processors-in-eclipse/
However, in my case, I have a simple class:
import java.lang.annotation.ElementType; import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(value = ElementType.METHOD) public @interface Criteria { String id(); double width(); double height(); }
As you can see, the above annotation is made available to the JVM at runtime using the Save meta annotation. I use this “Criteria” annotation in the source code of another class to annotate a method, for example:
@Criteria(id = "fooBar", width = 22, height = 10 ) public void fooStream() { System.out.println("foo stream method"); }
At run time, I want to include the "fooStream" method in another class, ONLY if the variables that are being passed match the values of the elements in the @Criteria annotation, namely "width" and "height". My question is: how can I use the fooStream method and inject it into another class at runtime? Is it possible? I'm not looking for code examples, just the answers to the two above questions. In addition, the link at the top shows an example of creating code using instances of "JavaFileObject" and "Writer", where the generated code is passed as a string.
source share