diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/JavaLineMarkerProvider.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/JavaLineMarkerProvider.java index 732a60555e23..4c705206a0a1 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/JavaLineMarkerProvider.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/JavaLineMarkerProvider.java @@ -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 info = new LineMarkerInfo(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 diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/MarkerType.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/MarkerType.java index 5e0c0ecf95b2..b479b7a258e0 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/MarkerType.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/MarkerType.java @@ -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() { + + private final GutterIconNavigationHandler handler; + private final Function myTooltip; + + public MarkerType(@NotNull Function tooltip, @NotNull final LineMarkerNavigator navigator, + @Nullable Function actionText, @Nullable String actionId) { + myTooltip = tooltip; + handler = new GutterIconNavigationHandler() { + @Override + public void navigate(MouseEvent e, PsiElement elt) { + navigator.browse(e, elt); + } + }; + } + + public MarkerType(@NotNull Function tooltip, @NotNull final LineMarkerNavigator navigator) { + this(tooltip, navigator, null, null); + } + + @NotNull + public GutterIconNavigationHandler getNavigationHandler() { + return handler; + } + + @NotNull + public Function getTooltip() { + return myTooltip; + } + + static final MarkerType OVERRIDING_METHOD = new MarkerType(new NullableFunction() { @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("Go to overriding method(s)")); + }, new ConstantFunction("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() { + static final MarkerType OVERRIDDEN_METHOD = new MarkerType(new NullableFunction() { @Override public String fun(PsiElement element) { PsiElement parent = element.getParent(); @@ -132,7 +162,7 @@ public class MarkerType { navigateToOverriddenMethod(e, (PsiMethod)parent); } - }, new ConstantFunction("Go to overriding methods")); + }, new ConstantFunction("Go to overridden method"), IdeActions.ACTION_GOTO_IMPLEMENTATION); public static String getOverriddenMethodTooltip(final PsiMethod method) { PsiElementProcessor.CollectElementsWithLimit processor = new PsiElementProcessor.CollectElementsWithLimit(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() { + private static final String SEARCHING_FOR_OVERRIDDEN_METHODS = "Searching for Overridden Methods"; + static final MarkerType SUBCLASSED_CLASS = new MarkerType(new NullableFunction() { @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 processor = new PsiElementProcessor.CollectElementsWithLimit(5, new THashSet()); @@ -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 handler; - private final Function myTooltip; - private final Function myNavigateActionText; - - public MarkerType(@NotNull Function tooltip, @NotNull final LineMarkerNavigator navigator, - @Nullable Function actionText) { - myTooltip = tooltip; - handler = new GutterIconNavigationHandler() { - @Override - public void navigate(MouseEvent e, PsiElement elt) { - navigator.browse(e, elt); - } - }; - myNavigateActionText = actionText; - } - - public MarkerType(@NotNull Function tooltip, @NotNull final LineMarkerNavigator navigator) { - this(tooltip, navigator, null); - } - - @NotNull - public GutterIconNavigationHandler getNavigationHandler() { - return handler; - } - - @NotNull - public Function getTooltip() { - return myTooltip; - } - - public Function getNavigateActionText() { - return myNavigateActionText; - } - private static class SubclassUpdater extends ListBackgroundUpdaterTask { private final PsiClass myClass; private final PsiClassOrFunctionalExpressionListCellRenderer myRenderer; diff --git a/platform/lang-api/src/com/intellij/codeInsight/daemon/LineMarkerInfo.java b/platform/lang-api/src/com/intellij/codeInsight/daemon/LineMarkerInfo.java index b558bdbfb49a..2b2d176a9ab3 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/daemon/LineMarkerInfo.java +++ b/platform/lang-api/src/com/intellij/codeInsight/daemon/LineMarkerInfo.java @@ -17,7 +17,6 @@ package com.intellij.codeInsight.daemon; import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.editor.markup.GutterIconRenderer; import com.intellij.openapi.editor.markup.RangeHighlighter; import com.intellij.openapi.editor.markup.SeparatorPlacement; @@ -31,7 +30,6 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; -import java.awt.event.MouseEvent; import java.lang.ref.WeakReference; public class LineMarkerInfo { @@ -45,7 +43,7 @@ public class LineMarkerInfo { public final int updatePass; @Nullable private final Function myTooltipProvider; - @Nullable private Function myNavigateActionTextProvider; + private AnAction myNavigateAction = new NavigateAction(this); @NotNull private final GutterIconRenderer.Alignment myIconAlignment; @Nullable private final GutterIconNavigationHandler myNavigationHandler; @@ -112,31 +110,8 @@ public class LineMarkerInfo { return elementRef.get(); } - public void setNavigateActionTextProvider(@Nullable Function navigateActionTextProvider) { - myNavigateActionTextProvider = navigateActionTextProvider; - } - - private class NavigateAction extends AnAction { - @Override - public void actionPerformed(AnActionEvent e) { - if (myNavigationHandler != null) { - MouseEvent mouseEvent = (MouseEvent)e.getInputEvent(); - T element = getElement(); - if (element == null || !element.isValid()) return; - - myNavigationHandler.navigate(mouseEvent, element); - } - } - - @Override - public void update(AnActionEvent e) { - if (myNavigateActionTextProvider == null) return; - T element = getElement(); - if (element != null && element.isValid()) { - String text = myNavigateActionTextProvider.fun(element); - e.getPresentation().setText(text); - } - } + public void setNavigateAction(AnAction navigateAction) { + myNavigateAction = navigateAction; } @Nullable @@ -163,7 +138,7 @@ public class LineMarkerInfo { @Override public AnAction getClickAction() { - return myInfo.new NavigateAction(); + return myInfo.myNavigateAction; } @Override diff --git a/platform/lang-api/src/com/intellij/codeInsight/daemon/NavigateAction.java b/platform/lang-api/src/com/intellij/codeInsight/daemon/NavigateAction.java new file mode 100644 index 000000000000..90a06ae7b13d --- /dev/null +++ b/platform/lang-api/src/com/intellij/codeInsight/daemon/NavigateAction.java @@ -0,0 +1,61 @@ +/* + * Copyright 2000-2015 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.daemon; + +import com.intellij.openapi.actionSystem.ActionManager; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.ShortcutSet; +import com.intellij.psi.PsiElement; + +import java.awt.event.MouseEvent; + +/** + * @author Dmitry Avdeev + */ +public class NavigateAction extends AnAction { + private LineMarkerInfo myInfo; + + public NavigateAction(String text, + LineMarkerInfo info, + String originalActionId) { + super(text); + myInfo = info; + ShortcutSet set = ActionManager.getInstance().getAction(originalActionId).getShortcutSet(); + setShortcutSet(set); + } + + public NavigateAction(LineMarkerInfo info) { + myInfo = info; + } + + @Override + public void actionPerformed(AnActionEvent e) { + if (myInfo.getNavigationHandler() != null) { + MouseEvent mouseEvent = (MouseEvent)e.getInputEvent(); + T element = myInfo.getElement(); + if (element == null || !element.isValid()) return; + + myInfo.getNavigationHandler().navigate(mouseEvent, element); + } + } + + public static LineMarkerInfo setNavigateAction(LineMarkerInfo info, String text, String originalActionId) { + NavigateAction action = new NavigateAction(text, info, originalActionId); + info.setNavigateAction(action); + return info; + } +}