mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
field can be local: don't evaluate runtime constants (IDEA-157179)
This commit is contained in:
+2
-3
@@ -37,7 +37,6 @@ import com.intellij.psi.search.LocalSearchScope;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.Processor;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jdom.Element;
|
||||
@@ -214,8 +213,8 @@ public class FieldCanBeLocalInspectionBase extends BaseJavaBatchLocalInspectionT
|
||||
Set<PsiField> ignored) {
|
||||
try {
|
||||
final Ref<Collection<PsiVariable>> writtenVariables = new Ref<Collection<PsiVariable>>();
|
||||
final ControlFlow
|
||||
controlFlow = ControlFlowFactory.getInstance(body.getProject()).getControlFlow(body, AllVariablesControlFlowPolicy.getInstance());
|
||||
final ControlFlow controlFlow = ControlFlowFactory.getInstance(body.getProject())
|
||||
.getControlFlow(body, AllVariablesControlFlowPolicy.getInstance(), false, false);
|
||||
final List<PsiVariable> usedVars = ControlFlowUtil.getUsedVariables(controlFlow, 0, controlFlow.getSize());
|
||||
for (PsiVariable usedVariable : usedVars) {
|
||||
if (usedVariable instanceof PsiField) {
|
||||
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems/>
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
class test {
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
private test field;
|
||||
|
||||
private test(test field) {
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
private void method() {
|
||||
if (DEBUG) {
|
||||
field.method();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,7 @@ public class FieldCanBeLocalTest extends InspectionTestCase {
|
||||
public void testFieldUsedForWritingInLambda() throws Exception {doTest();}
|
||||
public void testStaticQualifiedFieldAccessForWriting() throws Exception {doTest();}
|
||||
public void testFieldReferencedFromAnotherObject() throws Exception {doTest();}
|
||||
public void testDontSimplifyRuntimeConstants() throws Exception {doTest();}
|
||||
public void testIgnoreAnnotated() throws Exception {
|
||||
final FieldCanBeLocalInspection inspection = new FieldCanBeLocalInspection();
|
||||
doTestConfigured(inspection);
|
||||
|
||||
Reference in New Issue
Block a user