为什么apt process()在这种情况下调用了两次

时间:2017-06-08 12:20:50

标签: java android annotations

我正在尝试学习如何使用注释处理器,但是我遇到了一个问题,我发现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.javajavac -processor com.ilumer.InterfaceExtractorProcessor com/ilumer/Multiplier.java

输出

Hello World

Hello World

我尝试使用google和oracle doc找到一些解决方案,但未能找到解决此程序的任何解决方案。我的计划有什么问题。您可以通过Processor告诉javac的进展情况。

1 个答案:

答案 0 :(得分:0)

我尝试使用-XprintRounds来发现这个程序有两轮。

 round 1:
        : {com.ilumer.Multiplier}
        : [com.ilumer.ExtractInterface]
        : false
hello world
com.ilumer.Multiplier
round 2:
        : {}
        : []
        : true
hello world