IG: fix "'if' statement with identical branches" false positive

This commit is contained in:
Bas Leijdekkers
2016-06-23 14:51:17 +02:00
parent 68d99378ee
commit a02562cadb
2 changed files with 15 additions and 3 deletions
@@ -174,8 +174,8 @@ public class IfStatementWithIdenticalBranchesInspection
@Override
public void visitIfStatement(@NotNull PsiIfStatement ifStatement) {
super.visitIfStatement(ifStatement);
final PsiStatement elseBranch = unwrap(ifStatement.getElseBranch());
final PsiStatement thenBranch = unwrap(ifStatement.getThenBranch());
final PsiStatement elseBranch = ifStatement.getElseBranch();
final PsiStatement thenBranch = ifStatement.getThenBranch();
if (thenBranch == null) {
return;
}
@@ -194,7 +194,9 @@ public class IfStatementWithIdenticalBranchesInspection
}
}
private boolean isDuplicate(@NotNull PsiElement element1, @NotNull PsiElement element2) {
private boolean isDuplicate(@NotNull PsiStatement element1, @NotNull PsiStatement element2) {
element1 = unwrap(element1);
element2 = unwrap(element2);
final InputVariables inputVariables =
new InputVariables(Collections.emptyList(), element1.getProject(), new LocalSearchScope(element1), false);
final DuplicatesFinder finder = new DuplicatesFinder(new PsiElement[]{element1}, inputVariables, null, Collections.emptyList());
@@ -214,4 +214,14 @@ class NotADup {
private Object bar(Object x) {
return null;
}
void nesting(int i, int j) {
if (i == 2) {
System.out.println("2");
} else {
if (j == 2) {
System.out.println("2");
}
}
}
}