mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ImplementationViewSession interface, factory and extension point
This commit is contained in:
@@ -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<List<ImplementationViewElement>> 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());
|
||||
|
||||
@@ -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<ImplementationViewElement>
|
||||
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<PsiElement>): List<ImplementationViewElement>
|
||||
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<ImplementationViewSessionFactory>("com.intellij.implementationViewSessionFactory")
|
||||
}
|
||||
}
|
||||
|
||||
class PsiImplementationSessionViewFactory : ImplementationViewSessionFactory {
|
||||
override fun createSession(dataContext: DataContext, project: Project, invokedByShortcut: Boolean): ImplementationViewSession? {
|
||||
return PsiImplementationViewSession.create(dataContext, project, invokedByShortcut)
|
||||
}
|
||||
}
|
||||
+11
-2
@@ -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<ImplementationViewElement> 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<ImplementationViewElement> searchImplementationsInBackground(@NotNull ProgressIndicator indicator,
|
||||
boolean isSearchDeep,
|
||||
boolean includeSelf,
|
||||
final Processor<PsiElement> processor) {
|
||||
@NotNull final Processor<PsiElement> processor) {
|
||||
final ImplementationSearcher.BackgroundableImplementationSearcher implementationSearcher =
|
||||
new ImplementationSearcher.BackgroundableImplementationSearcher() {
|
||||
@Override
|
||||
|
||||
+13
-13
@@ -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<ImplementationViewElement> myElements;
|
||||
|
||||
private ImplementationsUpdaterTask(PsiImplementationViewSession session,
|
||||
private ImplementationsUpdaterTask(ImplementationViewSession session,
|
||||
final String caption,
|
||||
boolean includeSelf,
|
||||
ImplementationViewComponent component) {
|
||||
|
||||
@@ -996,6 +996,8 @@
|
||||
<extensionPoint name="retypeFileAssistant" interface="com.intellij.internal.retype.RetypeFileAssistant"/>
|
||||
|
||||
<extensionPoint name="trafficLightRendererContributor" interface="com.intellij.codeInsight.daemon.impl.TrafficLightRendererContributor"/>
|
||||
|
||||
<extensionPoint name="implementationViewSessionFactory" interface="com.intellij.codeInsight.hint.ImplementationViewSessionFactory"/>
|
||||
</extensionPoints>
|
||||
</idea-plugin>
|
||||
|
||||
|
||||
@@ -1184,6 +1184,8 @@
|
||||
<editorNotificationProvider implementation="com.intellij.internal.retype.RetypeEditorNotificationProvider"/>
|
||||
|
||||
<fileBreadcrumbsCollector implementation="com.intellij.xml.breadcrumbs.PsiFileBreadcrumbsCollector" order="last"/>
|
||||
|
||||
<implementationViewSessionFactory implementation="com.intellij.codeInsight.hint.PsiImplementationSessionViewFactory"/>
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user