IDEA-86945 'Redundant type cast' and 'Constant conditions & exceptions' inspections

This commit is contained in:
peter
2012-06-19 18:41:10 +02:00
parent f54bfe021c
commit 96d18fe897
3 changed files with 17 additions and 0 deletions
@@ -147,6 +147,10 @@ public class StandardInstructionVisitor extends InstructionVisitor {
}
}
if (instruction.getCastTo() instanceof PsiPrimitiveType) {
memState.push(runner.getFactory().getBoxedFactory().createUnboxed(memState.pop()));
}
return nextInstruction(instruction, runner, memState);
}
@@ -0,0 +1,11 @@
class Foo {
public void foo() {
Integer a = 128;
Integer b = (int) a;// cast is necessary because new object is created
Integer c = 128;
System.out.println(a == b);
System.out.println(<warning descr="Condition 'a == c' is always 'false'">a == c</warning>);
}
}
@@ -64,4 +64,6 @@ public class DataFlowInspectionFixtureTest extends JavaCodeInsightFixtureTestCas
public void testComparingToNotNullShouldNotAffectNullity() throws Throwable { doTest(); }
public void testStringTernaryAlwaysTrue() throws Throwable { doTest(); }
public void testBoxing128() throws Throwable { doTest(); }
}