IDEA-110917 Incorrect "Redundant Cast" on Complex Conditional

This commit is contained in:
anna
2013-07-24 17:14:30 +02:00
parent d59413a8a1
commit 080504137e
3 changed files with 13 additions and 0 deletions
@@ -390,6 +390,10 @@ public class RedundantCastUtil {
return;
}
if (!checkResolveAfterRemoveCast(parent)) return;
final PsiExpression thenExpression = ((PsiConditionalExpression)parent).getThenExpression();
final PsiExpression elseExpression = ((PsiConditionalExpression)parent).getElseExpression();
final PsiExpression opposite = thenExpression == typeCast ? elseExpression : thenExpression;
if (opposite == null || !Comparing.equal(conditionalType, opposite.getType())) return;
}
} else if (parent instanceof PsiSynchronizedStatement && (expr instanceof PsiExpression && ((PsiExpression)expr).getType() instanceof PsiPrimitiveType)) {
return;
@@ -0,0 +1,8 @@
public class Foo {
public static void main(String[] args) {
final boolean b = false;
final Integer i = (<warning descr="Casting '3' to 'Integer' is redundant">Integer</warning>)3;
final short s = (short)(b ? i : (int)Integer.valueOf(3));
System.out.println(s);
}
}
@@ -57,4 +57,5 @@ public class LightAdvHighlightingJdk6Test extends LightDaemonAnalyzerTestCase {
public void testIDEADEV11877() throws Exception { setLanguageLevel(LanguageLevel.JDK_1_6); doTest(false, false); }
public void testIDEA108285() throws Exception { setLanguageLevel(LanguageLevel.JDK_1_6); doTest(false, false); }
public void testClassObjectAccessibility() throws Exception { setLanguageLevel(LanguageLevel.JDK_1_6); doTest(false, false); }
public void testRedundantCastInConditionalExpression() throws Exception { setLanguageLevel(LanguageLevel.JDK_1_6); doTest(true, false); }
}