Quantcast
Channel: How do I use Annotation Processing API in runtime? - Stack Overflow
Viewing all articles
Browse latest Browse all 3

How do I use Annotation Processing API in runtime?

$
0
0

I have and followed several Annotation Processing Tool (APT) guides (such as 1 and 2) on the Internet and have managed to get it working in compiler/ build time, and even got it working in Eclipse.

Is there a way I can use APT in run time to get a list of Types (Classes) using my annotation.

I wrote something like:

@SupportedAnnotationTypes("com.domain.MyAnnotation")public class MyAbstractProcessor extends AbstractProcessor {    public static Map<Element, MyAnnotation> patches = new HashMap<Element, MyAnnotation>();    @Override    public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnvironment) {        // Get all classes that has the annotation        Set<? extends Element> classElements = roundEnvironment.getElementsAnnotatedWith(MyAnnotation.class);        // For each class that has the annotation        for (final Element classElement : classElements) {            patches.put(classElement, annotation);

So MyAbstractProcessor.patches would be populate with a list of classes using the annotation. A noble idea, apart from the flaw that this APT is executing at build time, and not run time.

Is it even possible to use APT in run time?

Or am I using the wrong frameworks to get what I want?


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images