From c196e66f24c03f5a67cb0a75d987e2c6e2dcd012 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Mon, 7 Jan 2019 16:24:11 +0100 Subject: [PATCH] Move createSessionForLookupElement() to ImplementationViewSessionFactory; clarify code (IDEA-CR-41751) --- .../hint/ImplementationViewSession.kt | 28 +++++++++++++++++-- .../hint/PsiImplementationViewSession.java | 27 +++++------------- .../actions/ShowImplementationsAction.java | 5 ++-- 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hint/ImplementationViewSession.kt b/platform/lang-impl/src/com/intellij/codeInsight/hint/ImplementationViewSession.kt index bd10e445fc58..eab7bf4abff1 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hint/ImplementationViewSession.kt +++ b/platform/lang-impl/src/com/intellij/codeInsight/hint/ImplementationViewSession.kt @@ -1,6 +1,8 @@ // Copyright 2000-2019 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.codeInsight.documentation.DocumentationManager +import com.intellij.codeInsight.hint.PsiImplementationViewSession.getSelfAndImplementations import com.intellij.openapi.actionSystem.DataContext import com.intellij.openapi.editor.Editor import com.intellij.openapi.extensions.ExtensionPointName @@ -8,10 +10,17 @@ 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.psi.presentation.java.SymbolPresentationUtil import com.intellij.util.Processor interface ImplementationViewSession { + val factory: ImplementationViewSessionFactory val project: Project + + /** + * The list of implementations which could be found synchronously. Additional implementations can be obtained by calling + * [searchImplementationsInBackground]. + */ val implementationElements: List val file: PsiFile? @@ -19,8 +28,6 @@ interface ImplementationViewSession { val text: String? val editor: Editor? - fun createSessionForLookupElement(lookupItemObject: Any?, isSearchDeep: Boolean): ImplementationViewSession? - fun searchImplementationsInBackground(indicator: ProgressIndicator, isSearchDeep: Boolean, includeSelf: Boolean, @@ -31,6 +38,7 @@ interface ImplementationViewSession { interface ImplementationViewSessionFactory { fun createSession(dataContext: DataContext, project: Project, invokedByShortcut: Boolean): ImplementationViewSession? + fun createSessionForLookupElement(project: Project, editor: Editor?, file: PsiFile?, lookupItemObject: Any?, isSearchDeep: Boolean): ImplementationViewSession? companion object { @JvmField val EP_NAME = ExtensionPointName.create("com.intellij.implementationViewSessionFactory") @@ -41,4 +49,20 @@ class PsiImplementationSessionViewFactory : ImplementationViewSessionFactory { override fun createSession(dataContext: DataContext, project: Project, invokedByShortcut: Boolean): ImplementationViewSession? { return PsiImplementationViewSession.create(dataContext, project, invokedByShortcut) } + + override fun createSessionForLookupElement(project: Project, editor: Editor?, file: PsiFile?, lookupItemObject: Any?, isSearchDeep: Boolean): ImplementationViewSession? { + val element = lookupItemObject as? PsiElement ?: DocumentationManager.getInstance(project).getElementFromLookup(editor, file) + var impls = arrayOf() + var text = "" + if (element != null) { + // if (element instanceof PsiPackage) return; + val containingFile = element.containingFile + if (containingFile == null || !containingFile.viewProvider.isPhysical) return null + + impls = getSelfAndImplementations(editor, element, PsiImplementationViewSession.createImplementationsSearcher(isSearchDeep)) + text = SymbolPresentationUtil.getSymbolPresentableText(element) + } + + return PsiImplementationViewSession(project, element, impls, text, editor, file) + } } 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 f1987239d321..6c48c50d02d6 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hint/PsiImplementationViewSession.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/hint/PsiImplementationViewSession.java @@ -1,4 +1,4 @@ -// 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. +// Copyright 2000-2019 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.codeInsight.TargetElementUtil; @@ -52,6 +52,12 @@ public class PsiImplementationViewSession implements ImplementationViewSession { myFile = file; } + @NotNull + @Override + public ImplementationViewSessionFactory getFactory() { + return ImplementationViewSessionFactory.EP_NAME.findExtensionOrFail(PsiImplementationSessionViewFactory.class); + } + @NotNull public Project getProject() { return myProject; @@ -83,25 +89,6 @@ public class PsiImplementationViewSession implements ImplementationViewSession { return myFile; } - @Override - public PsiImplementationViewSession createSessionForLookupElement(Object lookupItemObject, boolean isSearchDeep) { - final PsiElement element = lookupItemObject instanceof PsiElement - ? (PsiElement)lookupItemObject - : DocumentationManager.getInstance(myProject).getElementFromLookup(myEditor, myFile); - PsiElement[] impls = {}; - String text = ""; - if (element != null) { - // if (element instanceof PsiPackage) return; - PsiFile containingFile = element.getContainingFile(); - if (containingFile == null || !containingFile.getViewProvider().isPhysical()) return null; - - impls = getSelfAndImplementations(myEditor, element, PsiImplementationViewSession.createImplementationsSearcher(isSearchDeep)); - text = SymbolPresentationUtil.getSymbolPresentableText(element); - } - - return new PsiImplementationViewSession(myProject, element, impls, text, myEditor, myFile); - } - @Override public boolean elementRequiresIncludeSelf() { return !(myElement instanceof PomTargetPsiElement); 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 611bcafe6651..b802aa782c07 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 @@ -1,4 +1,4 @@ -// 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. +// Copyright 2000-2019 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.actions; import com.intellij.codeInsight.CodeInsightBundle; @@ -87,7 +87,8 @@ public class ShowImplementationsAction extends AnAction implements PopupAction { } private void updateElementImplementations(final Object lookupItemObject, ImplementationViewSession session) { - ImplementationViewSession newSession = session.createSessionForLookupElement(lookupItemObject, isSearchDeep()); + ImplementationViewSession newSession = session.getFactory().createSessionForLookupElement(session.getProject(), + session.getEditor(), session.getFile(), lookupItemObject, isSearchDeep()); if (newSession != null) { showImplementations(newSession, false, false); }