From 9c7b1ab1c4359e4b3854c014fcb7908f43f49683 Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Thu, 3 Nov 2016 16:16:11 +0100 Subject: [PATCH] definitions search: distinguish show implementations and goto implementations --- .../hint/actions/ShowSiblingsAction.java | 7 ++++++- .../searches/DefinitionsScopedSearch.java | 15 ++++++++++++--- .../actions/ShowImplementationsAction.java | 18 ++++++++++++++++-- .../navigation/ImplementationSearcher.java | 17 +++++++++++++---- 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/hint/actions/ShowSiblingsAction.java b/java/java-impl/src/com/intellij/codeInsight/hint/actions/ShowSiblingsAction.java index 937a27572eeb..a7c8780f95f3 100644 --- a/java/java-impl/src/com/intellij/codeInsight/hint/actions/ShowSiblingsAction.java +++ b/java/java-impl/src/com/intellij/codeInsight/hint/actions/ShowSiblingsAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -73,6 +73,11 @@ public class ShowSiblingsAction extends ShowImplementationsAction { } } + @Override + protected boolean isSearchDeep() { + return true; + } + private void showSiblings(boolean invokedByShortcut, @NotNull Project project, Editor editor, diff --git a/platform/indexing-api/src/com/intellij/psi/search/searches/DefinitionsScopedSearch.java b/platform/indexing-api/src/com/intellij/psi/search/searches/DefinitionsScopedSearch.java index 6faa3cfaa4e4..03cfe5540943 100644 --- a/platform/indexing-api/src/com/intellij/psi/search/searches/DefinitionsScopedSearch.java +++ b/platform/indexing-api/src/com/intellij/psi/search/searches/DefinitionsScopedSearch.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -53,9 +53,18 @@ public class DefinitionsScopedSearch extends ExtensibleQueryFactory search(PsiElement definitionsOf) { return INSTANCE.createUniqueResultsQuery(new SearchParameters(definitionsOf)); } - + public static Query search(PsiElement definitionsOf, SearchScope searchScope) { - return INSTANCE.createUniqueResultsQuery(new SearchParameters(definitionsOf, searchScope, true)); + return search(definitionsOf, searchScope, true); + } + + /** + * @param checkDeep false for show implementations to present definition only + */ + public static Query search(PsiElement definitionsOf, + SearchScope searchScope, + final boolean checkDeep) { + return INSTANCE.createUniqueResultsQuery(new SearchParameters(definitionsOf, searchScope, checkDeep)); } public static class SearchParameters { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hint/actions/ShowImplementationsAction.java b/platform/lang-impl/src/com/intellij/codeInsight/hint/actions/ShowImplementationsAction.java index c5187394a745..8a727fe9f64d 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hint/actions/ShowImplementationsAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/hint/actions/ShowImplementationsAction.java @@ -199,7 +199,7 @@ public class ShowImplementationsAction extends AnAction implements PopupAction { } @NotNull - static ImplementationSearcher createImplementationsSearcher() { + ImplementationSearcher createImplementationsSearcher() { if (ApplicationManager.getApplication().isUnitTestMode()) { return new ImplementationSearcher() { @Override @@ -213,6 +213,11 @@ public class ShowImplementationsAction extends AnAction implements PopupAction { protected PsiElement[] filterElements(PsiElement element, PsiElement[] targetElements) { return ShowImplementationsAction.filterElements(targetElements); } + + @Override + protected boolean isSearchDeep() { + return ShowImplementationsAction.this.isSearchDeep(); + } }; } @@ -399,7 +404,11 @@ public class ShowImplementationsAction extends AnAction implements PopupAction { return PsiUtilCore.toPsiElementArray(unique); } - private static class ImplementationsUpdaterTask extends BackgroundUpdaterTask { + protected boolean isSearchDeep() { + return false; + } + + private class ImplementationsUpdaterTask extends BackgroundUpdaterTask { private final String myCaption; private final Editor myEditor; @NotNull @@ -441,6 +450,11 @@ public class ShowImplementationsAction extends AnAction implements PopupAction { super.run(indicator); final ImplementationSearcher.BackgroundableImplementationSearcher implementationSearcher = new ImplementationSearcher.BackgroundableImplementationSearcher() { + @Override + protected boolean isSearchDeep() { + return ShowImplementationsAction.this.isSearchDeep(); + } + @Override protected void processElement(PsiElement element) { if (!updateComponent(element, null)) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/navigation/ImplementationSearcher.java b/platform/lang-impl/src/com/intellij/codeInsight/navigation/ImplementationSearcher.java index 22536aa09383..6080b0721467 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/navigation/ImplementationSearcher.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/navigation/ImplementationSearcher.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -33,6 +33,7 @@ import com.intellij.psi.search.PsiElementProcessorAdapter; 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; @@ -104,7 +105,7 @@ public class ImplementationSearcher { final PsiElement[][] result = new PsiElement[1][]; if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> { try { - result[0] = DefinitionsScopedSearch.search(element, getSearchScope(element, editor)).toArray(PsiElement.EMPTY_ARRAY); + result[0] = search(element, editor).toArray(PsiElement.EMPTY_ARRAY); } catch (IndexNotReadyException e) { dumbModeNotification(element); @@ -116,6 +117,14 @@ public class ImplementationSearcher { return result[0]; } + protected Query search(PsiElement element, Editor editor) { + return DefinitionsScopedSearch.search(element, getSearchScope(element, editor), isSearchDeep()); + } + + protected boolean isSearchDeep() { + return true; + } + private static void dumbModeNotification(@NotNull PsiElement element) { Project project = ApplicationManager.getApplication().runReadAction(new Computable() { @Override @@ -148,7 +157,7 @@ public class ImplementationSearcher { @Override public void run() { try { - DefinitionsScopedSearch.search(element, getSearchScope(element, editor)).forEach(new PsiElementProcessorAdapter(collectProcessor){ + search(element, editor).forEach(new PsiElementProcessorAdapter(collectProcessor){ @Override public boolean processInReadAction(PsiElement element) { return !accept(element) || super.processInReadAction(element); @@ -187,7 +196,7 @@ public class ImplementationSearcher { } }; try { - DefinitionsScopedSearch.search(element, getSearchScope(element, editor)).forEach(processor); + search(element, editor).forEach(processor); } catch (IndexNotReadyException e) { ImplementationSearcher.dumbModeNotification(element);