自定义编译器错误未删除(修复后),直到文件保存 [英] Custom compiler error isnt removed (after fixing) until file is saved

查看:324
本文介绍了自定义编译器错误未删除(修复后),直到文件保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我所做的每个注解处理器似乎都有这个问题。例如, @Constant 注释:

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 {

}

处理器:

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

这将引发编译器错误, @Constant 不是 public static final

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.

我使用Eclipse的Luna与Java 8u31。有什么办法防止这种情况?

I'm using Eclipse Luna with Java 8u31. Is there any way to prevent this?

推荐答案

编译器不会运行,直到文件被保存。这就是为什么不能确定编译器错误是固定的(直到文件被保存)。不,没有什么要解决(这是它的设计工作方式)。

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).

这篇关于自定义编译器错误未删除(修复后),直到文件保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆