Suppress some overlap with UnusedVariable

This commit is contained in:
Clément Fournier
2020-06-22 18:39:45 +02:00
parent 58adfca79f
commit b7c09a9555

View File

@ -130,8 +130,16 @@ public class UnusedAssignmentRule extends AbstractJavaRule {
.defaultValue(false)
.build();
private static final PropertyDescriptor<Boolean> REPORT_UNUSED_VARS =
PropertyFactory.booleanProperty("reportUnusedVariables")
.desc("Report variables that are only initialized, and never read at all. "
+ "The rule UnusedVariable already cares for that, so you can disable it if needed")
.defaultValue(false)
.build();
public UnusedAssignmentRule() {
definePropertyDescriptor(CHECK_PREFIX_INCREMENT);
definePropertyDescriptor(REPORT_UNUSED_VARS);
}
@Override
@ -169,6 +177,9 @@ public class UnusedAssignmentRule extends AbstractJavaRule {
if (isField) {
// assignments to fields don't really go out of scope
continue;
} else if (suppressUnusedVariableRuleOverlap(entry)) {
// see REPORT_UNUSED_VARS property
continue;
}
// This is a "DU" anomaly, the others are "DD"
reason = "goes out of scope";
@ -183,6 +194,10 @@ public class UnusedAssignmentRule extends AbstractJavaRule {
}
}
private boolean suppressUnusedVariableRuleOverlap(AssignmentEntry entry) {
return !getProperty(REPORT_UNUSED_VARS) && entry.rhs instanceof ASTVariableInitializer;
}
private boolean isIgnorablePrefixIncrement(JavaNode assignment) {
if (assignment instanceof ASTPreIncrementExpression
|| assignment instanceof ASTPreDecrementExpression) {