Issue
I have many Java classes with two constructors:
- a private constructor with no arguments and with unused warning suppression called by gson;
- a public constructor with arguments.
In one class IntelliJ informs me with a warning that the public constructor is never used. In all other classes there isn't the warning, but if I click Find Usage for the method it displays "Nothing found in project files".
Why is there a warning in some cases and not in others? How can I make IntelliJ always behave in the same way?
This is the class where the public constructor throws the warning:
public class ShopMarketAction extends Action {
private Boolean inRow = null;
private Integer index = null;
@SuppressWarnings("unused") // Called by gson
private ShopMarketAction() {
super(ActionType.SHOP_MARKET);
}
// THIS METHOD THROWS AN UNUSED WARNING
public ShopMarketAction(boolean inRow, int index) {
super(ActionType.SHOP_MARKET);
this.inRow = inRow;
this.index = index;
}
}
This is an example class where the public constructor doesn't throw the warning:
public class ProductionAction extends Action {
private Integer cardIndex = null;
@SuppressWarnings("unused") // Called by gson
private ProductionAction() {
super(ActionType.PRODUCE);
}
// THIS METHOD DOESN'T THROW THE WARNING BUT IS NEVER USED
public ProductionAction(int cardIndex) {
super(ActionType.PRODUCE);
this.cardIndex = cardIndex;
}
}
I specify that in both classes the method is not used yet.
The Action class that both classes extends:
public abstract class Action {
@SuppressWarnings({"unused", "FieldCanBeLocal"})
private final ActionType type; // Used by gson
protected Action(ActionType type) {
this.type = type;
}
}
The ActionType enum:
public enum ActionType {
SHOP_MARKET, PRODUCE;
}
Solution
I found what causes the problem: I have a non-Java file (an UXF file created by another application) which contains the name of all these methods and for some reason IntelliJ consider them as used because of this.
Answered By - Axelitama Answer Checked By - Willingham (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.