diff options
author | Tor Norbye <tnorbye@google.com> | 2014-08-19 22:27:03 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-08-19 21:25:05 +0000 |
commit | 4ca751c002784c4bfd349cc5240b045b62277c80 (patch) | |
tree | dfc17b31990e2429535609b85f6d080c4fa0d9fe /java/java-impl/src/com/intellij/codeInspection/varScopeCanBeNarrowed/FieldCanBeLocalInspection.java | |
parent | 890d9a2952301682ffecaed4495f5f65c84c3642 (diff) | |
parent | 060e58b3afea3ea39f5ba1cb5a443ca3ebda28c8 (diff) | |
download | idea-4ca751c002784c4bfd349cc5240b045b62277c80.tar.gz |
Merge "Merge remote-tracking branch 'aosp/upstream-master' into merge"
Diffstat (limited to 'java/java-impl/src/com/intellij/codeInspection/varScopeCanBeNarrowed/FieldCanBeLocalInspection.java')
-rw-r--r-- | java/java-impl/src/com/intellij/codeInspection/varScopeCanBeNarrowed/FieldCanBeLocalInspection.java | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/java/java-impl/src/com/intellij/codeInspection/varScopeCanBeNarrowed/FieldCanBeLocalInspection.java b/java/java-impl/src/com/intellij/codeInspection/varScopeCanBeNarrowed/FieldCanBeLocalInspection.java index 38ee7449994a..51beb4239fc3 100644 --- a/java/java-impl/src/com/intellij/codeInspection/varScopeCanBeNarrowed/FieldCanBeLocalInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/varScopeCanBeNarrowed/FieldCanBeLocalInspection.java @@ -63,7 +63,7 @@ public class FieldCanBeLocalInspection extends FieldCanBeLocalInspectionBase { @Override protected PsiElement moveDeclaration(@NotNull final Project project, @NotNull final PsiField variable) { final Map<PsiCodeBlock, Collection<PsiReference>> refs = new HashMap<PsiCodeBlock, Collection<PsiReference>>(); - groupByCodeBlocks(ReferencesSearch.search(variable).findAll(), refs); + if (!groupByCodeBlocks(ReferencesSearch.search(variable).findAll(), refs)) return null; PsiElement element = null; for (Collection<PsiReference> psiReferences : refs.values()) { element = super.moveDeclaration(project, variable, psiReferences, false); @@ -82,11 +82,14 @@ public class FieldCanBeLocalInspection extends FieldCanBeLocalInspectionBase { return element; } - private static void groupByCodeBlocks(final Collection<PsiReference> allReferences, Map<PsiCodeBlock, Collection<PsiReference>> refs) { + private static boolean groupByCodeBlocks(final Collection<PsiReference> allReferences, Map<PsiCodeBlock, Collection<PsiReference>> refs) { for (PsiReference psiReference : allReferences) { final PsiElement element = psiReference.getElement(); final PsiCodeBlock block = PsiTreeUtil.getTopmostParentOfType(element, PsiCodeBlock.class); - LOG.assertTrue(block != null); + if (block == null) { + return false; + } + Collection<PsiReference> references = refs.get(block); if (references == null) { references = new ArrayList<PsiReference>(); @@ -95,6 +98,7 @@ public class FieldCanBeLocalInspection extends FieldCanBeLocalInspectionBase { } references.add(psiReference); } + return true; } private static boolean findExistentBlock(Map<PsiCodeBlock, Collection<PsiReference>> refs, |