NavigateAction

This commit is contained in:
Dmitry Avdeev
2015-06-08 14:22:09 +03:00
parent 150b7e1a82
commit 4b79683e7c
4 changed files with 111 additions and 79 deletions
@@ -16,11 +16,9 @@
package com.intellij.codeInsight.daemon.impl;
import com.intellij.codeHighlighting.Pass;
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzerSettings;
import com.intellij.codeInsight.daemon.LineMarkerInfo;
import com.intellij.codeInsight.daemon.LineMarkerProvider;
import com.intellij.codeInsight.daemon.MergeableLineMarkerInfo;
import com.intellij.codeInsight.daemon.*;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.colors.CodeInsightColors;
@@ -75,7 +73,8 @@ public class JavaLineMarkerProvider implements LineMarkerProvider {
final Icon icon = overrides ? AllIcons.Gutter.OverridingMethod : AllIcons.Gutter.ImplementingMethod;
final MarkerType type = MarkerType.OVERRIDING_METHOD;
return new ArrowUpLineMarkerInfo(element, icon, type);
ArrowUpLineMarkerInfo info = new ArrowUpLineMarkerInfo(element, icon, type);
return NavigateAction.setNavigateAction(info, "Go to super method", "GotoSuperMethod");
}
}
@@ -84,7 +83,8 @@ public class JavaLineMarkerProvider implements LineMarkerProvider {
if (interfaceMethod != null && firstChild != null) {
final Icon icon = AllIcons.Gutter.ImplementingMethod;
final MarkerType type = MarkerType.OVERRIDING_METHOD;
return new ArrowUpLineMarkerInfo(firstChild, icon, type);
ArrowUpLineMarkerInfo info = new ArrowUpLineMarkerInfo(firstChild, icon, type);
return NavigateAction.setNavigateAction(info, "Go to super method", "GotoSuperMethod");
}
if (myDaemonSettings.SHOW_METHOD_SEPARATORS && firstChild == null) {
@@ -183,6 +183,7 @@ public class JavaLineMarkerProvider implements LineMarkerProvider {
icon, Pass.UPDATE_OVERRIDEN_MARKERS, type.getTooltip(),
type.getNavigationHandler(),
GutterIconRenderer.Alignment.RIGHT);
NavigateAction.setNavigateAction(info, aClass.isInterface() ? "Go to implementation(s)" : "Go to subclass(es)", IdeActions.ACTION_GOTO_IMPLEMENTATION);
result.add(info);
}
}
@@ -243,12 +244,12 @@ public class JavaLineMarkerProvider implements LineMarkerProvider {
}
}
if (range == null) range = method;
final MarkerType type = MarkerType.OVERRIDEN_METHOD;
final MarkerType type = MarkerType.OVERRIDDEN_METHOD;
LineMarkerInfo<PsiElement> info = new LineMarkerInfo<PsiElement>(range, range.getTextRange(),
icon, Pass.UPDATE_OVERRIDEN_MARKERS, type.getTooltip(),
type.getNavigationHandler(),
GutterIconRenderer.Alignment.RIGHT);
info.setNavigateActionTextProvider(type.getNavigateActionText());
NavigateAction.setNavigateAction(info, overrides ? "Go to overriding methods" : "Go to implementation(s)", IdeActions.ACTION_GOTO_IMPLEMENTATION);
result.add(info);
}
}
@@ -257,7 +258,6 @@ public class JavaLineMarkerProvider implements LineMarkerProvider {
private ArrowUpLineMarkerInfo(@NotNull PsiElement element, Icon icon, @NotNull MarkerType markerType) {
super(element, element.getTextRange(), icon, Pass.UPDATE_ALL, markerType.getTooltip(),
markerType.getNavigationHandler(), GutterIconRenderer.Alignment.LEFT);
setNavigateActionTextProvider(markerType.getNavigateActionText());
}
@Override
@@ -24,6 +24,7 @@ import com.intellij.codeInsight.daemon.DaemonBundle;
import com.intellij.codeInsight.daemon.GutterIconNavigationHandler;
import com.intellij.codeInsight.navigation.ListBackgroundUpdaterTask;
import com.intellij.ide.util.*;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
@@ -49,7 +50,36 @@ import java.util.Arrays;
import java.util.Comparator;
public class MarkerType {
public static final MarkerType OVERRIDING_METHOD = new MarkerType(new NullableFunction<PsiElement, String>() {
private final GutterIconNavigationHandler<PsiElement> handler;
private final Function<PsiElement, String> myTooltip;
public MarkerType(@NotNull Function<PsiElement, String> tooltip, @NotNull final LineMarkerNavigator navigator,
@Nullable Function<PsiElement, String> actionText, @Nullable String actionId) {
myTooltip = tooltip;
handler = new GutterIconNavigationHandler<PsiElement>() {
@Override
public void navigate(MouseEvent e, PsiElement elt) {
navigator.browse(e, elt);
}
};
}
public MarkerType(@NotNull Function<PsiElement, String> tooltip, @NotNull final LineMarkerNavigator navigator) {
this(tooltip, navigator, null, null);
}
@NotNull
public GutterIconNavigationHandler<PsiElement> getNavigationHandler() {
return handler;
}
@NotNull
public Function<PsiElement, String> getTooltip() {
return myTooltip;
}
static final MarkerType OVERRIDING_METHOD = new MarkerType(new NullableFunction<PsiElement, String>() {
@Override
public String fun(PsiElement element) {
PsiElement parent = getParentMethod(element);
@@ -66,7 +96,7 @@ public class MarkerType {
PsiMethod method = (PsiMethod)parent;
navigateToOverridingMethod(e, method, method != element.getParent());
}
}, new ConstantFunction<PsiElement, String>("Go to overriding method(s)"));
}, new ConstantFunction<PsiElement, String>("Go to overriding method(s)"), IdeActions.ACTION_GOTO_IMPLEMENTATION);
@Nullable
public static String calculateOverridingMethodTooltip(PsiMethod method, boolean acceptSelf) {
@@ -115,7 +145,7 @@ public class MarkerType {
}
public static final String SEARCHING_FOR_OVERRIDING_METHODS = "Searching for Overriding Methods";
public static final MarkerType OVERRIDEN_METHOD = new MarkerType(new NullableFunction<PsiElement, String>() {
static final MarkerType OVERRIDDEN_METHOD = new MarkerType(new NullableFunction<PsiElement, String>() {
@Override
public String fun(PsiElement element) {
PsiElement parent = element.getParent();
@@ -132,7 +162,7 @@ public class MarkerType {
navigateToOverriddenMethod(e, (PsiMethod)parent);
}
}, new ConstantFunction<PsiElement, String>("Go to overriding methods"));
}, new ConstantFunction<PsiElement, String>("Go to overridden method"), IdeActions.ACTION_GOTO_IMPLEMENTATION);
public static String getOverriddenMethodTooltip(final PsiMethod method) {
PsiElementProcessor.CollectElementsWithLimit<PsiMethod> processor = new PsiElementProcessor.CollectElementsWithLimit<PsiMethod>(5);
@@ -202,8 +232,8 @@ public class MarkerType {
PsiElementListNavigator.openTargets(e, overridings, methodsUpdater.getCaption(overridings.length), "Overriding methods of " + method.getName(), renderer, methodsUpdater);
}
public static final String SEARCHING_FOR_OVERRIDDEN_METHODS = "Searching for Overridden Methods";
public static final MarkerType SUBCLASSED_CLASS = new MarkerType(new NullableFunction<PsiElement, String>() {
private static final String SEARCHING_FOR_OVERRIDDEN_METHODS = "Searching for Overridden Methods";
static final MarkerType SUBCLASSED_CLASS = new MarkerType(new NullableFunction<PsiElement, String>() {
@Override
public String fun(PsiElement element) {
PsiElement parent = element.getParent();
@@ -228,7 +258,7 @@ public class MarkerType {
final PsiClass aClass = (PsiClass)parent;
return aClass.isInterface() ? "Go to implementation(s)" : "Go to subclass(es)";
}
});
}, IdeActions.ACTION_GOTO_IMPLEMENTATION);
public static String getSubclassedClassTooltip(PsiClass aClass) {
PsiElementProcessor.CollectElementsWithLimit<PsiClass> processor = new PsiElementProcessor.CollectElementsWithLimit<PsiClass>(5, new THashSet<PsiClass>());
@@ -290,40 +320,6 @@ public class MarkerType {
PsiElementListNavigator.openTargets(e, inheritors, subclassUpdater.getCaption(inheritors.length), CodeInsightBundle.message("goto.implementation.findUsages.title", aClass.getName()), renderer, subclassUpdater);
}
private final GutterIconNavigationHandler<PsiElement> handler;
private final Function<PsiElement, String> myTooltip;
private final Function<PsiElement, String> myNavigateActionText;
public MarkerType(@NotNull Function<PsiElement, String> tooltip, @NotNull final LineMarkerNavigator navigator,
@Nullable Function<PsiElement, String> actionText) {
myTooltip = tooltip;
handler = new GutterIconNavigationHandler<PsiElement>() {
@Override
public void navigate(MouseEvent e, PsiElement elt) {
navigator.browse(e, elt);
}
};
myNavigateActionText = actionText;
}
public MarkerType(@NotNull Function<PsiElement, String> tooltip, @NotNull final LineMarkerNavigator navigator) {
this(tooltip, navigator, null);
}
@NotNull
public GutterIconNavigationHandler<PsiElement> getNavigationHandler() {
return handler;
}
@NotNull
public Function<PsiElement, String> getTooltip() {
return myTooltip;
}
public Function<PsiElement, String> getNavigateActionText() {
return myNavigateActionText;
}
private static class SubclassUpdater extends ListBackgroundUpdaterTask {
private final PsiClass myClass;
private final PsiClassOrFunctionalExpressionListCellRenderer myRenderer;