diff --git a/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java b/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java index 5d3bce67739f..aed782a2ba0d 100644 --- a/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java +++ b/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java @@ -224,11 +224,13 @@ public class ShowUsagesAction extends AnAction implements PopupAction { final List usages = new ArrayList(); final Set visibleNodes = new LinkedHashSet(); + UsageInfoToUsageConverter.TargetElementsDescriptor descriptor = + new UsageInfoToUsageConverter.TargetElementsDescriptor(handler.getPrimaryElements(), handler.getSecondaryElements()); final MyTable table = new MyTable(); final AsyncProcessIcon processIcon = new AsyncProcessIcon("xxx"); - final JBPopup popup = createUsagePopup(usages, visibleNodes, handler, editor, popupPosition, maxUsages, usageView, options, table, presentation, - processIcon); + final JBPopup popup = createUsagePopup(usages, descriptor, visibleNodes, handler, editor, popupPosition, + maxUsages, usageView, options, table, presentation, processIcon); Disposer.register(popup, usageView); @@ -288,7 +290,7 @@ public class ShowUsagesAction extends AnAction implements PopupAction { } }; - final ProgressIndicator indicator = FindUsagesManager.startProcessUsages(handler, collect, options, new Runnable() { + final ProgressIndicator indicator = FindUsagesManager.startProcessUsages(handler, descriptor, collect, options, new Runnable() { @Override public void run() { ApplicationManager.getApplication().invokeLater(new Runnable() { @@ -456,6 +458,7 @@ public class ShowUsagesAction extends AnAction implements PopupAction { @NotNull private JBPopup createUsagePopup(@NotNull final List usages, + @NotNull final UsageInfoToUsageConverter.TargetElementsDescriptor descriptor, @NotNull Set visibleNodes, @NotNull final FindUsagesHandler handler, final Editor editor, @@ -613,8 +616,9 @@ public class ShowUsagesAction extends AnAction implements PopupAction { FindUsagesManager findUsagesManager = ((FindManagerImpl)FindManager.getInstance(project)).getFindUsagesManager(); FindUsagesManager.SearchData data = new FindUsagesManager.SearchData(); data.myOptions = options; - SmartPsiElementPointer pointer = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(handler.getPsiElement()); - data.myElements = new SmartPsiElementPointer[]{pointer}; + List> plist = descriptor.getAllElementPointers(); + + data.myElements = plist.toArray(new SmartPsiElementPointer[plist.size()]); findUsagesManager.rerunAndRecallFromHistory(data); } }); 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 55239f9a5d27..51fe7537e7d8 100644 --- a/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java +++ b/platform/lang-impl/src/com/intellij/find/findUsages/FindUsagesManager.java @@ -308,12 +308,10 @@ public class FindUsagesManager implements JDOMExternalizable { @NotNull public static ProgressIndicator startProcessUsages(@NotNull FindUsagesHandler handler, + @NotNull UsageInfoToUsageConverter.TargetElementsDescriptor descriptor, @NotNull final Processor processor, @NotNull FindUsagesOptions findUsagesOptions, @NotNull final Runnable onComplete) { - final UsageInfoToUsageConverter.TargetElementsDescriptor descriptor = - new UsageInfoToUsageConverter.TargetElementsDescriptor(handler.getPrimaryElements(), handler.getSecondaryElements()); - final UsageSearcher usageSearcher = createUsageSearcher(descriptor, handler, findUsagesOptions, null); final ProgressIndicatorBase indicator = new ProgressIndicatorBase(); diff --git a/platform/usageView/src/com/intellij/usages/UsageInfoToUsageConverter.java b/platform/usageView/src/com/intellij/usages/UsageInfoToUsageConverter.java index 9c099c8aa317..69cc7af5e4bd 100644 --- a/platform/usageView/src/com/intellij/usages/UsageInfoToUsageConverter.java +++ b/platform/usageView/src/com/intellij/usages/UsageInfoToUsageConverter.java @@ -26,7 +26,6 @@ import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; -import java.util.Collections; import java.util.List; /** @@ -38,39 +37,42 @@ public class UsageInfoToUsageConverter { } public static class TargetElementsDescriptor { - private final List myPrimarySearchedElements; - private final List myAdditionalSearchedElements; + private final List> myPrimarySearchedElements; + private final List> myAdditionalSearchedElements; - public TargetElementsDescriptor(PsiElement element) { + public TargetElementsDescriptor(@NotNull PsiElement element) { this(new PsiElement[]{element}); } - public TargetElementsDescriptor(PsiElement[] primarySearchedElements) { + public TargetElementsDescriptor(@NotNull PsiElement[] primarySearchedElements) { this(primarySearchedElements, PsiElement.EMPTY_ARRAY); } - public TargetElementsDescriptor(PsiElement[] primarySearchedElements, PsiElement[] additionalSearchedElements) { + public TargetElementsDescriptor(@NotNull PsiElement[] primarySearchedElements, @NotNull PsiElement[] additionalSearchedElements) { myPrimarySearchedElements = convertToSmartPointers(primarySearchedElements); myAdditionalSearchedElements = convertToSmartPointers(additionalSearchedElements); } - private static final Function SMARTPOINTER_TO_ELEMENT_MAPPER = new Function() { + private static final Function,PsiElement> SMARTPOINTER_TO_ELEMENT_MAPPER = new Function, PsiElement>() { @Override - public PsiElement fun(final SmartPsiElementPointer s) { - return s.getElement(); + public PsiElement fun(final SmartPsiElementPointer pointer) { + return pointer.getElement(); } }; - private static PsiElement[] convertToPsiElements(final List primary) { + + @NotNull + private static PsiElement[] convertToPsiElements(@NotNull List> primary) { return ContainerUtil.map2Array(primary, PsiElement.class, SMARTPOINTER_TO_ELEMENT_MAPPER); } - private static List convertToSmartPointers(final PsiElement[] primaryElements) { - return primaryElements != null ? ContainerUtil.mapNotNull(primaryElements, new Function() { - @Override - public SmartPsiElementPointer fun(final PsiElement s) { - return SmartPointerManager.getInstance(s.getProject()).createSmartPsiElementPointer(s); - } - }) : Collections.emptyList(); + @NotNull + private static List> convertToSmartPointers(@NotNull PsiElement[] primaryElements) { + return ContainerUtil.mapNotNull(primaryElements, new Function>() { + @Override + public SmartPsiElementPointer fun(final PsiElement s) { + return SmartPointerManager.getInstance(s.getProject()).createSmartPsiElementPointer(s); + } + }); } /** @@ -81,14 +83,18 @@ public class UsageInfoToUsageConverter { * 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. */ + @NotNull public PsiElement[] getPrimaryElements() { return convertToPsiElements(myPrimarySearchedElements); } + @NotNull public PsiElement[] getAdditionalElements() { return convertToPsiElements(myAdditionalSearchedElements); } - public List getAllElements() { + + @NotNull + public List getAllElements() { List result = new ArrayList(myPrimarySearchedElements.size() + myAdditionalSearchedElements.size()); for (SmartPsiElementPointer pointer : myPrimarySearchedElements) { PsiElement element = pointer.getElement(); @@ -105,15 +111,22 @@ public class UsageInfoToUsageConverter { return result; } + @NotNull + public List> getAllElementPointers() { + List> result = new ArrayList>(myPrimarySearchedElements.size() + myAdditionalSearchedElements.size()); + result.addAll(myPrimarySearchedElements); + result.addAll(myAdditionalSearchedElements); + return result; + } } @NotNull - public static Usage convert(TargetElementsDescriptor descriptor, UsageInfo usageInfo) { - final PsiElement[] primaryElements = descriptor.getPrimaryElements(); + public static Usage convert(@NotNull TargetElementsDescriptor descriptor, @NotNull UsageInfo usageInfo) { + PsiElement[] primaryElements = descriptor.getPrimaryElements(); + PsiElement usageElement = usageInfo.getElement(); for(ReadWriteAccessDetector detector: Extensions.getExtensions(ReadWriteAccessDetector.EP_NAME)) { if (isReadWriteAccessibleElements(primaryElements, detector)) { - final PsiElement usageElement = usageInfo.getElement(); final ReadWriteAccessDetector.Access rwAccess = detector.getExpressionAccess(usageElement); return new ReadWriteAccessUsageInfo2UsageAdapter(usageInfo, rwAccess != ReadWriteAccessDetector.Access.Write, @@ -123,7 +136,8 @@ public class UsageInfoToUsageConverter { return new UsageInfo2UsageAdapter(usageInfo); } - public static Usage[] convert(TargetElementsDescriptor descriptor, UsageInfo[] usageInfos) { + @NotNull + public static Usage[] convert(@NotNull TargetElementsDescriptor descriptor, @NotNull UsageInfo[] usageInfos) { Usage[] usages = new Usage[usageInfos.length]; for (int i = 0; i < usages.length; i++) { usages[i] = convert(descriptor, usageInfos[i]); @@ -131,7 +145,7 @@ public class UsageInfoToUsageConverter { return usages; } - private static boolean isReadWriteAccessibleElements(final PsiElement[] elements, final ReadWriteAccessDetector detector) { + private static boolean isReadWriteAccessibleElements(@NotNull PsiElement[] elements, @NotNull ReadWriteAccessDetector detector) { if (elements.length == 0) { return false; } diff --git a/platform/util/src/com/intellij/util/ArrayUtil.java b/platform/util/src/com/intellij/util/ArrayUtil.java index aaa48d042c7f..d5dbeb1e9fe1 100644 --- a/platform/util/src/com/intellij/util/ArrayUtil.java +++ b/platform/util/src/com/intellij/util/ArrayUtil.java @@ -300,7 +300,21 @@ public class ArrayUtil extends ArrayUtilRt { return append(src, element, (Class)src.getClass().getComponentType()); } - public static T[] append(@NotNull final T[] src, final T element, ArrayFactory factory) { + @NotNull + public static T[] prepend(final T element, @NotNull final T[] array) { + return prepend(element, array, (Class)array.getClass().getComponentType()); + } + + @NotNull + public static T[] prepend(T element, @NotNull T[] array, @NotNull Class type) { + int length = array.length; + T[] result = (T[])Array.newInstance(type, length + 1); + System.arraycopy(array, 0, result, 0, length); + result[length] = element; + return result; + } + + public static T[] append(@NotNull final T[] src, final T element, @NotNull ArrayFactory factory) { int length = src.length; T[] result = factory.create(length + 1); System.arraycopy(src, 0, result, 0, length);