mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
correctly work with filters and read/write access usages in UsageView
This commit is contained in:
@@ -5,10 +5,6 @@
|
||||
package com.intellij.usages;
|
||||
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiReferenceExpression;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.util.Icons;
|
||||
|
||||
/**
|
||||
@@ -16,17 +12,13 @@ import com.intellij.util.Icons;
|
||||
* Date: Jan 17, 2005
|
||||
*/
|
||||
public class ReadWriteAccessUsageInfo2UsageAdapter extends UsageInfo2UsageAdapter implements ReadWriteAccessUsage{
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.usages.ReadWriteAccessUsageInfo2UsageAdapter");
|
||||
private final boolean myAccessedForReading;
|
||||
private final boolean myAccessedForWriting;
|
||||
|
||||
public ReadWriteAccessUsageInfo2UsageAdapter(final UsageInfo usageInfo) {
|
||||
public ReadWriteAccessUsageInfo2UsageAdapter(final UsageInfo usageInfo, final boolean accessedForReading, final boolean accessedForWriting) {
|
||||
super(usageInfo);
|
||||
final PsiElement element = getUsageInfo().getElement();
|
||||
LOG.assertTrue(element instanceof PsiReferenceExpression);
|
||||
final PsiReferenceExpression referent = (PsiReferenceExpression)element;
|
||||
myAccessedForReading = PsiUtil.isAccessedForReading(referent);
|
||||
myAccessedForWriting = isAccessedForWriting(referent);
|
||||
myAccessedForReading = accessedForReading;
|
||||
myAccessedForWriting = accessedForWriting;
|
||||
if (myIcon == null) {
|
||||
if (myAccessedForReading && myAccessedForWriting) {
|
||||
myIcon = Icons.VARIABLE_RW_ACCESS;
|
||||
@@ -48,22 +40,6 @@ public class ReadWriteAccessUsageInfo2UsageAdapter extends UsageInfo2UsageAdapte
|
||||
return myAccessedForReading;
|
||||
}
|
||||
|
||||
private static boolean isAccessedForWriting(PsiReferenceExpression referent) {
|
||||
if (PsiUtil.isAccessedForWriting(referent)) {
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
todo: when searching usages of fields, should show all found setters as a "write usage"
|
||||
if (myProcessedElementsPointers.length > 0) {
|
||||
PsiElement referee = myProcessedElementsPointers[0].getElement();
|
||||
if (referee instanceof PsiField && !referent.isReferenceTo(referee)) {
|
||||
PsiElement actualReferee = referent.resolve();
|
||||
return actualReferee instanceof PsiMethod && PropertyUtil.isSimplePropertySetter((PsiMethod)actualReferee);
|
||||
}
|
||||
}
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,25 +5,103 @@
|
||||
package com.intellij.usages;
|
||||
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.psi.PsiReferenceExpression;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.PropertyUtil;
|
||||
|
||||
/**
|
||||
* @author Eugene Zhuravlev
|
||||
* Date: Jan 17, 2005
|
||||
*/
|
||||
public class UsageInfoToUsageConverter {
|
||||
public static Usage convert(UsageInfo usageInfo) {
|
||||
if (usageInfo.getElement() instanceof PsiReferenceExpression) {
|
||||
return new ReadWriteAccessUsageInfo2UsageAdapter(usageInfo);
|
||||
|
||||
public static class TargetElementsDescriptor {
|
||||
private final PsiElement[] myPrimarySearchedElements;
|
||||
private final PsiElement[] myAdditionalSearchedElements;
|
||||
|
||||
public TargetElementsDescriptor(PsiElement element) {
|
||||
this(new PsiElement[]{element});
|
||||
}
|
||||
|
||||
public TargetElementsDescriptor(PsiElement[] primarySearchedElements) {
|
||||
this(primarySearchedElements, PsiElement.EMPTY_ARRAY);
|
||||
}
|
||||
|
||||
public TargetElementsDescriptor(PsiElement[] primarySearchedElements, PsiElement[] additionalSearchedElements) {
|
||||
myPrimarySearchedElements = primarySearchedElements != null? primarySearchedElements : PsiElement.EMPTY_ARRAY;
|
||||
myAdditionalSearchedElements = additionalSearchedElements != null? additionalSearchedElements : PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
/**
|
||||
* A read-only attribute describing the target as a "primary" target.
|
||||
* A primary target is a target that was the main purpose of the search.
|
||||
* All usages of a non-primary target should be considered as a special case of usages of the corresponding primary target.
|
||||
* Example: searching field and its getter and setter methods -
|
||||
* the field searched is a primary target, and its accessor methods are non-primary targets, because
|
||||
* for this particular search usages of getter/setter methods are to be considered as a usages of the corresponding field.
|
||||
*/
|
||||
public PsiElement[] getPrimaryElements() {
|
||||
return myPrimarySearchedElements;
|
||||
}
|
||||
|
||||
public PsiElement[] getAdditionalElements() {
|
||||
return myAdditionalSearchedElements;
|
||||
}
|
||||
}
|
||||
|
||||
public static Usage convert(TargetElementsDescriptor descriptor, UsageInfo usageInfo) {
|
||||
final PsiElement[] primaryElements = descriptor.getPrimaryElements();
|
||||
if (isReadWriteAccessibleElements(primaryElements)) {
|
||||
final PsiElement usageElement = usageInfo.getElement();
|
||||
if (usageElement instanceof PsiReferenceExpression) {
|
||||
final Access access = isAccessedForReading((PsiReferenceExpression)usageElement);
|
||||
return new ReadWriteAccessUsageInfo2UsageAdapter(usageInfo, access.read, access.write);
|
||||
}
|
||||
}
|
||||
return new UsageInfo2UsageAdapter(usageInfo);
|
||||
}
|
||||
|
||||
public static Usage[] convert(UsageInfo[] usageInfos) {
|
||||
public static Usage[] convert(TargetElementsDescriptor descriptor, UsageInfo[] usageInfos) {
|
||||
Usage[] usages = new Usage[usageInfos.length];
|
||||
for (int i = 0; i < usages.length; i++) {
|
||||
usages[i] = convert(usageInfos[i]);
|
||||
usages[i] = convert(descriptor, usageInfos[i]);
|
||||
}
|
||||
return usages;
|
||||
}
|
||||
|
||||
private static boolean isReadWriteAccessibleElements(final PsiElement[] elements) {
|
||||
if (elements.length == 0) {
|
||||
return false;
|
||||
}
|
||||
for (int idx = 0; idx < elements.length; idx++) {
|
||||
if (!(elements[idx] instanceof PsiVariable)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static final class Access {
|
||||
public final boolean read;
|
||||
public final boolean write;
|
||||
|
||||
public Access(final boolean read, final boolean write) {
|
||||
this.read = read;
|
||||
this.write = write;
|
||||
}
|
||||
}
|
||||
private static Access isAccessedForReading(final PsiReferenceExpression referent) {
|
||||
boolean accessedForReading = PsiUtil.isAccessedForReading(referent);
|
||||
boolean accessedForWriting = PsiUtil.isAccessedForWriting(referent);
|
||||
if (!accessedForWriting) {
|
||||
//when searching usages of fields, should show all found setters as a "only write usage"
|
||||
PsiElement actualReferee = referent.resolve();
|
||||
if ((actualReferee instanceof PsiMethod) && PropertyUtil.isSimplePropertySetter((PsiMethod)actualReferee)) {
|
||||
accessedForWriting = true;
|
||||
accessedForReading = false;
|
||||
}
|
||||
}
|
||||
return new Access(accessedForReading, accessedForWriting);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
39
UsageView/src/com/intellij/usages/impl/RuleAction.java
Normal file
39
UsageView/src/com/intellij/usages/impl/RuleAction.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2000-2004 by JetBrains s.r.o. All Rights Reserved.
|
||||
* Use is subject to license terms.
|
||||
*/
|
||||
package com.intellij.usages.impl;
|
||||
|
||||
import com.intellij.openapi.actionSystem.ToggleAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* @author Eugene Zhuravlev
|
||||
* Date: Jan 19, 2005
|
||||
*/
|
||||
abstract class RuleAction extends ToggleAction {
|
||||
private UsageViewImpl myView;
|
||||
private boolean myState;
|
||||
|
||||
public RuleAction(UsageViewImpl view, final String text, final Icon icon) {
|
||||
super(text, null, icon);
|
||||
myView = view;
|
||||
myState = getOptionValue();
|
||||
}
|
||||
|
||||
protected abstract boolean getOptionValue();
|
||||
|
||||
protected abstract void setOptionValue(boolean value);
|
||||
|
||||
public boolean isSelected(AnActionEvent e) {
|
||||
return myState;
|
||||
}
|
||||
|
||||
public void setSelected(AnActionEvent e, boolean state) {
|
||||
setOptionValue(state);
|
||||
myState = state;
|
||||
myView.rulesChanged();
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,6 @@ import com.intellij.usages.impl.rules.ReadAccessFilteringRule;
|
||||
import com.intellij.usages.impl.rules.WriteAccessFilteringRule;
|
||||
import com.intellij.usages.rules.UsageFilteringRule;
|
||||
import com.intellij.usages.rules.UsageFilteringRuleProvider;
|
||||
import com.intellij.util.Icons;
|
||||
import org.jdom.Element;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -59,57 +58,45 @@ public class UsageFilteringRuleProviderImpl extends UsageFilteringRuleProvider i
|
||||
return new AnAction[] {showImportsAction, showReadAccessUsagesAction, showWriteAccessUsagesAction};
|
||||
}
|
||||
|
||||
private class ShowImportsAction extends ToggleAction {
|
||||
private UsageViewImpl myView;
|
||||
|
||||
private class ShowImportsAction extends RuleAction {
|
||||
public ShowImportsAction(UsageViewImpl view) {
|
||||
super("Show import statements", null, IconLoader.getIcon("/actions/showImportStatements.png"));
|
||||
myView = view;
|
||||
super(view, "Show import statements", IconLoader.getIcon("/actions/showImportStatements.png"));
|
||||
}
|
||||
|
||||
public boolean isSelected(AnActionEvent e) {
|
||||
protected boolean getOptionValue() {
|
||||
return SHOW_IMPORTS;
|
||||
}
|
||||
|
||||
public void setSelected(AnActionEvent e, boolean state) {
|
||||
SHOW_IMPORTS = state;
|
||||
myView.rulesChanged();
|
||||
protected void setOptionValue(boolean value) {
|
||||
SHOW_IMPORTS = value;
|
||||
}
|
||||
}
|
||||
|
||||
private class ShowReadAccessUsagesAction extends ToggleAction {
|
||||
private UsageViewImpl myView;
|
||||
|
||||
private class ShowReadAccessUsagesAction extends RuleAction {
|
||||
public ShowReadAccessUsagesAction(UsageViewImpl view) {
|
||||
super("Show read access", null, IconLoader.getIcon("/actions/showReadAccess.png"));
|
||||
myView = view;
|
||||
super(view, "Show read access", IconLoader.getIcon("/actions/showReadAccess.png"));
|
||||
}
|
||||
|
||||
public boolean isSelected(AnActionEvent e) {
|
||||
protected boolean getOptionValue() {
|
||||
return SHOW_READ_ACCESS;
|
||||
}
|
||||
|
||||
public void setSelected(AnActionEvent e, boolean state) {
|
||||
SHOW_READ_ACCESS = state;
|
||||
myView.rulesChanged();
|
||||
protected void setOptionValue(boolean value) {
|
||||
SHOW_READ_ACCESS = value;
|
||||
}
|
||||
}
|
||||
|
||||
private class ShowWriteAccessUsagesAction extends ToggleAction {
|
||||
private UsageViewImpl myView;
|
||||
|
||||
private class ShowWriteAccessUsagesAction extends RuleAction {
|
||||
public ShowWriteAccessUsagesAction(UsageViewImpl view) {
|
||||
super("Show write access", null, IconLoader.getIcon("/actions/showWriteAccess.png"));
|
||||
myView = view;
|
||||
super(view, "Show write access", IconLoader.getIcon("/actions/showWriteAccess.png"));
|
||||
}
|
||||
|
||||
public boolean isSelected(AnActionEvent e) {
|
||||
protected boolean getOptionValue() {
|
||||
return SHOW_WRITE_ACCESS;
|
||||
}
|
||||
|
||||
public void setSelected(AnActionEvent e, boolean state) {
|
||||
SHOW_WRITE_ACCESS = state;
|
||||
myView.rulesChanged();
|
||||
protected void setOptionValue(boolean value) {
|
||||
SHOW_WRITE_ACCESS = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.intellij.usages.rules.UsageGroupingRule;
|
||||
import com.intellij.usages.rules.UsageGroupingRuleProvider;
|
||||
import org.jdom.Element;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -59,75 +60,53 @@ public class UsageGroupingRuleProviderImpl extends UsageGroupingRuleProvider imp
|
||||
};
|
||||
}
|
||||
|
||||
private class GroupByUsageTypeAction extends ToggleAction {
|
||||
private UsageViewImpl myView;
|
||||
|
||||
private class GroupByUsageTypeAction extends RuleAction {
|
||||
public GroupByUsageTypeAction(UsageViewImpl view) {
|
||||
super("Group by usage type", null, IconLoader.getIcon("/ant/filter.png")); //TODO: special icon
|
||||
myView = view;
|
||||
super(view, "Group by usage type", IconLoader.getIcon("/ant/filter.png")); //TODO: special icon
|
||||
}
|
||||
|
||||
public boolean isSelected(AnActionEvent e) {
|
||||
protected boolean getOptionValue() {
|
||||
return GROUP_BY_USAGE_TYPE;
|
||||
}
|
||||
|
||||
public void setSelected(AnActionEvent e, boolean state) {
|
||||
GROUP_BY_USAGE_TYPE = state;
|
||||
myView.rulesChanged();
|
||||
protected void setOptionValue(boolean value) {
|
||||
GROUP_BY_USAGE_TYPE = value;
|
||||
}
|
||||
}
|
||||
|
||||
private class GroupByModuleTypeAction extends ToggleAction {
|
||||
private UsageViewImpl myView;
|
||||
|
||||
private class GroupByModuleTypeAction extends RuleAction {
|
||||
public GroupByModuleTypeAction(UsageViewImpl view) {
|
||||
super("Group by module", null, IconLoader.getIcon("/objectBrowser/showModules.png"));
|
||||
myView = view;
|
||||
super(view, "Group by module", IconLoader.getIcon("/objectBrowser/showModules.png"));
|
||||
}
|
||||
|
||||
public boolean isSelected(AnActionEvent e) {
|
||||
protected boolean getOptionValue() {
|
||||
return GROUP_BY_MODULE;
|
||||
}
|
||||
|
||||
public void setSelected(AnActionEvent e, boolean state) {
|
||||
GROUP_BY_MODULE = state;
|
||||
myView.rulesChanged();
|
||||
protected void setOptionValue(boolean value) {
|
||||
GROUP_BY_MODULE = value;
|
||||
}
|
||||
}
|
||||
|
||||
private class GroupByPackageAction extends ToggleAction {
|
||||
private UsageViewImpl myView;
|
||||
|
||||
private class GroupByPackageAction extends RuleAction {
|
||||
public GroupByPackageAction(UsageViewImpl view) {
|
||||
super("Group by package", null, IconLoader.getIcon("/toolbar/folders.png"));
|
||||
myView = view;
|
||||
super(view, "Group by package", IconLoader.getIcon("/toolbar/folders.png"));
|
||||
}
|
||||
|
||||
public boolean isSelected(AnActionEvent e) {
|
||||
protected boolean getOptionValue() {
|
||||
return GROUP_BY_PACKAGE;
|
||||
}
|
||||
|
||||
public void setSelected(AnActionEvent e, boolean state) {
|
||||
GROUP_BY_PACKAGE = state;
|
||||
myView.rulesChanged();
|
||||
protected void setOptionValue(boolean value) {
|
||||
GROUP_BY_PACKAGE = value;
|
||||
}
|
||||
}
|
||||
|
||||
private class GroupByFileStructureAction extends ToggleAction {
|
||||
private UsageViewImpl myView;
|
||||
|
||||
private class GroupByFileStructureAction extends RuleAction {
|
||||
public GroupByFileStructureAction(UsageViewImpl view) {
|
||||
super("Group by file structure", null, IconLoader.getIcon("/actions/groupByMethod.png"));
|
||||
myView = view;
|
||||
super(view, "Group by file structure", IconLoader.getIcon("/actions/groupByMethod.png"));
|
||||
}
|
||||
|
||||
public boolean isSelected(AnActionEvent e) {
|
||||
protected boolean getOptionValue() {
|
||||
return GROUP_BY_FILE_STRUCTURE;
|
||||
}
|
||||
|
||||
public void setSelected(AnActionEvent e, boolean state) {
|
||||
GROUP_BY_FILE_STRUCTURE = state;
|
||||
myView.rulesChanged();
|
||||
protected void setOptionValue(boolean value) {
|
||||
GROUP_BY_FILE_STRUCTURE = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -313,18 +313,17 @@ public class UsageViewImpl implements UsageView {
|
||||
}
|
||||
}
|
||||
|
||||
private class MergeDupLines extends ToggleAction {
|
||||
private class MergeDupLines extends RuleAction {
|
||||
public MergeDupLines() {
|
||||
super("Merge usages from the same line", null, IconLoader.getIcon("/toolbar/filterdups.png"));
|
||||
super(UsageViewImpl.this, "Merge usages from the same line", IconLoader.getIcon("/toolbar/filterdups.png"));
|
||||
}
|
||||
|
||||
public boolean isSelected(AnActionEvent e) {
|
||||
protected boolean getOptionValue() {
|
||||
return UsageViewSettings.getInstance().IS_FILTER_DUPLICATED_LINE;
|
||||
}
|
||||
|
||||
public void setSelected(AnActionEvent e, boolean state) {
|
||||
UsageViewSettings.getInstance().IS_FILTER_DUPLICATED_LINE = state;
|
||||
rulesChanged();
|
||||
protected void setOptionValue(boolean value) {
|
||||
UsageViewSettings.getInstance().IS_FILTER_DUPLICATED_LINE = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,14 +45,15 @@ import com.intellij.usageView.FindUsagesCommand;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.usageView.UsageViewManager;
|
||||
import com.intellij.usageView.UsageViewUtil;
|
||||
import com.intellij.usages.*;
|
||||
import com.intellij.usages.Usage;
|
||||
import com.intellij.usages.UsageInfoToUsageConverter;
|
||||
import com.intellij.usages.UsageSearcher;
|
||||
import com.intellij.usages.UsageViewPresentation;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public class FindUsagesManager {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.find.findParameterUsages.FindUsagesManager");
|
||||
@@ -305,22 +306,30 @@ public class FindUsagesManager {
|
||||
FindUsagesOptions options = myLastSearchData.myLastOptions;
|
||||
|
||||
|
||||
findUsagesInEditor(allElements, psiFile, direction, options, textEditor);
|
||||
findUsagesInEditor(new UsageInfoToUsageConverter.TargetElementsDescriptor(allElements), psiFile, direction, options, textEditor);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private void initLastSearchElement(final PsiElement[] elements, final FindUsagesOptions findUsagesOptions) {
|
||||
myLastSearchData.myLastSearchElements = new SmartPsiElementPointer[elements.length];
|
||||
for (int i = 0; i < elements.length; i++) {
|
||||
myLastSearchData.myLastSearchElements[i] = SmartPointerManager.getInstance(myProject)
|
||||
.createSmartPsiElementPointer(elements[i]);
|
||||
private void initLastSearchElement(final FindUsagesOptions findUsagesOptions, UsageInfoToUsageConverter.TargetElementsDescriptor descriptor) {
|
||||
final PsiElement[] primaryElements = descriptor.getPrimaryElements();
|
||||
final PsiElement[] additionalElements = descriptor.getAdditionalElements();
|
||||
List<PsiElement> allElements = new ArrayList<PsiElement>(primaryElements.length + additionalElements.length);
|
||||
allElements.addAll(Arrays.asList(primaryElements));
|
||||
allElements.addAll(Arrays.asList(additionalElements));
|
||||
|
||||
myLastSearchData.myLastSearchElements = new SmartPsiElementPointer[allElements.size()];
|
||||
int idx = 0;
|
||||
for (Iterator it = allElements.iterator(); it.hasNext();) {
|
||||
final PsiElement psiElement = (PsiElement)it.next();
|
||||
myLastSearchData.myLastSearchElements[idx++] = SmartPointerManager.getInstance(myProject).createSmartPsiElementPointer(psiElement);
|
||||
}
|
||||
myLastSearchData.myLastOptions = findUsagesOptions;
|
||||
}
|
||||
|
||||
public void findUsages(PsiElement psiElement, final PsiFile scopeFile, final FileEditor editor) {
|
||||
PsiElement[] elementsToSearch = null;
|
||||
PsiElement[] secondaryElementsToSearch = null;
|
||||
if (!canFindUsages(psiElement)) {
|
||||
return;
|
||||
}
|
||||
@@ -355,7 +364,9 @@ public class FindUsagesManager {
|
||||
"find usages of");
|
||||
}
|
||||
|
||||
if (psiElement == null) return;
|
||||
if (psiElement == null) {
|
||||
return;
|
||||
}
|
||||
final FindUsagesDialog dialog = getFindUsagesDialog(psiElement, scopeFile != null, toOpenInNewTab, isOpenInNewTabEnabled);
|
||||
if (dialog == null) {
|
||||
return;
|
||||
@@ -423,39 +434,65 @@ public class FindUsagesManager {
|
||||
Messages.getQuestionIcon()) ==
|
||||
DialogWrapper.OK_EXIT_CODE) {
|
||||
final List<PsiElement> elements = new ArrayList<PsiElement>();
|
||||
elements.add(field);
|
||||
if (getter != null) {
|
||||
getter = SuperMethodWarningUtil.checkSuperMethod(getter, "find usages of");
|
||||
if (getter == null) return;
|
||||
if (getter == null) {
|
||||
return;
|
||||
}
|
||||
elements.add(getter);
|
||||
}
|
||||
if (setter != null) {
|
||||
setter = SuperMethodWarningUtil.checkSuperMethod(setter, "find usages of");
|
||||
if (setter == null) return;
|
||||
if (setter == null) {
|
||||
return;
|
||||
}
|
||||
elements.add(setter);
|
||||
}
|
||||
|
||||
elementsToSearch = elements.toArray(new PsiElement[elements.size()]);
|
||||
secondaryElementsToSearch = elements.toArray(new PsiElement[elements.size()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (psiElement instanceof PsiMethod) {
|
||||
if (scopeFile == null && findUsagesOptions.isIncludeOverloadUsages) {
|
||||
elementsToSearch = MethodSignatureUtil.getOverloads((PsiMethod)psiElement);
|
||||
}
|
||||
}
|
||||
|
||||
if (elementsToSearch == null) {
|
||||
elementsToSearch = new PsiElement[] {psiElement};
|
||||
}
|
||||
|
||||
|
||||
final UsageInfoToUsageConverter.TargetElementsDescriptor descriptor = new UsageInfoToUsageConverter.TargetElementsDescriptor(
|
||||
elementsToSearch, secondaryElementsToSearch
|
||||
);
|
||||
if (scopeFile == null) {
|
||||
findUsages(elementsToSearch, dialog.isSkipResultsWhenOneUsage(),
|
||||
toOpenInNewTab, findUsagesOptions);
|
||||
findUsages(descriptor, dialog.isSkipResultsWhenOneUsage(), toOpenInNewTab, findUsagesOptions);
|
||||
}
|
||||
else {
|
||||
editor.putUserData(KEY_START_USAGE_AGAIN, null);
|
||||
findUsagesInEditor(elementsToSearch, scopeFile, FROM_START, findUsagesOptions, editor);
|
||||
findUsagesInEditor(descriptor, scopeFile, FROM_START, findUsagesOptions, editor);
|
||||
}
|
||||
}
|
||||
|
||||
private PsiElement2UsageTargetAdapter[] convertToUsageTargets(final PsiElement[] primaryElementsToSearch, final PsiElement[] secondaryElementsToSearch) {
|
||||
final ArrayList<PsiElement2UsageTargetAdapter> targets = new ArrayList<PsiElement2UsageTargetAdapter>();
|
||||
if (primaryElementsToSearch != null) {
|
||||
for (int idx = 0; idx < primaryElementsToSearch.length; idx++) {
|
||||
convertToUsageTarget(targets, primaryElementsToSearch[idx]);
|
||||
}
|
||||
}
|
||||
if (secondaryElementsToSearch != null) {
|
||||
for (int idx = 0; idx < secondaryElementsToSearch.length; idx++) {
|
||||
convertToUsageTarget(targets, secondaryElementsToSearch[idx]);
|
||||
}
|
||||
}
|
||||
|
||||
return targets.toArray(new PsiElement2UsageTargetAdapter[targets.size()]);
|
||||
}
|
||||
|
||||
private PsiElement[] getParameterElementsToSearch(final PsiParameter parameter) {
|
||||
final PsiMethod method = (PsiMethod)parameter.getDeclarationScope();
|
||||
PsiSearchHelper helper = parameter.getManager().getSearchHelper();
|
||||
@@ -537,52 +574,46 @@ public class FindUsagesManager {
|
||||
}
|
||||
}
|
||||
|
||||
private UsageSearcher getUsageSearcher(final PsiElement[] elementsToSearch, final FindUsagesOptions options, final PsiFile scopeFile) {
|
||||
private UsageSearcher createUsageSearcher(final UsageInfoToUsageConverter.TargetElementsDescriptor descriptor, final FindUsagesOptions options,
|
||||
final PsiFile scopeFile) {
|
||||
return new UsageSearcher() {
|
||||
public void generate(final Processor<Usage> processor) {
|
||||
if (scopeFile != null) {
|
||||
options.searchScope = new LocalSearchScope(scopeFile);
|
||||
}
|
||||
for (int i = 0; i < elementsToSearch.length; i++) {
|
||||
final PsiElement elementToSearch = elementsToSearch[i];
|
||||
if (elementToSearch != null && elementToSearch.isValid()) {
|
||||
FindUsagesUtil.processUsages(elementToSearch, new Processor<UsageInfo>() {
|
||||
public boolean process(UsageInfo usageInfo) {
|
||||
return processor.process(UsageInfoToUsageConverter.convert(usageInfo));
|
||||
}
|
||||
}, options);
|
||||
final Processor<UsageInfo> usageInfoProcessorToUsageProcessorAdapter = new Processor<UsageInfo>() {
|
||||
public boolean process(UsageInfo usageInfo) {
|
||||
return processor.process(UsageInfoToUsageConverter.convert(descriptor, usageInfo));
|
||||
}
|
||||
};
|
||||
final PsiElement[] primaryElements = descriptor.getPrimaryElements();
|
||||
for (int idx = 0; idx < primaryElements.length; idx++) {
|
||||
FindUsagesUtil.processUsages(primaryElements[idx], usageInfoProcessorToUsageProcessorAdapter, options);
|
||||
}
|
||||
final PsiElement[] additionalElements = descriptor.getAdditionalElements();
|
||||
for (int idx = 0; idx < additionalElements.length; idx++) {
|
||||
FindUsagesUtil.processUsages(additionalElements[idx], usageInfoProcessorToUsageProcessorAdapter, options);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void findUsages(final PsiElement[] elementsToSearch,
|
||||
final boolean toSkipUsagePanelWhenOneUsage,
|
||||
private void findUsages(final UsageInfoToUsageConverter.TargetElementsDescriptor descriptor, final boolean toSkipUsagePanelWhenOneUsage,
|
||||
final boolean toOpenInNewTab,
|
||||
final FindUsagesOptions findUsagesOptions) {
|
||||
PsiElement[] elementsToDisplay = elementsToSearch;
|
||||
PsiElement psiElement = elementsToSearch[0];
|
||||
if (findUsagesOptions.isIncludeOverloadUsages) {
|
||||
LOG.assertTrue(elementsToSearch.length == 1 && psiElement instanceof PsiMethod);
|
||||
elementsToDisplay = MethodSignatureUtil.getOverloads((PsiMethod)psiElement);
|
||||
}
|
||||
|
||||
UsageViewPresentation presentation = createPresentation(psiElement, findUsagesOptions, toOpenInNewTab);
|
||||
UsageViewPresentation presentation = createPresentation(descriptor.getPrimaryElements()[0], findUsagesOptions, toOpenInNewTab);
|
||||
|
||||
Factory<UsageSearcher> searcherFactory = new Factory<UsageSearcher>() {
|
||||
final Factory<UsageSearcher> searcherFactory = new Factory<UsageSearcher>() {
|
||||
public UsageSearcher create() {
|
||||
return getUsageSearcher(elementsToSearch, findUsagesOptions, null);
|
||||
return createUsageSearcher(descriptor, findUsagesOptions, null);
|
||||
}
|
||||
};
|
||||
|
||||
myAnotherManager.searchAndShowUsages(convertTargets(elementsToDisplay),
|
||||
searcherFactory, !toSkipUsagePanelWhenOneUsage, true, presentation);
|
||||
final PsiElement2UsageTargetAdapter[] targets = convertToUsageTargets(descriptor.getPrimaryElements(), descriptor.getAdditionalElements());
|
||||
myAnotherManager.searchAndShowUsages(targets, searcherFactory, !toSkipUsagePanelWhenOneUsage, true, presentation);
|
||||
}
|
||||
|
||||
private UsageViewPresentation createPresentation(PsiElement psiElement,
|
||||
final FindUsagesOptions findUsagesOptions,
|
||||
boolean toOpenInNewTab) {
|
||||
private UsageViewPresentation createPresentation(PsiElement psiElement, final FindUsagesOptions findUsagesOptions, boolean toOpenInNewTab) {
|
||||
UsageViewPresentation presentation = new UsageViewPresentation();
|
||||
String scopeString = findUsagesOptions.searchScope != null ? findUsagesOptions.searchScope.getDisplayName() : null;
|
||||
presentation.setScopeText(scopeString);
|
||||
@@ -596,19 +627,18 @@ public class FindUsagesManager {
|
||||
return presentation;
|
||||
}
|
||||
|
||||
private void findUsagesInEditor(final PsiElement[] elementsToSearch,
|
||||
final PsiFile scopeFile,
|
||||
private void findUsagesInEditor(final UsageInfoToUsageConverter.TargetElementsDescriptor descriptor, final PsiFile scopeFile,
|
||||
final int direction,
|
||||
final FindUsagesOptions findUsagesOptions,
|
||||
FileEditor fileEditor) {
|
||||
LOG.assertTrue(fileEditor != null);
|
||||
initLastSearchElement(elementsToSearch, findUsagesOptions);
|
||||
initLastSearchElement(findUsagesOptions, descriptor);
|
||||
|
||||
clearStatusBar();
|
||||
|
||||
final FileEditorLocation currentLocation = fileEditor.getCurrentLocation();
|
||||
|
||||
final UsageSearcher usageSearcher = getUsageSearcher(elementsToSearch, findUsagesOptions, scopeFile);
|
||||
final UsageSearcher usageSearcher = createUsageSearcher(descriptor, findUsagesOptions, scopeFile);
|
||||
final boolean[] usagesWereFound = new boolean[]{false};
|
||||
|
||||
Usage fUsage = findSiblingUsage(usageSearcher, direction, currentLocation, usagesWereFound, fileEditor);
|
||||
@@ -618,14 +648,12 @@ public class FindUsagesManager {
|
||||
fUsage.selectInEditor();
|
||||
}
|
||||
else if (!usagesWereFound[0]) {
|
||||
String message = getNoUsagesFoundMessage(elementsToSearch[0]);
|
||||
|
||||
String message = getNoUsagesFoundMessage(descriptor.getPrimaryElements()[0]);
|
||||
showHintOrStatusBarMessage(message, fileEditor);
|
||||
}
|
||||
else {
|
||||
fileEditor.putUserData(KEY_START_USAGE_AGAIN, "START_AGAIN");
|
||||
|
||||
showHintOrStatusBarMessage(getSearchAgainMessage(elementsToSearch[0], direction), fileEditor);
|
||||
showHintOrStatusBarMessage(getSearchAgainMessage(descriptor.getPrimaryElements()[0], direction), fileEditor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -738,19 +766,13 @@ public class FindUsagesManager {
|
||||
return fUsage;
|
||||
}
|
||||
|
||||
private UsageTarget[] convertTargets(PsiElement[] elementsToDisplay) {
|
||||
UsageTarget[] targets = new UsageTarget[elementsToDisplay.length];
|
||||
for (int i = 0; i < targets.length; i++) {
|
||||
PsiElement display = elementsToDisplay[i];
|
||||
if (display instanceof NavigationItem) {
|
||||
final NavigationItem item = (NavigationItem)display;
|
||||
targets[i] = new PsiElement2UsageTargetAdapter((PsiElement)item);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Wrong usage target:" + display);
|
||||
}
|
||||
private void convertToUsageTarget(final List<PsiElement2UsageTargetAdapter> targets, PsiElement elementToSearch) {
|
||||
if (elementToSearch instanceof NavigationItem) {
|
||||
targets.add(new PsiElement2UsageTargetAdapter(elementToSearch));
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Wrong usage target:" + elementToSearch);
|
||||
}
|
||||
return targets;
|
||||
}
|
||||
|
||||
private static String generateUsagesString(final FindUsagesOptions selectedOptions,
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.intellij.packageDependencies.FindDependencyUtil;
|
||||
import com.intellij.packageDependencies.BackwardDependenciesBuilder;
|
||||
import com.intellij.packageDependencies.DependenciesBuilder;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.usages.*;
|
||||
import com.intellij.util.Alarm;
|
||||
@@ -57,10 +58,15 @@ public class UsagesPanel extends JPanel {
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
public void run() {
|
||||
UsageInfo[] usages = new UsageInfo[0];
|
||||
Set<PsiFile> elementsToSearch = null;
|
||||
|
||||
try {
|
||||
if (myBuilder.isBackward()){
|
||||
elementsToSearch = searchIn;
|
||||
usages = FindDependencyUtil.findBackwardDependencies(myBuilder, searchFor, searchIn);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
elementsToSearch = searchFor;
|
||||
usages = FindDependencyUtil.findDependencies(myBuilder, searchIn, searchFor);
|
||||
}
|
||||
}
|
||||
@@ -72,9 +78,10 @@ public class UsagesPanel extends JPanel {
|
||||
|
||||
if (!progress.isCanceled()) {
|
||||
final UsageInfo[] finalUsages = usages;
|
||||
final PsiElement[] _elementsToSearch = elementsToSearch != null? elementsToSearch.toArray(new PsiElement[elementsToSearch.size()]) : PsiElement.EMPTY_ARRAY;
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
showUsages(finalUsages);
|
||||
showUsages(new UsageInfoToUsageConverter.TargetElementsDescriptor(_elementsToSearch), finalUsages);
|
||||
}
|
||||
}, ModalityState.stateForComponent(UsagesPanel.this));
|
||||
}
|
||||
@@ -95,9 +102,9 @@ public class UsagesPanel extends JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
private void showUsages(final UsageInfo[] usageInfos) {
|
||||
private void showUsages(final UsageInfoToUsageConverter.TargetElementsDescriptor descriptor, final UsageInfo[] usageInfos) {
|
||||
try {
|
||||
Usage[] usages = UsageInfoToUsageConverter.convert(usageInfos);
|
||||
Usage[] usages = UsageInfoToUsageConverter.convert(descriptor, usageInfos);
|
||||
UsageViewPresentation presentation = new UsageViewPresentation();
|
||||
presentation.setCodeUsagesString(myBuilder.getRootNodeNameInUsageView());
|
||||
UsageView usageView = myProject.getComponent(UsageViewManager.class).createUsageView(new UsageTarget[0],
|
||||
|
||||
@@ -181,7 +181,8 @@ public abstract class BaseRefactoringProcessor {
|
||||
private void showUsageView(final UsageViewDescriptor viewDescriptor, boolean showReadAccessIcon, boolean showWriteAccessIcon) {
|
||||
UsageViewManager viewManager = myProject.getComponent(UsageViewManager.class);
|
||||
|
||||
final UsageTarget[] targets = PsiElement2UsageTargetAdapter.convert(viewDescriptor.getElements());
|
||||
final PsiElement[] initialElements = viewDescriptor.getElements();
|
||||
final UsageTarget[] targets = PsiElement2UsageTargetAdapter.convert(initialElements);
|
||||
|
||||
Factory<UsageSearcher> searcherFactory = new Factory<UsageSearcher>() {
|
||||
boolean myRequireRefresh = false;
|
||||
@@ -189,6 +190,7 @@ public abstract class BaseRefactoringProcessor {
|
||||
public UsageSearcher create() {
|
||||
UsageSearcher usageSearcher = new UsageSearcher() {
|
||||
public void generate(Processor<Usage> processor) {
|
||||
final PsiElement[] currentElements;
|
||||
if (myRequireRefresh) {
|
||||
List<PsiElement> elements = new ArrayList<PsiElement>();
|
||||
for (int i = 0; i < targets.length; i++) {
|
||||
@@ -197,14 +199,16 @@ public abstract class BaseRefactoringProcessor {
|
||||
elements.add(((PsiElement2UsageTargetAdapter)target).getElement());
|
||||
}
|
||||
}
|
||||
viewDescriptor.refresh(elements.toArray(new PsiElement[elements.size()]));
|
||||
currentElements = elements.toArray(new PsiElement[elements.size()]);
|
||||
viewDescriptor.refresh(currentElements);
|
||||
}
|
||||
else {
|
||||
currentElements = initialElements;
|
||||
myRequireRefresh = true;
|
||||
}
|
||||
|
||||
UsageInfo[] usageInfos = viewDescriptor.getUsages();
|
||||
final Usage[] usages = UsageInfoToUsageConverter.convert(usageInfos);
|
||||
final Usage[] usages = UsageInfoToUsageConverter.convert(new UsageInfoToUsageConverter.TargetElementsDescriptor(currentElements), usageInfos);
|
||||
|
||||
for (int i = 0; i < usages.length; i++) {
|
||||
Usage usage = usages[i];
|
||||
|
||||
@@ -821,9 +821,11 @@ public class InheritanceToDelegationProcessor extends BaseRefactoringProcessor {
|
||||
presentation.setTabText("Instances upcasted to Object");
|
||||
|
||||
UsageViewManager manager = myProject.getComponent(UsageViewManager.class);
|
||||
manager.showUsages(new UsageTarget[]{new PsiElement2UsageTargetAdapter(myClass)},
|
||||
UsageInfoToUsageConverter.convert(usages),
|
||||
presentation);
|
||||
manager.showUsages(
|
||||
new UsageTarget[]{new PsiElement2UsageTargetAdapter(myClass)},
|
||||
UsageInfoToUsageConverter.convert(new UsageInfoToUsageConverter.TargetElementsDescriptor(myClass), usages),
|
||||
presentation
|
||||
);
|
||||
|
||||
WindowManager.getInstance().getStatusBar(myProject).setInfo("Instances upcasted to java.lang.Object found");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user