mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
IDEA-110917 Incorrect "Redundant Cast" on Complex Conditional
This commit is contained in:
@@ -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;
|
||||
|
||||
+8
@@ -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);
|
||||
}
|
||||
}
|
||||
+1
@@ -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); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user