mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
no matter if there are other variables having that constant value, it's still constant
This commit is contained in:
+1
-1
@@ -549,7 +549,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
|
||||
public DfaConstValue getConstantValue(DfaVariableValue value) {
|
||||
DfaConstValue result = null;
|
||||
for (DfaValue equal : getEqClassesFor(value)) {
|
||||
if (equal == value) continue;
|
||||
if (equal instanceof DfaVariableValue) continue;
|
||||
DfaConstValue constValue = asConstantValue(equal);
|
||||
if (constValue == null) return null;
|
||||
result = constValue;
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
public class Foo {
|
||||
private final boolean field = hashCode() == 2;
|
||||
|
||||
public void main(boolean b) {
|
||||
if (!b) {
|
||||
System.out.println(<warning descr="Value 'b' is always 'false'">b</warning>);
|
||||
|
||||
}
|
||||
if (field) {
|
||||
System.out.println(b);
|
||||
}
|
||||
if (b) {
|
||||
System.out.println(<warning descr="Value 'b' is always 'true'">b</warning>);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -147,12 +147,14 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
|
||||
}
|
||||
|
||||
public void testReportConstantReferences() {
|
||||
doTestReplaceConstantReferences();
|
||||
doTestReportConstantReferences();
|
||||
myFixture.launchAction(myFixture.findSingleIntention("Replace with 'null'"));
|
||||
myFixture.checkResultByFile(getTestName(false) + "_after.java");
|
||||
}
|
||||
|
||||
private void doTestReplaceConstantReferences() {
|
||||
public void testReportConstantReferencesAfterFinalFieldAccess() { doTestReportConstantReferences(); }
|
||||
|
||||
private void doTestReportConstantReferences() {
|
||||
DataFlowInspection inspection = new DataFlowInspection();
|
||||
inspection.SUGGEST_NULLABLE_ANNOTATIONS = true;
|
||||
myFixture.enableInspections(inspection);
|
||||
@@ -160,27 +162,27 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
|
||||
}
|
||||
|
||||
public void testReportConstantReferences_ReplaceWithString() {
|
||||
doTestReplaceConstantReferences();
|
||||
doTestReportConstantReferences();
|
||||
myFixture.launchAction(myFixture.findSingleIntention("Replace with 'CONST'"));
|
||||
myFixture.checkResultByFile(getTestName(false) + "_after.java");
|
||||
}
|
||||
public void testReportConstantReferences_ReplaceWithIntConstant() {
|
||||
doTestReplaceConstantReferences();
|
||||
doTestReportConstantReferences();
|
||||
myFixture.launchAction(myFixture.findSingleIntention("Replace with 'CONST'"));
|
||||
myFixture.checkResultByFile(getTestName(false) + "_after.java");
|
||||
}
|
||||
public void testReportConstantReferences_ReplaceWithEnum() {
|
||||
myFixture.addClass("package foo; public enum MyEnum { FOO }");
|
||||
doTestReplaceConstantReferences();
|
||||
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 }");
|
||||
doTestReplaceConstantReferences();
|
||||
doTestReportConstantReferences();
|
||||
assertEmpty(myFixture.filterAvailableIntentions("Replace with"));
|
||||
}
|
||||
public void testReportConstantReferences_Switch() { doTestReplaceConstantReferences(); }
|
||||
public void testReportConstantReferences_Switch() { doTestReportConstantReferences(); }
|
||||
|
||||
public void testCheckFieldInitializers() {
|
||||
doTest();
|
||||
|
||||
Reference in New Issue
Block a user