Netbeans提供了很多自定义的“提示”,就像警告一样,只是大多数都无法被抑制(只是全局禁用IDE)。
但现在我查看使用的代码
@SuppressWarnings("element-type-mismatch")
抑制被称为“可疑方法调用”的提示/警告 (如 remove(...)
对于具有“错误”类型的集合)。
好吧,我永远不会想到用一个名为“可疑方法调用”的提示来抑制 SuppressWarnings
- 参数称为“元素类型不匹配”,但显然,它有效。
那么,这些参数是否存在“魔力列表”?
例如,我如何抑制提示/警告“收集字段的返回”?
注意:对于 这个类似的问题,“元素类型不匹配”未列出。
在简要介绍了NB-sourcecode之后,我在一些java.hint -classes中找到了这些:
@Hint(category="bitwise_operations", suppressWarnings="IncompatibleBitwiseMaskOperation")
@Hint(category="initialization", suppressWarnings="LeakingThisInConstructor")
@Hint(category="logging", suppressWarnings={"NonConstantLogger"}) //NOI18N
@Hint(category="logging", suppressWarnings={"ClassWithMultipleLoggers"}) //NOI18N
@Hint(category="logging", suppressWarnings={"ClassWithoutLogger"}, enabled=false) //NOI18N
@Hint(category="code_maturity", suppressWarnings="UseOfObsoleteCollectionType")
@Hint(category="initialization", suppressWarnings="OverridableMethodCallInConstructor")
@Hint(category="bitwise_operations", suppressWarnings="PointlessBitwiseExpression")
@Hint(category="code_maturity", suppressWarnings="CallToThreadDumpStack")
@Hint(category="bitwise_operations", suppressWarnings="ShiftOutOfRange")
@Hint(category="initialization", suppressWarnings="StaticNonFinalUsedInInitialization")
@Hint(category="code_maturity", enabled = false, suppressWarnings="UseOfSystemOutOrSystemErr")
@Hint(category="code_maturity", suppressWarnings="CallToPrintStackTrace")
显然,并非所有显示为警告的IDE提示都可以抑制...
不知道为什么,'因为它们中很多很容易扩展的AbstractHint类提供了这种能力......
这些只是抑制名称,所以要找到它们所代表的警告名称的映射,需要在源代码中进行更深入的挖掘。
在简要介绍了NB-sourcecode之后,我在一些java.hint -classes中找到了这些:
@Hint(category="bitwise_operations", suppressWarnings="IncompatibleBitwiseMaskOperation")
@Hint(category="initialization", suppressWarnings="LeakingThisInConstructor")
@Hint(category="logging", suppressWarnings={"NonConstantLogger"}) //NOI18N
@Hint(category="logging", suppressWarnings={"ClassWithMultipleLoggers"}) //NOI18N
@Hint(category="logging", suppressWarnings={"ClassWithoutLogger"}, enabled=false) //NOI18N
@Hint(category="code_maturity", suppressWarnings="UseOfObsoleteCollectionType")
@Hint(category="initialization", suppressWarnings="OverridableMethodCallInConstructor")
@Hint(category="bitwise_operations", suppressWarnings="PointlessBitwiseExpression")
@Hint(category="code_maturity", suppressWarnings="CallToThreadDumpStack")
@Hint(category="bitwise_operations", suppressWarnings="ShiftOutOfRange")
@Hint(category="initialization", suppressWarnings="StaticNonFinalUsedInInitialization")
@Hint(category="code_maturity", enabled = false, suppressWarnings="UseOfSystemOutOrSystemErr")
@Hint(category="code_maturity", suppressWarnings="CallToPrintStackTrace")
显然,并非所有显示为警告的IDE提示都可以抑制...
不知道为什么,'因为它们中很多很容易扩展的AbstractHint类提供了这种能力......
这些只是抑制名称,所以要找到它们所代表的警告名称的映射,需要在源代码中进行更深入的挖掘。
该 文件 说:
编译器供应商应记录它们支持的警告名称以及此注释类型。鼓励他们合作以确保相同的名称在多个编译器中工作。
由于NetBeans使用的是javac,我想, 这是一个清单。
另见这个问题。
如果您正在使用其他编译器或某些编译器插件,请搜索其文档。
那个名单很难找到。找到了源头 hint classes
Netbeans。
所以'列表'是 这里。 (另请查看子包;例如 jdk
和 perf
)
所有课程都可以通过使用它来抑制 camel cases
名字如:
// org.netbeans.modules.java.hints.jdk.UnnecessaryBoxing.java
@SuppressWarnings("UnnecessaryBoxing")