jeudi 30 novembre 2017

Load the class dynamically and get the annotated classes

import com.this.class.Factory;
      public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {

        // Itearate over all @Factory annotated elements
        for (Element annotatedElement : roundEnv.getElementsAnnotatedWith(Factory.class)) {
            ...
        }
      }

This works when I import the annotation class in the annotation processor. But when the annotation class is loaded dynamically doesn't works

Class<?> Factorry = class.forName("com.this.class.Factory")
 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {

        // Itearate over all @Factory annotated elements
        for (Element annotatedElement : roundEnv.getElementsAnnotatedWith(Factory.class)) {
            ...
        }
      }

How to pass the annotated Factory.class to getElementsAnnotatedWith when the class is loaded using class.forName()





Aucun commentaire:

Enregistrer un commentaire