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");
}
}
什麼是'processingEnv'?或'processingEnv.messager'?你有它的來源? – madhead
'processingEnv'是'javax.annotation.processing.AbstractProcessor'的成員,屬於'ProcessingEnvironment'類型。 'messager'是'javax.annotation.processing.ProcessingEnvironment'中的'Messager'。 javac'Messager'將消息輸出到控制檯,所以我誤以爲Eclipse中的Messager會這樣做。 –