我在IntelliJ IDEA中创建了一个简单的注解处理器,并添加了注解配置文件,但是我不知道如何运行它。我知道注解处理器是在编译时起作用的,但是我没有看到任何来自注解处理器消息传递器的输出信息。
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;
}
}