checker框架,有什么办法可以silence/disable type.anno.before.modifier警告吗?

checker framework, is there any way to silence/disable type.anno.before.modifier warning?

我想试试检查器框架,但我得到了很多这样的东西

/Users/calebcushing/IdeaProjects/ppm/scaf/src/main/java/com/xenoterracide/scaf/Config.java:22: warning: [type.anno.before.modifier] write type annotation @NonNull() immediately before type, after modifiers [abstract]
  abstract Map<String, SkeletonConfiguration> getTemplates();

对于此代码

  @Nullable
  abstract String getWorkdir();

好像建议我写

  abstract @Nullable String getWorkdir();

但这不利于 JLS,是否可以禁用它?

  1. 你说,“这违背了 JLS”,但事实并非如此。合法Java,风格更佳

  2. Checker Framework Manual describes how to suppress warnings,例如通过 @SuppressWarning("type.anno.before.modifier") 注释或 -AsuppressWarnings=type.anno.before.modifier 命令行参数。

but that goes against the JLS

回答纯粹是为了这个陈述:检查器正在执行 JLS 9.7.4:

中描述的内容

It is customary, though not required, to write declaration annotations before all other modifiers, and type annotations immediately before the type to which they apply.

如上所示in the Javadoc of Checker's Nullable:

Nullable is a type annotation

因此它应该出现在它所应用的类型之前,即方法的 return 类型。


您还在评论中链接了 JLS 8.4.3。这显示语法产生式 MethodModifier:

MethodModifier:
    (one of)
    Annotation public protected private
    abstract static final synchronized native strictfp

这没有直接关系:一方面,它说你只能使用这些修饰符之一,所以它不能告诉你任何关于排序的信息。但是如果勾选JLS 19,就可以找到MethodModifier出现的上下文:

MethodDeclaration:
    {MethodModifier} MethodHeader MethodBody

MethodModifier:
    (one of)
    Annotation public protected private
    abstract static final synchronized native strictfp

MethodHeader:
    Result MethodDeclarator [Throws]
    TypeParameters {Annotation} Result MethodDeclarator [Throws]

因此,检查器告诉您按照 MethodHeader 生产中的指定放置注释。