私はインターネット上のいくつかの Annotation Processing Tool (APT) ガイド ( 1や2など) をフォローしており、コンパイラー/ビルド時にそれを機能させることができ、Eclipse でも機能させることができました。
実行時に APT を使用して、アノテーションを使用してタイプ (クラス) のリストを取得する方法はありますか?
私は次のようなものを書きました:
@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);
したがって、 MyAbstractProcessor.patches には、注釈を使用してクラスのリストが入力されます。この APT が実行時ではなくビルド時に実行されるという欠点を除けば、素晴らしいアイデアです。
実行時に APT を使用することは可能ですか?
それとも、私が望むものを得るために間違ったフレームワークを使用していますか?