Every annotation processor I've made seems to have this problem. For example, a @Constant
annotation:
package annotations;
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.FIELD)
public @interface Constant {
}
The processor:
package processor;
@SupportedAnnotationTypes("annotations.Constant")
@SupportedSourceVersion(SourceVersion.RELEASE_8)
public final class ConstantProcessor extends AbstractProcessor {
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for(Element element : roundEnv.getElementsAnnotatedWith(Constant.class)) {
Set<Modifier> modifiers = element.getModifiers();
if(!modifiers.contains(Modifier.PUBLIC) || !modifiers.contains(Modifier.STATIC) || !modifiers.contains(Modifier.FINAL)) {
processingEnv.getMessager().printMessage(Kind.ERROR, "A constant must be public, static and final", element);
}
}
return false;
}
}
This will raise a compiler error if a field annotated with @Constant
isn't public static final
.
The problem is, the error won't appear until I save the file. Same with the error going away. If I fix the problem, the error stays until I save the file.
I'm using Eclipse Luna with Java 8u31. Is there any way to prevent this?