From 9cd8517fb7758911fc205394e63f209ef38e2ee2 Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 11 Mar 2011 16:31:10 +0100 Subject: [PATCH] replace hand made grouping rule with common one --- .../refactoring/util/MoveRenameUsageInfo.java | 12 +-- .../src/com/intellij/usageView/UsageInfo.java | 6 ++ .../find/findUsages/FindUsagesManager.java | 3 +- .../refactoring/rename/RenameUtil.java | 3 +- .../impl/rules/NonCodeUsageGroupingRule.java | 25 ++++-- plugins/groovy/src/META-INF/plugin.xml | 1 - .../GroovyUsageViewGroupingRuleProvider.java | 39 -------- .../LateBoundUsageGroupingRule.java | 89 ------------------- 8 files changed, 25 insertions(+), 153 deletions(-) delete mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GroovyUsageViewGroupingRuleProvider.java delete mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/LateBoundUsageGroupingRule.java diff --git a/platform/lang-api/src/com/intellij/refactoring/util/MoveRenameUsageInfo.java b/platform/lang-api/src/com/intellij/refactoring/util/MoveRenameUsageInfo.java index 29a9ad83bc44..8015da154fff 100644 --- a/platform/lang-api/src/com/intellij/refactoring/util/MoveRenameUsageInfo.java +++ b/platform/lang-api/src/com/intellij/refactoring/util/MoveRenameUsageInfo.java @@ -29,7 +29,6 @@ public class MoveRenameUsageInfo extends UsageInfo{ private PsiReference myReference; private RangeMarker myReferenceRangeMarker = null; - private boolean myDynamicUsage; public MoveRenameUsageInfo(PsiReference reference, PsiElement referencedElement){ this(reference.getElement(), reference, referencedElement); @@ -46,12 +45,6 @@ public class MoveRenameUsageInfo extends UsageInfo{ init(element, reference, referencedElement); } - public MoveRenameUsageInfo(PsiElement element, PsiReference reference, int startOffset, int endOffset, PsiElement referencedElement, boolean nonCodeUsage, boolean isDynamicUsage){ - super(element, startOffset, endOffset, nonCodeUsage); - myDynamicUsage = isDynamicUsage; - init(element, reference, referencedElement); - } - private void init(final PsiElement element, PsiReference reference, final PsiElement referencedElement) { final Project project = element.getProject(); myReferencedElement = referencedElement; @@ -68,6 +61,7 @@ public class MoveRenameUsageInfo extends UsageInfo{ int elementStart = reference.getElement().getTextRange().getStartOffset(); myReferenceRangeMarker = document.createRangeMarker(elementStart + reference.getRangeInElement().getStartOffset(), elementStart + reference.getRangeInElement().getEndOffset()); + myDynamicUsage = reference.resolve() == null; } } @@ -99,8 +93,4 @@ public class MoveRenameUsageInfo extends UsageInfo{ if (rangeInElement.getStartOffset() != start || rangeInElement.getEndOffset() != end) return null; return reference; } - - public boolean isDynamicUsage() { - return myDynamicUsage; - } } diff --git a/platform/lang-api/src/com/intellij/usageView/UsageInfo.java b/platform/lang-api/src/com/intellij/usageView/UsageInfo.java index 425b01cc2929..23c9adee35b6 100644 --- a/platform/lang-api/src/com/intellij/usageView/UsageInfo.java +++ b/platform/lang-api/src/com/intellij/usageView/UsageInfo.java @@ -37,6 +37,7 @@ public class UsageInfo { private final int endOffset; // in navigation element public final boolean isNonCodeUsage; + protected boolean myDynamicUsage = false; public UsageInfo(@NotNull PsiElement element, int startOffset, int endOffset, boolean isNonCodeUsage) { LOG.assertTrue(element.isValid(), element); @@ -80,6 +81,7 @@ public class UsageInfo { public UsageInfo(@NotNull PsiReference reference) { this(reference.getElement(), reference.getRangeInElement().getStartOffset(), reference.getRangeInElement().getEndOffset()); + myDynamicUsage = reference.resolve() == null; } public UsageInfo(@NotNull PsiQualifiedReference reference) { @@ -206,4 +208,8 @@ public class UsageInfo { public void dispose() { ((Disposable)mySmartPointer).dispose(); } + + public boolean isDynamicUsage() { + return myDynamicUsage; + } } diff --git a/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java b/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java index 57f760abbde8..5bff937c484d 100644 --- a/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java +++ b/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java @@ -389,8 +389,7 @@ public class FindUsagesManager implements JDOMExternalizable { }); PsiManager.getInstance(project).getSearchHelper().processRequests(options.fastTrack, new ReadActionProcessor() { public boolean processInReadAction(final PsiReference ref) { - TextRange rangeInElement = ref.getRangeInElement(); - return usageInfoProcessor.process(new UsageInfo(ref.getElement(), rangeInElement.getStartOffset(), rangeInElement.getEndOffset(), false)); + return usageInfoProcessor.process(new UsageInfo(ref)); } }); } diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/RenameUtil.java b/platform/lang-impl/src/com/intellij/refactoring/rename/RenameUtil.java index a942123ce3d8..ee01fe58425c 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/RenameUtil.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/RenameUtil.java @@ -71,10 +71,9 @@ public class RenameUtil { continue; } PsiElement referenceElement = ref.getElement(); - final boolean isDynamic = ref.resolve() == null; result.add(new MoveRenameUsageInfo(referenceElement, ref, ref.getRangeInElement().getStartOffset(), ref.getRangeInElement().getEndOffset(), element, - isDynamic, isDynamic)); + ref.resolve() == null)); } processor.findCollisions(element, newName, allRenames, result); diff --git a/platform/usageView/src/com/intellij/usages/impl/rules/NonCodeUsageGroupingRule.java b/platform/usageView/src/com/intellij/usages/impl/rules/NonCodeUsageGroupingRule.java index 9663d13c773a..15cb1337d60f 100644 --- a/platform/usageView/src/com/intellij/usages/impl/rules/NonCodeUsageGroupingRule.java +++ b/platform/usageView/src/com/intellij/usages/impl/rules/NonCodeUsageGroupingRule.java @@ -18,6 +18,7 @@ package com.intellij.usages.impl.rules; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.FileStatus; import com.intellij.refactoring.util.MoveRenameUsageInfo; +import com.intellij.usageView.UsageInfo; import com.intellij.usageView.UsageViewBundle; import com.intellij.usages.Usage; import com.intellij.usages.UsageGroup; @@ -25,6 +26,7 @@ import com.intellij.usages.UsageInfo2UsageAdapter; import com.intellij.usages.UsageView; import com.intellij.usages.rules.PsiElementUsage; import com.intellij.usages.rules.UsageGroupingRule; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -90,10 +92,17 @@ public class NonCodeUsageGroupingRule implements UsageGroupingRule { private static class DynamicUsageGroup implements UsageGroup { public static final UsageGroup INSTANCE = new DynamicUsageGroup(); + @NonNls private static final String DYNAMIC_CAPTION = "Dynamic usages"; @NotNull public String getText(UsageView view) { - return view == null ? "Dynamic usages" : view.getPresentation().getDynamicCodeUsagesString(); + if (view == null) { + return DYNAMIC_CAPTION; + } + else { + final String dynamicCodeUsagesString = view.getPresentation().getDynamicCodeUsagesString(); + return dynamicCodeUsagesString == null ? DYNAMIC_CAPTION : dynamicCodeUsagesString; + } } public void update() { @@ -117,15 +126,13 @@ public class NonCodeUsageGroupingRule implements UsageGroupingRule { public UsageGroup groupUsage(Usage usage) { if (usage instanceof PsiElementUsage) { - if (((PsiElementUsage)usage).isNonCodeUsage()) { - if (usage instanceof UsageInfo2UsageAdapter) { - if (((UsageInfo2UsageAdapter)usage).getUsageInfo() instanceof MoveRenameUsageInfo) { - final MoveRenameUsageInfo usageInfo = (MoveRenameUsageInfo)((UsageInfo2UsageAdapter)usage).getUsageInfo(); - if (usageInfo.isDynamicUsage()) { - return DynamicUsageGroup.INSTANCE; - } - } + if (usage instanceof UsageInfo2UsageAdapter) { + final UsageInfo usageInfo = ((UsageInfo2UsageAdapter)usage).getUsageInfo(); + if (usageInfo.isDynamicUsage()) { + return DynamicUsageGroup.INSTANCE; } + } + if (((PsiElementUsage)usage).isNonCodeUsage()) { return NonCodeUsageGroup.INSTANCE; } else { diff --git a/plugins/groovy/src/META-INF/plugin.xml b/plugins/groovy/src/META-INF/plugin.xml index 3c69d065228d..d90bdad173ef 100644 --- a/plugins/groovy/src/META-INF/plugin.xml +++ b/plugins/groovy/src/META-INF/plugin.xml @@ -260,7 +260,6 @@ - diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GroovyUsageViewGroupingRuleProvider.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GroovyUsageViewGroupingRuleProvider.java deleted file mode 100644 index cbdb3eee86ca..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/GroovyUsageViewGroupingRuleProvider.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.plugins.groovy.findUsages; - -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.project.Project; -import com.intellij.usages.UsageView; -import com.intellij.usages.rules.UsageGroupingRule; -import com.intellij.usages.rules.UsageGroupingRuleProvider; -import org.jetbrains.annotations.NotNull; - -/** - * @author ven - */ -public class GroovyUsageViewGroupingRuleProvider implements UsageGroupingRuleProvider { - @NotNull - public UsageGroupingRule[] getActiveRules(Project project) { - return new UsageGroupingRule[] {new LateBoundUsageGroupingRule()}; - } - - @NotNull - public AnAction[] createGroupingActions(UsageView view) { - return AnAction.EMPTY_ARRAY; - } -} diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/LateBoundUsageGroupingRule.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/LateBoundUsageGroupingRule.java deleted file mode 100644 index 5d02dfed9ca6..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/findUsages/LateBoundUsageGroupingRule.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.plugins.groovy.findUsages; - -import com.intellij.openapi.vcs.FileStatus; -import com.intellij.psi.PsiElement; -import com.intellij.usages.Usage; -import com.intellij.usages.UsageGroup; -import com.intellij.usages.UsageView; -import com.intellij.usages.rules.OrderableUsageGroupingRule; -import com.intellij.usages.rules.PsiElementUsage; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression; - -import javax.swing.*; - -/** - * @author ven - */ -public class LateBoundUsageGroupingRule implements OrderableUsageGroupingRule { - private final LateBoundGroup INSTANCE = new LateBoundGroup(); - - private class LateBoundGroup implements UsageGroup { - - public Icon getIcon(boolean isOpen) { - return null; - } - - @NotNull - public String getText(UsageView view) { - return "Dynamically typed usages"; - } - - public FileStatus getFileStatus() { - return null; - } - - public boolean isValid() { - return true; - } - - public void update() { - } - - public int compareTo(UsageGroup usageGroup) { - return getText(null).compareTo(usageGroup.getText(null)); - } - - public void navigate(boolean b) { - } - - public boolean canNavigate() { - return false; - } - - public boolean canNavigateToSource() { - return false; - } - } - - public UsageGroup groupUsage(Usage usage) { - if (usage instanceof PsiElementUsage) { - final PsiElement element = ((PsiElementUsage) usage).getElement(); - if (element instanceof GrReferenceExpression && ((GrReferenceExpression) element).resolve() == null) { - return INSTANCE; - } - } - - return null; - } - - public int getRank() { - return 0; - } -}