Java 6 - 注释处理器和代码添加
2022-09-03 15:17:57
我写了一个自定义注释,其中包含属性的元数据和:AnnotationProcessor
@SupportedAnnotationTypes({"<package>.Property"})
public class PropertyProcessor extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
// Get messager object
Messager messager = processingEnv.getMessager();
// Iterate through the annotations
for(TypeElement typeElement : annotations) {
// Iterate through the annotated elements
for(Element element : roundEnv.getElementsAnnotatedWith(typeElement)) {
// Get Property annotation
Property property = element.getAnnotation(Property.class);
}
}
return false;
}
}
这是个问题,我以前使用过Javassist,但它取决于类加载器,我认为它不适合OSGi应用程序。我想在编译带有注释的类时更改生成的字节码。Property