Disable “not used” warning for public methods of a

2019-02-01 15:59发布

The new intellij upgrade (10.5) now shows a warning that some of the methods defined for a class are not being used. These methods are public and I plan on not using all of them as I have created them to support the API expected. I would like to disable this warning (not used for public methods in a class). Is there a way to do it?.

8条回答
孤傲高冷的网名
2楼-- · 2019-02-01 16:15

Here is the 2019 update for: IntelliJ IDEA 2018.3.2 (Community Edition) Build #IC-183.4886.37, built on December 17, 2018

Settings | Editor | Inspections | Declaration redundancy | Unused declaration

enter image description here

查看更多
劳资没心,怎么记你
3楼-- · 2019-02-01 16:19

This is an old thread, but I ended up here faster than I could find a solution so I'm going to go ahead and share my findings. First, I am not sure if we are working with the same language (JS here,) but fiddling with the GUI-based tools, here is what I ended up with. The following code was giving me the infamous "not used" warning:

/**
 * @class sample class
 */
var MyClass = function () {
    return this;
};

/**
 * Some public method
 * @api public
 */
MyClass.prototype.myMethod = function () {
    return null;
};

There goes the "Unused definition myMethod" The inspector ended up suggesting to ignore this specific issue by adding

//noinspection JSUnusedGlobalSymbols

right on top of this specific method so that the following code no longer results in this warning:

//noinspection JSUnusedGlobalSymbols
/**
 * Some public method
 * @api public
 */
MyClass.prototype.myMethod = function () {
   return null;
};

Other warnings (typoes etc..) still seem to show up, including unused local variables and parameters, so it seems to isolate this particular issue. The downside is that it tends to pollute your code if you have lots of it...

查看更多
干净又极端
4楼-- · 2019-02-01 16:21

I think the best way to avoid the highlighting of that unused public methods is writing a couple of test for those methods in your API.

查看更多
我欲成王,谁敢阻挡
5楼-- · 2019-02-01 16:22

You can disable it for a single method like this

@SuppressWarnings("unused")
public void myMethod(){...}
查看更多
劳资没心,怎么记你
6楼-- · 2019-02-01 16:27

In the latest version, this options is under Settings>Inspections>Java>Declaration redundancy>Unused declaration>Methods uncheck options which are not required.

查看更多
唯我独甜
7楼-- · 2019-02-01 16:27

I just clicked "suppress for statement" and webstorm prepended this:

//noinspection JSUnusedGlobalSymbols
查看更多
登录 后发表回答