DataFlowInspection: unwrap parentheses when checking if redundant assignment is inside class initializer

This commit is contained in:
Tagir Valeev
2018-07-06 13:58:51 +07:00
parent 5777239b52
commit eda88dd574
2 changed files with 11 additions and 0 deletions
@@ -306,6 +306,7 @@ public class DataFlowInspectionBase extends AbstractBaseJavaLocalInspectionTool
HashSet<PsiElement> reportedAnchors,
DataFlowInstructionVisitor visitor) {
visitor.sameValueAssignments().forEach(expr -> {
expr = PsiUtil.skipParenthesizedExprDown(expr);
if(!reportedAnchors.add(expr)) return;
PsiAssignmentExpression assignment = PsiTreeUtil.getParentOfType(expr, PsiAssignmentExpression.class);
PsiElement context = PsiTreeUtil.getParentOfType(expr, PsiForStatement.class, PsiClassInitializer.class);
@@ -39,4 +39,14 @@ public class RedundantAssignment {
<warning descr="Variable is already assigned to this value">a</warning> = b;
}
}
class X {
int a;
int b;
{
a = 0;
((b)) = 0;
}
}
}