3

I created simple Annotation processor in IntelliJ IDEA, added annotation profile, but I'm not understand how to run it. I know that annotation processor works in compile time, but I didn't see any messages from Annotation processor messenger in output.

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;
}

}

Pein
  • 1,059
  • 3
  • 10
  • 31

1 Answers1

0

Settings -> Build, Execution, Deployment -> Compiler -> Annotation Processors -> Enable Annotation Processing.

iamorozov
  • 761
  • 7
  • 26