[英]How to get the @SuppressWarnings warning name for an IntelliJ warning?
IntelliJ wrongly tells me that a field initializer is redundant, but it is in fact used by Lombok's @Builder.Default
. IntelliJ错误地告诉我字段初始化程序是多余的,但它实际上是由Lombok的
@Builder.Default
。
I would like to suppress this warning using @SuppressWarnings
but I don't know what the warning is called (alt-enter also gives me no option to suppress). 我想使用
@SuppressWarnings
来抑制此警告,但我不知道警告的内容是什么(alt-enter也没有给我压制的选项)。 How can I find a warning's name in IntelliJ? 如何在IntelliJ中找到警告名称?
By putting your cursor on the warning and pressing Alt + Enter , it should open up a menu. 将光标置于警告上并按Alt + Enter ,它将打开一个菜单。 In this menu, there should be an option to remove the field.
在此菜单中,应该有一个删除字段的选项。 Navigate to this option and press → .
导航到此选项并按→ 。 This opens up a sub-menu which contains the options to suppress the warning.
这将打开一个子菜单,其中包含禁止警告的选项。 By doing so, IntelliJ will generate the appropriate annotation.
通过这样做,IntelliJ将生成适当的注释。
In your case, the annotation should probably be along the lines of @SuppressWarnings("unused")
or @SuppressWarnings("UnusedAssignment")
. 在您的情况下,注释可能应该与
@SuppressWarnings("unused")
或@SuppressWarnings("UnusedAssignment")
。
Looks like there is another answer here for how to suppress unused methods or members, which is to add the annotation @SuppressWarnings("unused")
. 看起来这里有另一个答案可以抑制未使用的方法或成员,即添加注释
@SuppressWarnings("unused")
。 Or, if you want to suppress a local variable, then you'd have to insert a line comment // noinspection unused
, like 或者,如果要抑制局部变量,则必须插入行注释
// noinspection unused
,如
// noinspection unused
long int i = 0;
To answer your question of, "How can I find a warning's name in Intellij?", I found a web page from a James Roper who lists out all the Intellij warning keywords paired with a brief definition. 要回答你的问题,“如何在Intellij中找到警告名称?”,我找到了一个James Roper的网页,其中列出了所有Intellij警告关键字以及简要定义。 https://jazzy.id.au/2008/10/30/list_of_suppresswarnings_arguments.html
https://jazzy.id.au/2008/10/30/list_of_suppresswarnings_arguments.html
For example, the one I was after was 例如,我追求的那个是
Redundant local variable = UnnecessaryLocalVariable
冗余局部变量= UnnecessaryLocalVariable
That list in Roper's page only covers the special warnings invented by JetBrains. Roper页面中的列表仅涵盖了JetBrains发明的特殊警告。 The warning you need, "unused", has been around for a long time and pre-dates IntelliJ.
您需要的警告“未使用”已经存在很长时间并且在IntelliJ之前。 Some are a part of the java compiler.
有些是java编译器的一部分。 For a list of the javac warnings, I found from https://javarevisited.blogspot.com/2015/09/what-is-suppresswarnings-annotation-in-java-unchecked-raw-serial.html that you can run
javac -X
. 有关javac警告的列表,我从https://javarevisited.blogspot.com/2015/09/what-is-suppresswarnings-annotation-in-java-unchecked-raw-serial.html找到了你可以运行
javac -X
For Java 1.8, I found 对于Java 1.8,我找到了
all,auxiliaryclass,cast,classfile,deprecation,dep-ann,divzero,empty,fallthrough,finally,options,overloads,overrides,path,processing,rawtypes,serial,static,try,unchecked,varargs
That still doesn't lead us to unused
. 这仍然不会导致我们
unused
。 The unused
warning came from Eclipse and is also supported by Intellij. unused
警告来自Eclipse,并且也受到Intellij的支持。 For a list of Eclipse warnings, see https://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftask-suppress_warnings.htm 有关Eclipse警告的列表,请参阅https://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftask-suppress_warnings.htm
That pages contains 该页面包含
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.