mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
field can be local: group by top level blocks (IDEA-121490)
This commit is contained in:
@@ -85,7 +85,7 @@ public class FieldCanBeLocalInspection extends FieldCanBeLocalInspectionBase {
|
||||
private static void groupByCodeBlocks(final Collection<PsiReference> allReferences, Map<PsiCodeBlock, Collection<PsiReference>> refs) {
|
||||
for (PsiReference psiReference : allReferences) {
|
||||
final PsiElement element = psiReference.getElement();
|
||||
final PsiCodeBlock block = PsiTreeUtil.getParentOfType(element, PsiCodeBlock.class);
|
||||
final PsiCodeBlock block = PsiTreeUtil.getTopmostParentOfType(element, PsiCodeBlock.class);
|
||||
LOG.assertTrue(block != null);
|
||||
Collection<PsiReference> references = refs.get(block);
|
||||
if (references == null) {
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// "Convert to local" "true"
|
||||
import java.util.ArrayList;
|
||||
|
||||
class ITest {
|
||||
|
||||
public IntelliJBugConvertToLocal(int x, int z) {
|
||||
|
||||
ArrayList<String> mayBeLocal = new ArrayList<String>();
|
||||
if (x == 5) {
|
||||
mayBeLocal.add("jjj");
|
||||
}
|
||||
|
||||
if (x > z) {
|
||||
useIt(mayBeLocal);
|
||||
}
|
||||
}
|
||||
@SuppressWarnings("UnusedParameters")
|
||||
private void useIt(Object data) {
|
||||
System.out.println(data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// "Convert to local" "true"
|
||||
import java.util.ArrayList;
|
||||
|
||||
class ITest {
|
||||
|
||||
private ArrayList<String> may<caret>BeLocal = new ArrayList<String>();
|
||||
|
||||
public IntelliJBugConvertToLocal(int x, int z) {
|
||||
|
||||
if (x == 5) {
|
||||
mayBeLocal.add("jjj");
|
||||
}
|
||||
|
||||
if (x > z) {
|
||||
useIt(mayBeLocal);
|
||||
}
|
||||
}
|
||||
@SuppressWarnings("UnusedParameters")
|
||||
private void useIt(Object data) {
|
||||
System.out.println(data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user