public @interface GenerateCode {
String value();
}
@SupportedAnnotationTypes("com.example.GenerateCode")
@SupportedSourceVersion(SourceVersion.RELEASE_8)
public class GenerateCodeProcessor extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for (TypeElement element : annotations) {
for (Element annotatedElement : roundEnv.getElementsAnnotatedWith(element)) {
if (annotatedElement.getKind() == ElementKind.CLASS) {
GenerateCode generateCode = annotatedElement.getAnnotation(GenerateCode.class);
String code = generateCode.value();
// ...
}
}
}
return true;
}
}
com.example.GenerateCodeProcessor