IDEA-112968 Show "Value is always" warning only for null/true/false

This commit is contained in:
peter
2013-09-06 17:31:32 +02:00
parent ae942600e1
commit 6b3d77c6b3
2 changed files with 6 additions and 7 deletions
@@ -169,7 +169,7 @@ public class StandardInstructionVisitor extends InstructionVisitor {
DfaValue dfaValue = instruction.getValue();
if (dfaValue instanceof DfaVariableValue) {
DfaConstValue constValue = memState.getConstantValue((DfaVariableValue)dfaValue);
myPossibleVariableValues.putValue(instruction, constValue != null ? constValue : ANY_VALUE);
myPossibleVariableValues.putValue(instruction, constValue != null && (constValue.getValue() == null || constValue.getValue() instanceof Boolean) ? constValue : ANY_VALUE);
}
}
return super.visitPush(instruction, runner, memState);
@@ -161,28 +161,27 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
myFixture.testHighlighting(true, false, true, getTestName(false) + ".java");
}
public void testReportConstantReferences_ReplaceWithString() {
public void _testReportConstantReferences_ReplaceWithString() {
doTestReportConstantReferences();
myFixture.launchAction(myFixture.findSingleIntention("Replace with 'CONST'"));
myFixture.checkResultByFile(getTestName(false) + "_after.java");
}
public void testReportConstantReferences_ReplaceWithIntConstant() {
public void _testReportConstantReferences_ReplaceWithIntConstant() {
doTestReportConstantReferences();
myFixture.launchAction(myFixture.findSingleIntention("Replace with 'CONST'"));
myFixture.checkResultByFile(getTestName(false) + "_after.java");
}
public void testReportConstantReferences_ReplaceWithEnum() {
public void _testReportConstantReferences_ReplaceWithEnum() {
myFixture.addClass("package foo; public enum MyEnum { FOO }");
doTestReportConstantReferences();
myFixture.launchAction(myFixture.findSingleIntention("Replace with 'FOO'"));
myFixture.checkResultByFile(getTestName(false) + "_after.java");
}
public void testReportConstantReferences_NotInComplexAssignment() {
myFixture.addClass("package foo; public enum MyEnum { FOO }");
public void _testReportConstantReferences_NotInComplexAssignment() {
doTestReportConstantReferences();
assertEmpty(myFixture.filterAvailableIntentions("Replace with"));
}
public void testReportConstantReferences_Switch() { doTestReportConstantReferences(); }
public void _testReportConstantReferences_Switch() { doTestReportConstantReferences(); }
public void testCheckFieldInitializers() {
doTest();