Merge branch 'master' of git.labs.intellij.net:idea/community

This commit is contained in:
Dmitry Avdeev
2009-12-29 23:05:32 +03:00
6 changed files with 64 additions and 17 deletions
@@ -30,6 +30,7 @@ import com.intellij.usageView.UsageInfo;
import com.intellij.usages.Usage;
import com.intellij.usages.UsageGroup;
import com.intellij.usages.UsageView;
import com.intellij.usages.UsageViewSettings;
import com.intellij.usages.rules.PsiElementUsage;
import com.intellij.usages.rules.UsageGroupingRule;
import org.jetbrains.annotations.NotNull;
@@ -43,26 +44,25 @@ public class MethodGroupingRule implements UsageGroupingRule {
private static final Logger LOG = Logger.getInstance("#com.intellij.usages.impl.rules.MethodGroupingRule");
public UsageGroup groupUsage(Usage usage) {
if (usage instanceof PsiElementUsage) {
PsiElement psiElement = ((PsiElementUsage)usage).getElement();
if (psiElement.getContainingFile() instanceof PsiJavaFile) {
PsiElement containingMethod = psiElement;
do {
containingMethod = PsiTreeUtil.getParentOfType(containingMethod, PsiMethod.class, true);
if (containingMethod == null || ((PsiMethod)containingMethod).getContainingClass().getQualifiedName() != null) break;
}
while (true);
if (!(usage instanceof PsiElementUsage)) return null;
PsiElement psiElement = ((PsiElementUsage)usage).getElement();
if (psiElement.getContainingFile() instanceof PsiJavaFile) {
PsiElement containingMethod = psiElement;
do {
containingMethod = PsiTreeUtil.getParentOfType(containingMethod, PsiMethod.class, true);
if (containingMethod == null || ((PsiMethod)containingMethod).getContainingClass().getQualifiedName() != null) break;
}
while (true);
if (containingMethod != null) {
return new MethodUsageGroup((PsiMethod)containingMethod);
}
if (containingMethod != null) {
return new MethodUsageGroup((PsiMethod)containingMethod);
}
}
return null;
}
private static class MethodUsageGroup implements UsageGroup, TypeSafeDataProvider {
private final SmartPsiElementPointer myMethodPointer;
private final SmartPsiElementPointer<PsiMethod> myMethodPointer;
private final String myName;
private Icon myIcon;
@@ -142,8 +142,14 @@ public class MethodGroupingRule implements UsageGroupingRule {
if (!(usageGroup instanceof MethodUsageGroup)) {
LOG.error("MethodUsageGroup expected but " + usageGroup.getClass() + " found");
}
MethodUsageGroup other = (MethodUsageGroup)usageGroup;
PsiMethod myMethod = myMethodPointer.getElement();
PsiMethod otherMethod = other.myMethodPointer.getElement();
if (myMethod != null && otherMethod != null && myMethod != otherMethod && !UsageViewSettings.getInstance().IS_SORT_MEMBERS_ALPHABETICALLY) {
return myMethod.getTextOffset() < otherMethod.getTextOffset() ? -1 : 1;
}
return myName.compareTo(((MethodUsageGroup)usageGroup).myName);
return myName.compareTo(other.myName);
}
public void calcData(final DataKey key, final DataSink sink) {
@@ -44,9 +44,6 @@ public class OptimizeImportsAction extends AnAction {
final Editor editor = BaseCodeInsightAction.getInjectedEditor(project, PlatformDataKeys.EDITOR.getData(dataContext));
final VirtualFile[] files = PlatformDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext);
if (files == null) {
return;
}
PsiFile file = null;
PsiDirectory dir;
@@ -63,3 +63,4 @@ show.usages.only.usage=It''s the only usage in {0}
all.usages.are.in.this.line=All {0} usages in {1} are in this line
no.usages.found.in=No usages found in {0}
some.usages.found=({0,choice, 1#1 usage|2#{0,number} usages} found)
sort.alphabetically.action.text=Sort Members Alphabetically
@@ -42,6 +42,7 @@ public class UsageViewSettings implements PersistentStateComponent<UsageViewSett
public boolean IS_FILTER_DUPLICATED_LINE = false;
public boolean IS_SHOW_MODULES = false;
public boolean IS_PREVIEW_USAGES = false;
public boolean IS_SORT_MEMBERS_ALPHABETICALLY = true;
public float PREVIEW_USAGES_SPLITTER_PROPORTIONS = 0.5f;
public boolean GROUP_BY_USAGE_TYPE = true;
@@ -0,0 +1,41 @@
/*
* 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 com.intellij.usages.impl;
import com.intellij.openapi.util.IconLoader;
import com.intellij.usageView.UsageViewBundle;
import com.intellij.usages.UsageViewSettings;
import javax.swing.*;
/**
* @author cdr
*/
class SortMembersAlphabeticallyAction extends RuleAction {
private static final Icon ICON = IconLoader.getIcon("/objectBrowser/sorted.png");
SortMembersAlphabeticallyAction(UsageViewImpl usageView) {
super(usageView, UsageViewBundle.message("sort.alphabetically.action.text"), ICON);
}
protected boolean getOptionValue() {
return UsageViewSettings.getInstance().IS_SORT_MEMBERS_ALPHABETICALLY;
}
protected void setOptionValue(final boolean value) {
UsageViewSettings.getInstance().IS_SORT_MEMBERS_ALPHABETICALLY = value;
}
}
@@ -360,6 +360,7 @@ public class UsageViewImpl implements UsageView, UsageModelTracker.UsageModelTra
addFilteringActions(group);
group.add(new PreviewUsageAction(this));
group.add(new SortMembersAlphabeticallyAction(this));
return group;
}