mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-91331
This commit is contained in:
@@ -224,11 +224,13 @@ public class ShowUsagesAction extends AnAction implements PopupAction {
|
||||
|
||||
final List<Usage> usages = new ArrayList<Usage>();
|
||||
final Set<UsageNode> visibleNodes = new LinkedHashSet<UsageNode>();
|
||||
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<Usage> usages,
|
||||
@NotNull final UsageInfoToUsageConverter.TargetElementsDescriptor descriptor,
|
||||
@NotNull Set<UsageNode> 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<PsiElement> pointer = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(handler.getPsiElement());
|
||||
data.myElements = new SmartPsiElementPointer[]{pointer};
|
||||
List<SmartPsiElementPointer<PsiElement>> plist = descriptor.getAllElementPointers();
|
||||
|
||||
data.myElements = plist.toArray(new SmartPsiElementPointer[plist.size()]);
|
||||
findUsagesManager.rerunAndRecallFromHistory(data);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -308,12 +308,10 @@ public class FindUsagesManager implements JDOMExternalizable {
|
||||
|
||||
@NotNull
|
||||
public static ProgressIndicator startProcessUsages(@NotNull FindUsagesHandler handler,
|
||||
@NotNull UsageInfoToUsageConverter.TargetElementsDescriptor descriptor,
|
||||
@NotNull final Processor<Usage> 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();
|
||||
|
||||
@@ -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<SmartPsiElementPointer> myPrimarySearchedElements;
|
||||
private final List<SmartPsiElementPointer> myAdditionalSearchedElements;
|
||||
private final List<SmartPsiElementPointer<PsiElement>> myPrimarySearchedElements;
|
||||
private final List<SmartPsiElementPointer<PsiElement>> 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<SmartPsiElementPointer,PsiElement> SMARTPOINTER_TO_ELEMENT_MAPPER = new Function<SmartPsiElementPointer, PsiElement>() {
|
||||
private static final Function<SmartPsiElementPointer<PsiElement>,PsiElement> SMARTPOINTER_TO_ELEMENT_MAPPER = new Function<SmartPsiElementPointer<PsiElement>, PsiElement>() {
|
||||
@Override
|
||||
public PsiElement fun(final SmartPsiElementPointer s) {
|
||||
return s.getElement();
|
||||
public PsiElement fun(final SmartPsiElementPointer<PsiElement> pointer) {
|
||||
return pointer.getElement();
|
||||
}
|
||||
};
|
||||
private static PsiElement[] convertToPsiElements(final List<SmartPsiElementPointer> primary) {
|
||||
|
||||
@NotNull
|
||||
private static PsiElement[] convertToPsiElements(@NotNull List<SmartPsiElementPointer<PsiElement>> primary) {
|
||||
return ContainerUtil.map2Array(primary, PsiElement.class, SMARTPOINTER_TO_ELEMENT_MAPPER);
|
||||
}
|
||||
|
||||
private static List<SmartPsiElementPointer> convertToSmartPointers(final PsiElement[] primaryElements) {
|
||||
return primaryElements != null ? ContainerUtil.mapNotNull(primaryElements, new Function<PsiElement, SmartPsiElementPointer>() {
|
||||
@Override
|
||||
public SmartPsiElementPointer fun(final PsiElement s) {
|
||||
return SmartPointerManager.getInstance(s.getProject()).createSmartPsiElementPointer(s);
|
||||
}
|
||||
}) : Collections.<SmartPsiElementPointer>emptyList();
|
||||
@NotNull
|
||||
private static List<SmartPsiElementPointer<PsiElement>> convertToSmartPointers(@NotNull PsiElement[] primaryElements) {
|
||||
return ContainerUtil.mapNotNull(primaryElements, new Function<PsiElement, SmartPsiElementPointer<PsiElement>>() {
|
||||
@Override
|
||||
public SmartPsiElementPointer<PsiElement> 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<? extends PsiElement> getAllElements() {
|
||||
|
||||
@NotNull
|
||||
public List<PsiElement> getAllElements() {
|
||||
List<PsiElement> result = new ArrayList<PsiElement>(myPrimarySearchedElements.size() + myAdditionalSearchedElements.size());
|
||||
for (SmartPsiElementPointer pointer : myPrimarySearchedElements) {
|
||||
PsiElement element = pointer.getElement();
|
||||
@@ -105,15 +111,22 @@ public class UsageInfoToUsageConverter {
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<SmartPsiElementPointer<PsiElement>> getAllElementPointers() {
|
||||
List<SmartPsiElementPointer<PsiElement>> result = new ArrayList<SmartPsiElementPointer<PsiElement>>(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;
|
||||
}
|
||||
|
||||
@@ -300,7 +300,21 @@ public class ArrayUtil extends ArrayUtilRt {
|
||||
return append(src, element, (Class<T>)src.getClass().getComponentType());
|
||||
}
|
||||
|
||||
public static <T> T[] append(@NotNull final T[] src, final T element, ArrayFactory<T> factory) {
|
||||
@NotNull
|
||||
public static <T> T[] prepend(final T element, @NotNull final T[] array) {
|
||||
return prepend(element, array, (Class<T>)array.getClass().getComponentType());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <T> T[] prepend(T element, @NotNull T[] array, @NotNull Class<T> 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> T[] append(@NotNull final T[] src, final T element, @NotNull ArrayFactory<T> factory) {
|
||||
int length = src.length;
|
||||
T[] result = factory.create(length + 1);
|
||||
System.arraycopy(src, 0, result, 0, length);
|
||||
|
||||
Reference in New Issue
Block a user