Custom compiler error isnt removed (after fixing) until file is saved

独自空忆成欢 提交于 2020-01-06 13:12:51

问题


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?


回答1:


The compiler does not run until the file is saved. That is why the compiler error cannot be determined to be fixed (until the file is saved). No, there is nothing to fix (that is the way it is designed to work).




回答2:


I don't know how to make the error go away without saving (not sure that's possible), but I guess the next best thing is saving your file automatically.

Take a look at these plugins. You can also tweak how often they save.



来源:https://stackoverflow.com/questions/29597503/custom-compiler-error-isnt-removed-after-fixing-until-file-is-saved

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!