2013-01-23 45 views
7

Eclipse Juno在編譯類SimpleAnnotationTest時打印以下注釋處理器ComplexityProcessor輸出的消息?編譯後,我希望在控制檯窗格中看到消息,但它是空的。Eclipse在哪裏打印它在註釋處理器中輸出的消息?

public @interface Complexity 
{ 
    public enum Level 
    { 
     VERY_SIMPLE, 
     SIMPLE, 
     MEDIUM, 
     COMPLEX, 
     VERY_COMPLEX; 
    } 

    Level value() default Level.MEDIUM; 
} 

@SupportedAnnotationTypes("com.intelerad.annotations.Complexity") 
@SupportedSourceVersion(SourceVersion.RELEASE_6) 
public class ComplexityProcessor extends AbstractProcessor 
{ 
    @Override 
    public boolean process(final Set<? extends TypeElement> annotations, 
          final RoundEnvironment environment) 
    { 
     for (final Element element : environment.getElementsAnnotatedWith(Complexity.class)) 
     { 
      final Complexity complexity = element.getAnnotation(Complexity.class); 
      String message = 
       "Annotation found in " + element.getSimpleName() + " with complexity " + 
       complexity.value(); 

      // Where does Eclipse print this message? 
      processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, message); 
     } 
     return true; 
    } 
} 

@Complexity(Level.VERY_SIMPLE) 
public class SimpleAnnotationTest 
{ 
    @Complexity() 
    public void theMethod() 
    { 
     System.out.println("console output"); 
    } 
} 
+0

什麼是'processingEnv'?或'processingEnv.messager'?你有它的來源? – madhead

+0

'processingEnv'是'javax.annotation.processing.AbstractProcessor'的成員,屬於'ProcessingEnvironment'類型。 'messager'是'javax.annotation.processing.ProcessingEnvironment'中的'Messager'。 javac'Messager'將消息輸出到控制檯,所以我誤以爲Eclipse中的Messager會這樣做。 –

回答

7

我發現在Eclipse .metadata/.log輸出:

!ENTRY org.eclipse.jdt.apt.pluggable.core 1 1 2013-01-23 16:45:35.102 
!MESSAGE Annotation found in SimpleAnnotationTest with complexity VERY_SIMPLE 

!ENTRY org.eclipse.jdt.apt.pluggable.core 1 1 2013-01-23 16:45:35.102 
!MESSAGE Annotation found in theMethod with complexity MEDIUM 
+0

我們可以在控制檯處理器日誌中進行適當的監控嗎? – varpekv

相關問題