我正在尝试学习如何使用注释处理器,但是我遇到了一个问题,我发现process()
方法被调用了两次。
src --
com/ilumer/
ExtractInterface(annotation)
InterfaceExtractorProcessor(processor)
Multiplier(.java)
ExtractInterface
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.TYPE)
public @interface ExtractInterface {
String value();
}
InterfaceExtractorProcessor
@SupportedAnnotationTypes("com.ilumer.ExtractInterface")
public class InterfaceExtractorProcessor extends AbstractProcessor {
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv){
System.out.println("Hello World");
return false;
}
}
javac com/ilumer/InterfaceExtractorProcessor.java
和javac -processor com.ilumer.InterfaceExtractorProcessor com/ilumer/Multiplier.java
输出
Hello World
Hello World
我尝试使用google和oracle doc找到一些解决方案,但未能找到解决此程序的任何解决方案。我的计划有什么问题。您可以通过Processor
告诉javac
的进展情况。
答案 0 :(得分:0)
我尝试使用-XprintRounds
来发现这个程序有两轮。
round 1:
: {com.ilumer.Multiplier}
: [com.ilumer.ExtractInterface]
: false
hello world
com.ilumer.Multiplier
round 2:
: {}
: []
: true
hello world