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


上一篇:
下一篇:
切换中文