简体   繁体   English

如何在IntelliJ IDEA中运行AnnotationProcessor?

[英]How to run AnnotationProcessor in IntelliJ IDEA?

I created simple Annotation processor in IntelliJ IDEA, added annotation profile, but I'm not understand how to run it. 我在IntelliJ IDEA中创建了简单的注释处理器,添加了注释配置文件,但是我不知道如何运行它。 I know that annotation processor works in compile time, but I didn't see any messages from Annotation processor messenger in output. 我知道注释处理器可以在编译时工作,但是我在输出中没有看到来自注释处理器Messenger的任何消息。

public class SimpleAnnotationProcessor extends AbstractProcessor {
@Override
public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) {

    processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR,"hello");
    for (final Element element : roundEnv.getElementsAnnotatedWith(Immutable.class)) {
        if (element instanceof TypeElement) {
            final TypeElement typeElement = (TypeElement) element;


            for (final Element eclosedElement: typeElement.getEnclosedElements()) {
                if (eclosedElement instanceof VariableElement) {
                    final VariableElement variableElement = (VariableElement) eclosedElement;

                    if (!variableElement.getModifiers().contains(Modifier.FINAL)) {
                        **processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR,
                                String.format("Class '%s' is annotated as @Immutable," +
                                                "but filed '%s' is not declared as final",
                                        typeElement.getSimpleName(), variableElement.getSimpleName()));**



                    }
                }
            }
        }
    }

    return true;
}

} }

设置->构建,执行,部署->编译器->注释处理器->启用注释处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM