import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.*;
import javax.lang.model.element.*;
import javax.lang.model.util.*;
@SupportedAnnotationTypes("AnAnnotation")
@AnAnnotation
public class BasicVisitorProcessor extends AbstractProcessor {
@Override public boolean process(Set <? extends TypeElement > elements, RoundEnvironment env) {
ElementScanner7<Object, Object> scanner7 = new ElementScanner7<Object, Object>() {
@Override public Object visitVariable(VariableElement variable, final Object x) {
System.out.println("variable: " + variable);
return super.visitVariable(variable, x);
}
@Override public Object visitExecutable(ExecutableElement executable, Object x) {
System.out.println("executable: " + executable);
return super.visitExecutable(executable, x);
}
@Override public Object visitType(TypeElement type, Object x) {
System.out.println("type: " + type);
return super.visitType(type, x);
}
};
for(TypeElement typeElement: elements)
for(Element element: env.getElementsAnnotatedWith(typeElement))
scanner7.scan(element);
return true;
}
}
BasicVisitorProcessor.java: Rahmen eines Annotation-Prozessors mit Visitor.