mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
dfa: suggest to replace variable with int constant (IDEA-111178)
This commit is contained in:
@@ -271,7 +271,7 @@ public class StandardInstructionVisitor extends InstructionVisitor {
|
||||
|
||||
if (methodType == MethodCallInstruction.MethodType.CAST) {
|
||||
if (qualifierValue instanceof DfaConstValue) {
|
||||
return factory.getConstFactory().createFromValue(castConstValue((DfaConstValue)qualifierValue), type, null);
|
||||
return factory.getConstFactory().createFromValue(castConstValue((DfaConstValue)qualifierValue), type, ((DfaConstValue)qualifierValue).getConstant());
|
||||
}
|
||||
return qualifierValue;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
class Test {
|
||||
public static final int CONST = 23942;
|
||||
private void test(int a) {
|
||||
if (a == CONST) {
|
||||
System.out.println(<caret><warning descr="Value 'a' is always 'CONST'">a</warning>);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
class Test {
|
||||
public static final int CONST = 23942;
|
||||
private void test(int a) {
|
||||
if (a == CONST) {
|
||||
System.out.println(<caret>CONST);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,4 +6,17 @@ class Test {
|
||||
}
|
||||
}
|
||||
|
||||
private void test2(int state) {
|
||||
switch (state) {
|
||||
case ONE:
|
||||
case TWO:
|
||||
if (state == TWO) {
|
||||
System.out.println("hello");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final int ONE = 1;
|
||||
public static final int TWO = 2;
|
||||
|
||||
}
|
||||
@@ -164,6 +164,11 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
|
||||
myFixture.launchAction(myFixture.findSingleIntention("Replace with 'CONST'"));
|
||||
myFixture.checkResultByFile(getTestName(false) + "_after.java");
|
||||
}
|
||||
public void testReportConstantReferences_ReplaceWithIntConstant() {
|
||||
doTestReplaceConstantReferences();
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user