IDEA-61127 (bad inspection for IF statement)

This commit is contained in:
Bas Leijdekkers
2010-11-19 19:40:56 +01:00
parent 1e95617391
commit f47ef7fea1
2 changed files with 33 additions and 0 deletions
@@ -320,11 +320,19 @@ public class SimplifiableIfStatementInspection extends BaseInspection {
if (thenReturn == null) {
return false;
}
final PsiType thenType = thenReturn.getType();
if (!PsiType.BOOLEAN.equals(thenType)) {
return false;
}
final PsiExpression elseReturn =
((PsiReturnStatement)elseBranch).getReturnValue();
if (elseReturn == null) {
return false;
}
final PsiType elseType = elseReturn.getType();
if (!PsiType.BOOLEAN.equals(elseType)) {
return false;
}
final boolean thenConstant = BoolUtils.isFalse(thenReturn) ||
BoolUtils.isTrue(thenReturn);
final boolean elseConstant = BoolUtils.isFalse(elseReturn) ||
@@ -368,10 +376,18 @@ public class SimplifiableIfStatementInspection extends BaseInspection {
if (thenRhs == null) {
return false;
}
final PsiType thenRhsType = thenRhs.getType();
if (!PsiType.BOOLEAN.equals(thenRhsType)) {
return false;
}
final PsiExpression elseRhs = elseExpression.getRExpression();
if (elseRhs == null) {
return false;
}
final PsiType elseRhsType = elseRhs.getType();
if (!PsiType.BOOLEAN.equals(elseRhsType)) {
return false;
}
final boolean thenConstant = BoolUtils.isFalse(thenRhs) ||
BoolUtils.isTrue(thenRhs);
final boolean elseConstant = BoolUtils.isFalse(elseRhs) ||
@@ -82,4 +82,21 @@ public class SimplifiableIfStatement {
return c || d;
}
Boolean wrong1(int i) {
if (i == 3) {
return null;
}
return false;
}
void wrong2(int i) {
Boolean a;
if (i == 3) {
a = null;
} else {
a = false;
}
}
}