mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
field can be local: exclude all fields used in fields initializers (IDEA-72649 )
This commit is contained in:
@@ -229,14 +229,11 @@ public class FieldCanBeLocalInspection extends BaseLocalInspectionTool {
|
||||
}
|
||||
|
||||
@Override public void visitReferenceExpression(PsiReferenceExpression expression) {
|
||||
final PsiExpression qualifier = expression.getQualifierExpression();
|
||||
if (qualifier == null || qualifier instanceof PsiThisExpression) {
|
||||
final PsiElement resolved = expression.resolve();
|
||||
if (resolved instanceof PsiField) {
|
||||
final PsiField field = (PsiField)resolved;
|
||||
if (aClass.equals(field.getContainingClass())) {
|
||||
candidates.remove(field);
|
||||
}
|
||||
final PsiElement resolved = expression.resolve();
|
||||
if (resolved instanceof PsiField) {
|
||||
final PsiField field = (PsiField)resolved;
|
||||
if (aClass.equals(field.getContainingClass())) {
|
||||
candidates.remove(field);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
</problems>
|
||||
@@ -0,0 +1,9 @@
|
||||
class Test {
|
||||
public static final Object FOO = new Test().foo;
|
||||
|
||||
private final String foo;
|
||||
|
||||
private Test() {
|
||||
foo = "some text";
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ public class FieldCanBeLocalTest extends InspectionTestCase {
|
||||
public void testLocalStateVar2InnerClass() throws Exception { doTest(); }
|
||||
public void testNotConstantInitializer() throws Exception {doTest();}
|
||||
public void testInnerClassFieldInitializer() throws Exception {doTest();}
|
||||
public void testFieldUsedInConstantInitialization() throws Exception {doTest();}
|
||||
public void testFieldWithImmutableType() throws Exception {doTest();}
|
||||
public void testIgnoreAnnotated() throws Exception {
|
||||
final FieldCanBeLocalInspection inspection = new FieldCanBeLocalInspection();
|
||||
|
||||
Reference in New Issue
Block a user