IntelliJ IDEA @SuppressWarnings for inspection with name of tool

情到浓时终转凉″ 提交于 2019-12-04 11:36:27

A way of suppressing this for method arguments is to use a javadoc tag instead:

/**
 * @noinspection CollectionDeclaredAsConcreteClass
 */
public PropertiesExpander(Properties properties) {
    this.properties.putAll(properties);
}

This javadoc tag is very IntelliJ specific so no other tool should have any troubles with it. And you can easily identify it by just recognize it as it is or by adding some comment to it:

/**
 * @noinspection IntelliJ CollectionDeclaredAsConcreteClass
 */
public PropertiesExpander(Properties properties) {
    this.properties.putAll(properties);
}

And of course you can shorten it up even more:

/** @noinspection CollectionDeclaredAsConcreteClass */
public PropertiesExpander(Properties properties) {
    this.properties.putAll(properties);
}

General approach

It is possible to suppress some warnings on a one-by-one basis with special comments instead of the @SuppressWarnings annotation.

Here's an example with lots of warnings:

If you press Alt+Enter on notUsedLocalVariable you can then choose Suppress for statement with comment on the context menu (after going right when choosing Remove variable ...).

On some variables/fields/methods the selected suppression is just Suppress for statement.

And now most (not all) of the warnings has been suppressed if you look in the right-hand field:

As you can see there can be several suppressions on the same comment line.

This can seem to be a bit tedious but I think it's the best you can do.

I found a way how to achieve that with @SuppressWarnings:

@SuppressWarnings("idea: CollectionDeclaredAsConcreteClass")
public PropertiesExpander(Properties properties) {
    this.properties.putAll(properties);
}

Note that there must be space after idea:, otherwise it doesn't work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!