Java中有效的@SuppressWarnings警告名称列表是什么?
在@SuppressWarnings("")中位于("")之间的位。
Java中有效的@SuppressWarnings警告名称列表是什么?
在@SuppressWarnings("")中位于("")之间的位。
当前回答
我只想补充一点,在https://gist.github.com/vegaasen/157fbc6dce8545b7f12c上有一个IntelliJ抑制参数的主列表
它看起来相当全面。部分:
Warning Description - Warning Name
"Magic character" MagicCharacter
"Magic number" MagicNumber
'Comparator.compare()' method does not use parameter ComparatorMethodParameterNotUsed
'Connection.prepare*()' call with non-constant string JDBCPrepareStatementWithNonConstantString
'Iterator.hasNext()' which calls 'next()' IteratorHasNextCallsIteratorNext
'Iterator.next()' which can't throw 'NoSuchElementException' IteratorNextCanNotThrowNoSuchElementException
'Statement.execute()' call with non-constant string JDBCExecuteWithNonConstantString
'String.equals("")' StringEqualsEmptyString
'StringBuffer' may be 'StringBuilder' (JDK 5.0 only) StringBufferMayBeStringBuilder
'StringBuffer.toString()' in concatenation StringBufferToStringInConcatenation
'assert' statement AssertStatement
'assertEquals()' between objects of inconvertible types AssertEqualsBetweenInconvertibleTypes
'await()' not in loop AwaitNotInLoop
'await()' without corresponding 'signal()' AwaitWithoutCorrespondingSignal
'break' statement BreakStatement
'break' statement with label BreakStatementWithLabel
'catch' generic class CatchGenericClass
'clone()' does not call 'super.clone()' CloneDoesntCallSuperClone
其他回答
我注意到IntelliJ中可以自动生成noinspection
确保你在声明之前没有计划@SuppressWarninigs 现在你可以自动生成特定的//noinspection,点击Alt+Enter当你有警告选择,然后使用右箭头键看到Suppress for…选项
当我想要压制来自IntelliJ的“switch有太少case标签”警告时,就结束在这里。我没有找到IntelliJ的@SuppressWarning支持的完整列表,但//noinspection为我做到了这一点。
我最喜欢的是IntelliJ中的@SuppressWarnings(“WeakerAccess”),当它认为你应该使用一个比你正在使用的更弱的访问修饰符时,它不会抱怨。为了支持测试,我们必须对一些方法进行公共访问,而@VisibleForTesting注释并不能阻止警告。
埃塔: “匿名者”在@MattCampbell链接的页面上评论了以下非常有用的注释:
You shouldn't need to use this list for the purpose you are describing. IntelliJ will add those SuppressWarnings for you automatically if you ask it to. It has been capable of doing this for as many releases back as I remember. Just go to the location where you have the warning and type Alt-Enter (or select it in the Inspections list if you are seeing it there). When the menu comes up, showing the warning and offering to fix it for you (e.g. if the warning is "Method may be static" then "make static" is IntellJ's offer to fix it for you), instead of selecting "enter", just use the right arrow button to access the submenu, which will have options like "Edit inspection profile setting" and so forth. At the bottom of this list will be options like "Suppress all inspections for class", "Suppress for class", "Suppress for method", and occasionally "Suppress for statement". You probably want whichever one of these appears last on the list. Selecting one of these will add a @SuppressWarnings annotation (or comment in some cases) to your code suppressing the warning in question. You won't need to guess at which annotation to add, because IntelliJ will choose based on the warning you selected.
这似乎是一个更完整的列表,在那里我发现了一些特定于Android-Studio的警告,我在其他地方找不到(例如SynchronizeOnNonFinalField)
https://jazzy.id.au/2008/10/30/list_of_suppresswarnings_arguments.html
哦,现在SO的指导方针与SO的限制相反。 一方面,我应该复制列表,而不是只提供链接。 但另一方面,这将超过允许的最大字符数。所以让我们希望这个链接不会断裂。
这取决于您的IDE或编译器。
下面是Eclipse Galileo的列表:
all to suppress all warnings boxing to suppress warnings relative to boxing/unboxing operations cast to suppress warnings relative to cast operations dep-ann to suppress warnings relative to deprecated annotation deprecation to suppress warnings relative to deprecation fallthrough to suppress warnings relative to missing breaks in switch statements finally to suppress warnings relative to finally block that don’t return hiding to suppress warnings relative to locals that hide variable incomplete-switch to suppress warnings relative to missing entries in a switch statement (enum case) nls to suppress warnings relative to non-nls string literals null to suppress warnings relative to null analysis restriction to suppress warnings relative to usage of discouraged or forbidden references serial to suppress warnings relative to missing serialVersionUID field for a serializable class static-access to suppress warnings relative to incorrect static access synthetic-access to suppress warnings relative to unoptimized access from inner classes unchecked to suppress warnings relative to unchecked operations unqualified-field-access to suppress warnings relative to field access unqualified unused to suppress warnings relative to unused code
Indigo列表增加了:
压制相对于Javadoc警告的警告 原始类型来抑制与原始类型使用相关的警告 static-用于抑制相对于可声明为静态的方法的警告的方法 Super来抑制相对于覆盖没有Super调用的方法的警告
朱诺的列表增加了:
资源来抑制与使用Closeable类型资源相关的警告 Sync-override在覆盖同步方法时,由于缺少同步而抑制警告
Kepler和Luna使用与Juno相同的令牌列表(list)。
其他的将是相似的,但有所不同。
我只想补充一点,在https://gist.github.com/vegaasen/157fbc6dce8545b7f12c上有一个IntelliJ抑制参数的主列表
它看起来相当全面。部分:
Warning Description - Warning Name
"Magic character" MagicCharacter
"Magic number" MagicNumber
'Comparator.compare()' method does not use parameter ComparatorMethodParameterNotUsed
'Connection.prepare*()' call with non-constant string JDBCPrepareStatementWithNonConstantString
'Iterator.hasNext()' which calls 'next()' IteratorHasNextCallsIteratorNext
'Iterator.next()' which can't throw 'NoSuchElementException' IteratorNextCanNotThrowNoSuchElementException
'Statement.execute()' call with non-constant string JDBCExecuteWithNonConstantString
'String.equals("")' StringEqualsEmptyString
'StringBuffer' may be 'StringBuilder' (JDK 5.0 only) StringBufferMayBeStringBuilder
'StringBuffer.toString()' in concatenation StringBufferToStringInConcatenation
'assert' statement AssertStatement
'assertEquals()' between objects of inconvertible types AssertEqualsBetweenInconvertibleTypes
'await()' not in loop AwaitNotInLoop
'await()' without corresponding 'signal()' AwaitWithoutCorrespondingSignal
'break' statement BreakStatement
'break' statement with label BreakStatementWithLabel
'catch' generic class CatchGenericClass
'clone()' does not call 'super.clone()' CloneDoesntCallSuperClone