mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
FieldCanBeLocalInspection: do not report fields that have unknown types of usages (IDEA-258498)
GitOrigin-RevId: 36ccd2c540a08614d34c97badee31b2d264cdd12
This commit is contained in:
committed by
intellij-monorepo-bot
parent
13978065e4
commit
051ec9b3bb
+1
-1
@@ -78,7 +78,7 @@ public class FieldCanBeLocalInspection extends AbstractBaseJavaLocalInspectionTo
|
||||
final Map<PsiCodeBlock, Collection<PsiReference>> refs = new HashMap<>();
|
||||
for (PsiReference reference : references.findAll()) {
|
||||
final PsiElement element = reference.getElement();
|
||||
if (!(element instanceof PsiReferenceExpression)) break;
|
||||
if (!(element instanceof PsiReferenceExpression)) continue FieldLoop;
|
||||
final PsiElement qualifier = ((PsiReferenceExpression)element).getQualifier();
|
||||
if (qualifier != null && (!(qualifier instanceof PsiThisExpression) || ((PsiThisExpression)qualifier).getQualifier() != null) ||
|
||||
!groupReferenceByCodeBlocks(refs, reference)) {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import java.util.*;
|
||||
|
||||
public class Outer {
|
||||
class Outer {
|
||||
private final int value = calcValue();
|
||||
|
||||
int myValue;
|
||||
Set set = new <error descr="Cannot resolve symbol 'HashSet'">HashSet</error>();
|
||||
Set set = new HashSet();
|
||||
|
||||
int calcValue() {
|
||||
return set.size();
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
class Reflection {
|
||||
void reflectionAccess(BeanWithWeirdFields someBean) throws NoSuchFieldException {
|
||||
Field theField = someBean.getClass().getDeclaredField("UUID");
|
||||
}
|
||||
|
||||
void testOther() {
|
||||
BeanWithWeirdFields someBean = new BeanWithWeirdFields();
|
||||
System.out.println(someBean.UUID);
|
||||
}
|
||||
|
||||
static class BeanWithWeirdFields {
|
||||
private String UUID;
|
||||
|
||||
public void setUUID(String UUID) {
|
||||
this.UUID = UUID;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,9 @@ package com.intellij.java.codeInspection;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInspection.varScopeCanBeNarrowed.FieldCanBeLocalInspection;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FieldCanBeLocalTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
@Override
|
||||
@@ -11,6 +13,11 @@ public class FieldCanBeLocalTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
return JavaTestUtil.getRelativeJavaTestDataPath() + "/inspection/fieldCanBeLocal";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_8;
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
myFixture.enableInspections(new FieldCanBeLocalInspection());
|
||||
myFixture.testHighlighting(getTestName(false) + ".java");
|
||||
@@ -106,4 +113,8 @@ public class FieldCanBeLocalTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
public void testConstructor() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testReflection() {
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user