IntelliJ IDEA @SuppressWarnings用于检查工具名称
我知道我可以抑制IntelliJ IDEA检查的警告:
@SuppressWarnings("CollectionDeclaredAsConcreteClass") public PropertiesExpander(Properties properties) { this.properties.putAll(properties); }
对于来自外部的人,可能不清楚需要哪种工具进行抑制。
PMD使用前缀:
@SuppressWarnings("PMD.UnusedLocalVariable")
FindBugs使用专用注释:
@SuppressFBWarnings("NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
有没有办法清楚地表明这种抑制只适用于IntelliJ IDEA?
为方法参数抑制此方法的一种方法是使用javadoc标记:
/** * @noinspection CollectionDeclaredAsConcreteClass */ public PropertiesExpander(Properties properties) { this.properties.putAll(properties); }
这个javadoc标签非常具有IntelliJ特性,因此其他任何工具都不应该有任何麻烦。 您可以通过识别它或通过添加一些注释来轻松识别它:
/** * @noinspection IntelliJ CollectionDeclaredAsConcreteClass */ public PropertiesExpander(Properties properties) { this.properties.putAll(properties); }
当然,你可以进一步缩短它:
/** @noinspection CollectionDeclaredAsConcreteClass */ public PropertiesExpander(Properties properties) { this.properties.putAll(properties); }
一般的做法
可以使用特殊注释而不是@SuppressWarnings
注释逐个禁止某些警告。
这是一个有很多警告的例子:
如果您在notUsedLocalVariable
上按Alt + Enter , notUsedLocalVariable
可以选择Suppress for statement with comment
在上下文菜单上Suppress for statement with comment
(在选择Remove variable ...
后右转)。
在某些变量/字段/方法上,所选抑制只是Suppress for statement
。
现在,如果你查看右侧字段,大多数(并非所有)警告都被抑制:
正如您所看到的,在同一评论行上可能存在多个抑制。
这似乎有点乏味但我认为这是你能做的最好的。
我找到了一种如何使用@SuppressWarnings
实现这一@SuppressWarnings
:
@SuppressWarnings("idea: CollectionDeclaredAsConcreteClass") public PropertiesExpander(Properties properties) { this.properties.putAll(properties); }
请注意,在idea:
之后必须有空格idea:
否则它不起作用。
- 是否可以为equals()和hashCode()更改IntelliJ的代码生成模板
- 在tomcat 7中运行并使用IntelliJ Idea 12创建的servlet中调用doGet方法两次
- 在Gradle构建之后,Intellij Idea不会在消息工具窗口中显示错误
- Intellij IDEA。 始终显示maven的`target`目录
- 类文件有错误的版本52.0,应该是50.0
- 使用Maven在IntelliJ中构建时解决PermGen错误?
- IntelliJ结构搜索和替换问题
- 使用IntelliJ IDEA处理源和测试的不同语言和目标级别
- 在Java调试器中,如何忽略从不通过我的代码的exception