replace processor with 1-limit with FindProcessor to stop at first element

This commit is contained in:
Anna.Kozlova
2016-11-08 14:20:36 +01:00
parent 65f7e7098f
commit 97aa05e7db
2 changed files with 10 additions and 14 deletions
@@ -346,14 +346,11 @@ public class MarkerType {
return;
}
final PsiElementProcessor.CollectElementsWithLimit<PsiClass> collectProcessor = new PsiElementProcessor.CollectElementsWithLimit<>(2,
new THashSet<>());
final PsiElementProcessor.CollectElementsWithLimit<PsiFunctionalExpression> collectExprProcessor =
new PsiElementProcessor.CollectElementsWithLimit<>(1,
new THashSet<>());
final PsiElementProcessor.FindElement<PsiClass> collectProcessor = new PsiElementProcessor.FindElement<>();
final PsiElementProcessor.FindElement<PsiFunctionalExpression> collectExprProcessor = new PsiElementProcessor.FindElement<>();
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
ClassInheritorsSearch.search(aClass).forEach(new PsiElementProcessorAdapter<>(collectProcessor));
if (collectProcessor.getCollection().size() < 1) {
if (collectProcessor.getFoundElement() == null) {
FunctionalExpressionSearch.search(aClass).forEach(new PsiElementProcessorAdapter<>(collectExprProcessor));
}
}, SEARCHING_FOR_OVERRIDDEN_METHODS, true, aClass.getProject(), (JComponent)e.getComponent())) {
@@ -361,8 +358,8 @@ public class MarkerType {
}
final List<NavigatablePsiElement> inheritors = new ArrayList<>();
inheritors.addAll(collectProcessor.getCollection());
inheritors.addAll(collectExprProcessor.getCollection());
ContainerUtil.addIfNotNull(inheritors, collectProcessor.getFoundElement());
ContainerUtil.addIfNotNull(inheritors, collectExprProcessor.getFoundElement());
if (inheritors.isEmpty()) return;
final PsiClassOrFunctionalExpressionListCellRenderer renderer = new PsiClassOrFunctionalExpressionListCellRenderer();
final SubclassUpdater subclassUpdater = new SubclassUpdater(aClass, renderer);
@@ -34,7 +34,6 @@ import com.intellij.psi.search.SearchScope;
import com.intellij.psi.search.searches.DefinitionsScopedSearch;
import com.intellij.util.CommonProcessors;
import com.intellij.util.Query;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -127,9 +126,8 @@ public class ImplementationSearcher {
return new PsiElement[]{element};
}
PsiElementProcessor.CollectElementsWithLimit<PsiElement> collectProcessor =
new PsiElementProcessor.CollectElementsWithLimit<>(1, new THashSet<>());
PsiElement[][] result = new PsiElement[1][];
PsiElementProcessor.FindElement<PsiElement> collectProcessor = new PsiElementProcessor.FindElement<>();
PsiElement[] result = new PsiElement[1];
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
@Override
public void run() {
@@ -140,7 +138,7 @@ public class ImplementationSearcher {
return !accept(element) || super.processInReadAction(element);
}
});
result[0] = collectProcessor.toArray();
result[0] = collectProcessor.getFoundElement();
}
catch (IndexNotReadyException e) {
ImplementationSearcher.dumbModeNotification(element);
@@ -150,7 +148,8 @@ public class ImplementationSearcher {
}, SEARCHING_FOR_IMPLEMENTATIONS, true, element.getProject())) {
return null;
}
return result[0];
PsiElement foundElement = result[0];
return foundElement != null ? new PsiElement[] {foundElement} : null;
}
protected boolean canShowPopupWithOneItem(PsiElement element) {