public @interface Hello {
String value();
}
@SupportedAnnotationTypes("Hello")
@SupportedSourceVersion(SourceVersion.RELEASE_8)
public class HelloProcessor extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for (TypeElement annotation : annotations) {
Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(annotation);
for (Element element : elements) {
String value = element.getAnnotation(Hello.class).value();
System.out.println("Hello, " + value + "!");
}
}
return true;
}
}
@Hello("World")
public class MyClass {
@Hello("John")
public void sayHello() {
System.out.println("Hello, World!");
}
}