replace hand made grouping rule with common one

This commit is contained in:
anna
2011-03-11 16:53:03 +01:00
parent 266016d485
commit 9cd8517fb7
8 changed files with 25 additions and 153 deletions
@@ -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;
}
}
@@ -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;
}
}
@@ -389,8 +389,7 @@ public class FindUsagesManager implements JDOMExternalizable {
});
PsiManager.getInstance(project).getSearchHelper().processRequests(options.fastTrack, new ReadActionProcessor<PsiReference>() {
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));
}
});
}
@@ -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);
@@ -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 {
-1
View File
@@ -260,7 +260,6 @@
<fileTemplateGroup implementation="org.jetbrains.plugins.groovy.actions.GroovyTemplatesFactory"/>
<usageGroupingRuleProvider implementation="org.jetbrains.plugins.groovy.findUsages.GroovyUsageViewGroupingRuleProvider"/>
<compilerSettingsFactory implementation="org.jetbrains.plugins.groovy.compiler.GroovyCompilerSettingsFactory"/>
@@ -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;
}
}
@@ -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;
}
}