From 5c52c4099b6da5c11de3471d3e7bb2feb85f1cd0 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 28 Dec 2018 15:28:05 +0100 Subject: [PATCH] ImplementationViewSession interface, factory and extension point --- .../ShowImplementationsTestUtil.java | 4 +- .../hint/ImplementationViewSession.kt | 44 +++++++++++++++++++ .../hint/PsiImplementationViewSession.java | 13 +++++- .../actions/ShowImplementationsAction.java | 26 +++++------ .../src/META-INF/LangExtensionPoints.xml | 2 + .../src/META-INF/LangExtensions.xml | 2 + 6 files changed, 74 insertions(+), 17 deletions(-) create mode 100644 platform/lang-impl/src/com/intellij/codeInsight/hint/ImplementationViewSession.kt diff --git a/java/testFramework/src/com/intellij/codeInsight/ShowImplementationsTestUtil.java b/java/testFramework/src/com/intellij/codeInsight/ShowImplementationsTestUtil.java index 70b3efe52cc3..4008d85c7aa4 100644 --- a/java/testFramework/src/com/intellij/codeInsight/ShowImplementationsTestUtil.java +++ b/java/testFramework/src/com/intellij/codeInsight/ShowImplementationsTestUtil.java @@ -2,8 +2,8 @@ package com.intellij.codeInsight; import com.intellij.codeInsight.hint.ImplementationViewElement; +import com.intellij.codeInsight.hint.ImplementationViewSession; import com.intellij.codeInsight.hint.PsiImplementationViewElement; -import com.intellij.codeInsight.hint.PsiImplementationViewSession; import com.intellij.codeInsight.hint.actions.ShowImplementationsAction; import com.intellij.ide.DataManager; import com.intellij.openapi.actionSystem.DataContext; @@ -26,7 +26,7 @@ public class ShowImplementationsTestUtil { final Ref> ref = new Ref<>(); new ShowImplementationsAction() { @Override - protected void showImplementations(@NotNull PsiImplementationViewSession session, + protected void showImplementations(@NotNull ImplementationViewSession session, boolean invokedFromEditor, boolean invokedByShortcut) { ref.set(session.getImplementationElements()); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hint/ImplementationViewSession.kt b/platform/lang-impl/src/com/intellij/codeInsight/hint/ImplementationViewSession.kt new file mode 100644 index 000000000000..06ed20a5d0b1 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/hint/ImplementationViewSession.kt @@ -0,0 +1,44 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.codeInsight.hint + +import com.intellij.openapi.actionSystem.DataContext +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.extensions.ExtensionPointName +import com.intellij.openapi.progress.ProgressIndicator +import com.intellij.openapi.project.Project +import com.intellij.psi.PsiElement +import com.intellij.psi.PsiFile +import com.intellij.util.Processor + +interface ImplementationViewSession { + val project: Project + val implementationElements: List + val file: PsiFile? + + val element: PsiElement? + val text: String? + val editor: Editor? + + fun createSessionForLookupElement(lookupItemObject: Any?, isSearchDeep: Boolean): PsiImplementationViewSession? + + fun searchImplementationsInBackground(indicator: ProgressIndicator, + isSearchDeep: Boolean, + includeSelf: Boolean, + processor: Processor): List + fun elementRequiresIncludeSelf(): Boolean + fun needUpdateInBackground(): Boolean +} + +interface ImplementationViewSessionFactory { + fun createSession(dataContext: DataContext, project: Project, invokedByShortcut: Boolean): ImplementationViewSession? + + companion object { + @JvmField val EP_NAME = ExtensionPointName.create("com.intellij.implementationViewSessionFactory") + } +} + +class PsiImplementationSessionViewFactory : ImplementationViewSessionFactory { + override fun createSession(dataContext: DataContext, project: Project, invokedByShortcut: Boolean): ImplementationViewSession? { + return PsiImplementationViewSession.create(dataContext, project, invokedByShortcut) + } +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hint/PsiImplementationViewSession.java b/platform/lang-impl/src/com/intellij/codeInsight/hint/PsiImplementationViewSession.java index 9f73837ed6c2..f1987239d321 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hint/PsiImplementationViewSession.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/hint/PsiImplementationViewSession.java @@ -32,7 +32,7 @@ import java.util.*; /** * @author yole */ -public class PsiImplementationViewSession { +public class PsiImplementationViewSession implements ImplementationViewSession { private static final Logger LOG = Logger.getInstance(PsiImplementationViewSession.class); @NotNull private final Project myProject; @@ -57,19 +57,23 @@ public class PsiImplementationViewSession { return myProject; } + @Override @Nullable public PsiElement getElement() { return myElement; } + @NotNull public List getImplementationElements() { return ContainerUtil.map(myImpls, PsiImplementationViewElement::new); } + @Override public String getText() { return myText; } + @Override public Editor getEditor() { return myEditor; } @@ -79,6 +83,7 @@ public class PsiImplementationViewSession { return myFile; } + @Override public PsiImplementationViewSession createSessionForLookupElement(Object lookupItemObject, boolean isSearchDeep) { final PsiElement element = lookupItemObject instanceof PsiElement ? (PsiElement)lookupItemObject @@ -97,10 +102,12 @@ public class PsiImplementationViewSession { return new PsiImplementationViewSession(myProject, element, impls, text, myEditor, myFile); } + @Override public boolean elementRequiresIncludeSelf() { return !(myElement instanceof PomTargetPsiElement); } + @Override public boolean needUpdateInBackground() { return myElement != null; } @@ -184,10 +191,12 @@ public class PsiImplementationViewSession { }); } + @NotNull + @Override public List searchImplementationsInBackground(@NotNull ProgressIndicator indicator, boolean isSearchDeep, boolean includeSelf, - final Processor processor) { + @NotNull final Processor processor) { final ImplementationSearcher.BackgroundableImplementationSearcher implementationSearcher = new ImplementationSearcher.BackgroundableImplementationSearcher() { @Override 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 bf1a7aa20bcb..611bcafe6651 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 @@ -3,10 +3,7 @@ package com.intellij.codeInsight.hint.actions; import com.intellij.codeInsight.CodeInsightBundle; import com.intellij.codeInsight.documentation.DocumentationManager; -import com.intellij.codeInsight.hint.ImplementationViewComponent; -import com.intellij.codeInsight.hint.ImplementationViewElement; -import com.intellij.codeInsight.hint.PsiImplementationViewElement; -import com.intellij.codeInsight.hint.PsiImplementationViewSession; +import com.intellij.codeInsight.hint.*; import com.intellij.codeInsight.lookup.LookupManager; import com.intellij.codeInsight.navigation.BackgroundUpdaterTask; import com.intellij.codeInsight.navigation.ImplementationSearcher; @@ -81,19 +78,22 @@ public class ShowImplementationsAction extends AnAction implements PopupAction { boolean isInvokedFromEditor = CommonDataKeys.EDITOR.getData(dataContext) != null; - PsiImplementationViewSession psiImplementationViewSession = PsiImplementationViewSession.create(dataContext, project, isSearchDeep()); - if (psiImplementationViewSession == null) return; - showImplementations(psiImplementationViewSession, isInvokedFromEditor, invokedByShortcut); + for (ImplementationViewSessionFactory factory: ImplementationViewSessionFactory.EP_NAME.getExtensionList() ) { + ImplementationViewSession session = factory.createSession(dataContext, project, invokedByShortcut); + if (session != null) { + showImplementations(session, isInvokedFromEditor, invokedByShortcut); + } + } } - private void updateElementImplementations(final Object lookupItemObject, PsiImplementationViewSession session) { - PsiImplementationViewSession newSession = session.createSessionForLookupElement(lookupItemObject, isSearchDeep()); + private void updateElementImplementations(final Object lookupItemObject, ImplementationViewSession session) { + ImplementationViewSession newSession = session.createSessionForLookupElement(lookupItemObject, isSearchDeep()); if (newSession != null) { showImplementations(newSession, false, false); } } - protected void showImplementations(@NotNull PsiImplementationViewSession session, + protected void showImplementations(@NotNull ImplementationViewSession session, boolean invokedFromEditor, boolean invokedByShortcut) { @@ -175,7 +175,7 @@ public class ShowImplementationsAction extends AnAction implements PopupAction { } } - private void updateInBackground(@NotNull PsiImplementationViewSession session, + private void updateInBackground(@NotNull ImplementationViewSession session, @NotNull ImplementationViewComponent component, String title, @NotNull AbstractPopup popup, @@ -231,12 +231,12 @@ public class ShowImplementationsAction extends AnAction implements PopupAction { private class ImplementationsUpdaterTask extends BackgroundUpdaterTask { private final String myCaption; - private final PsiImplementationViewSession mySession; + private final ImplementationViewSession mySession; private final boolean myIncludeSelf; private final ImplementationViewComponent myComponent; private List myElements; - private ImplementationsUpdaterTask(PsiImplementationViewSession session, + private ImplementationsUpdaterTask(ImplementationViewSession session, final String caption, boolean includeSelf, ImplementationViewComponent component) { diff --git a/platform/platform-resources/src/META-INF/LangExtensionPoints.xml b/platform/platform-resources/src/META-INF/LangExtensionPoints.xml index 9ebe128afb58..07cb2f90e566 100644 --- a/platform/platform-resources/src/META-INF/LangExtensionPoints.xml +++ b/platform/platform-resources/src/META-INF/LangExtensionPoints.xml @@ -996,6 +996,8 @@ + + diff --git a/platform/platform-resources/src/META-INF/LangExtensions.xml b/platform/platform-resources/src/META-INF/LangExtensions.xml index 7aee3daab603..80d870123368 100644 --- a/platform/platform-resources/src/META-INF/LangExtensions.xml +++ b/platform/platform-resources/src/META-INF/LangExtensions.xml @@ -1184,6 +1184,8 @@ + +