From 776a71065db576c05dec8e94c6464d8963a1fc6d Mon Sep 17 00:00:00 2001 From: Ivan Migalev Date: Fri, 31 Jan 2025 21:32:02 +0100 Subject: [PATCH] GotoActionModel: extract GroupMapping to a separate class as it's done in 251 #LLM-13353 Fixed GitOrigin-RevId: d57451a4136f898fdf284fd2298b9a3620bf2e13 --- platform/lang-impl/api-dump-unreviewed.txt | 28 ++-- .../ide/util/gotoByName/GotoActionModel.java | 110 +-------------- .../ide/util/gotoByName/GroupMapping.java | 125 ++++++++++++++++++ 3 files changed, 141 insertions(+), 122 deletions(-) create mode 100644 platform/lang-impl/src/com/intellij/ide/util/gotoByName/GroupMapping.java diff --git a/platform/lang-impl/api-dump-unreviewed.txt b/platform/lang-impl/api-dump-unreviewed.txt index 6cdd3686d57f..6366a70d1302 100644 --- a/platform/lang-impl/api-dump-unreviewed.txt +++ b/platform/lang-impl/api-dump-unreviewed.txt @@ -12482,7 +12482,7 @@ f:com.intellij.ide.util.gotoByName.GotoActionItemProvider - com.intellij.ide.util.gotoByName.ChooseByNameWeightedItemProvider - (com.intellij.ide.util.gotoByName.GotoActionModel):V - clearIntentions():V -- s:createActionWrapper(com.intellij.openapi.actionSystem.AnAction,com.intellij.ide.util.gotoByName.GotoActionModel$GroupMapping,com.intellij.ide.util.gotoByName.MatchMode,com.intellij.ide.util.gotoByName.GotoActionModel):com.intellij.ide.util.gotoByName.GotoActionModel$ActionWrapper +- s:createActionWrapper(com.intellij.openapi.actionSystem.AnAction,com.intellij.ide.util.gotoByName.GroupMapping,com.intellij.ide.util.gotoByName.MatchMode,com.intellij.ide.util.gotoByName.GotoActionModel):com.intellij.ide.util.gotoByName.GotoActionModel$ActionWrapper - filterElements(com.intellij.ide.util.gotoByName.ChooseByNameViewModel,java.lang.String,Z,com.intellij.openapi.progress.ProgressIndicator,com.intellij.util.Processor):Z - filterElements(java.lang.String,java.util.function.Predicate):Z - filterElementsWithWeights(com.intellij.ide.util.gotoByName.ChooseByNameViewModel,java.lang.String,Z,com.intellij.openapi.progress.ProgressIndicator,com.intellij.util.Processor):Z @@ -12500,7 +12500,7 @@ f:com.intellij.ide.util.gotoByName.GotoActionModel - getElementName(java.lang.Object):java.lang.String - getElementsByName(java.lang.String,Z,java.lang.String):java.lang.Object[] - getFullName(java.lang.Object):java.lang.String -- getGroupMapping(com.intellij.openapi.actionSystem.AnAction):com.intellij.ide.util.gotoByName.GotoActionModel$GroupMapping +- getGroupMapping(com.intellij.openapi.actionSystem.AnAction):com.intellij.ide.util.gotoByName.GroupMapping - getGroupName(com.intellij.ide.ui.search.OptionDescription):java.lang.String - getHelpId():java.lang.String - getListCellRenderer():javax.swing.ListCellRenderer @@ -12515,12 +12515,12 @@ f:com.intellij.ide.util.gotoByName.GotoActionModel - useMiddleMatching():Z - willOpenEditor():Z c:com.intellij.ide.util.gotoByName.GotoActionModel$ActionWrapper -- (com.intellij.openapi.actionSystem.AnAction,com.intellij.ide.util.gotoByName.GotoActionModel$GroupMapping,com.intellij.ide.util.gotoByName.MatchMode,com.intellij.openapi.actionSystem.Presentation):V +- (com.intellij.openapi.actionSystem.AnAction,com.intellij.ide.util.gotoByName.GroupMapping,com.intellij.ide.util.gotoByName.MatchMode,com.intellij.openapi.actionSystem.Presentation):V - compareWeights(com.intellij.ide.util.gotoByName.GotoActionModel$ActionWrapper):I - equals(java.lang.Object):Z - getAction():com.intellij.openapi.actionSystem.AnAction - getActionText():java.lang.String -- getGroupMapping():com.intellij.ide.util.gotoByName.GotoActionModel$GroupMapping +- getGroupMapping():com.intellij.ide.util.gotoByName.GroupMapping - getGroupName():java.lang.String - getMode():com.intellij.ide.util.gotoByName.MatchMode - getPresentation():com.intellij.openapi.actionSystem.Presentation @@ -12534,16 +12534,6 @@ f:com.intellij.ide.util.gotoByName.GotoActionModel$GotoActionListCellRenderer - (com.intellij.util.Function,Z):V - s:calcHit(com.intellij.ide.ui.search.OptionDescription):java.lang.String - getListCellRendererComponent(javax.swing.JList,java.lang.Object,I,Z,Z):java.awt.Component -f:com.intellij.ide.util.gotoByName.GotoActionModel$GroupMapping -- java.lang.Comparable -- ():V -- (Z):V -- compareTo(com.intellij.ide.util.gotoByName.GotoActionModel$GroupMapping):I -- s:createFromText(java.lang.String,Z):com.intellij.ide.util.gotoByName.GotoActionModel$GroupMapping -- getAllGroupNames():java.util.List -- getBestGroupName():java.lang.String -- getFirstGroup():java.util.List -- updateBeforeShow(com.intellij.openapi.actionSystem.UpdateSession):V c:com.intellij.ide.util.gotoByName.GotoActionModel$MatchedValue - com.intellij.ide.actions.searcheverywhere.MergeableElement - com.intellij.internal.inspector.UiInspectorContextProvider @@ -12654,6 +12644,16 @@ c:com.intellij.ide.util.gotoByName.GotoSymbolModel2 - loadInitialCheckBoxState():Z - saveInitialCheckBoxState(Z):V - willOpenEditor():Z +f:com.intellij.ide.util.gotoByName.GroupMapping +- java.lang.Comparable +- ():V +- (Z):V +- compareTo(com.intellij.ide.util.gotoByName.GroupMapping):I +- s:createFromText(java.lang.String,Z):com.intellij.ide.util.gotoByName.GroupMapping +- getAllGroupNames():java.util.List +- getBestGroupName():java.lang.String +- getFirstGroup():java.util.List +- updateBeforeShow(com.intellij.openapi.actionSystem.UpdateSession):V f:com.intellij.ide.util.gotoByName.LanguageRef - sf:Companion:com.intellij.ide.util.gotoByName.LanguageRef$Companion - (java.lang.String,java.lang.String,javax.swing.Icon):V diff --git a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java index 4acb9bd071e9..e618bb671d52 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java +++ b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java @@ -1,4 +1,4 @@ -// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.ide.util.gotoByName; @@ -55,16 +55,13 @@ import javax.swing.*; import javax.swing.border.Border; import java.awt.*; import java.lang.ref.WeakReference; -import java.util.List; import java.util.*; +import java.util.List; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Supplier; -import java.util.regex.Matcher; -import java.util.regex.Pattern; public final class GotoActionModel implements ChooseByNameModel, Comparator, DumbAware { private static final Logger LOG = Logger.getInstance(GotoActionModel.class); - private static final Pattern INNER_GROUP_WITH_IDS = Pattern.compile("(.*) \\(\\d+\\)"); private static final Icon EMPTY_ICON = EmptyIcon.ICON_16; private final @Nullable Project myProject; @@ -519,109 +516,6 @@ public final class GotoActionModel implements ChooseByNameModel, Comparator { - private final boolean myShowNonPopupGroups; - private final List> myPaths = new ArrayList<>(); - - private @Nullable @ActionText String myBestGroupName; - private boolean myBestNameComputed; - - public GroupMapping() { - this(false); - } - - public GroupMapping(boolean showNonPopupGroups) { - myShowNonPopupGroups = showNonPopupGroups; - } - - public static @NotNull GroupMapping createFromText(@ActionText String text, boolean showGroupText) { - GroupMapping mapping = new GroupMapping(showGroupText); - mapping.addPath(Collections.singletonList(new DefaultActionGroup(text, false))); - return mapping; - } - - private void addPath(@NotNull List path) { - myPaths.add(path); - } - - - @Override - public int compareTo(@NotNull GroupMapping o) { - return Comparing.compare(getFirstGroupName(), o.getFirstGroupName()); - } - - public @ActionText @Nullable String getBestGroupName() { - if (myBestNameComputed) return myBestGroupName; - return getFirstGroupName(); - } - - public @Nullable List getFirstGroup() { - return ContainerUtil.getFirstItem(myPaths); - } - - private @Nls @Nullable String getFirstGroupName() { - List path = getFirstGroup(); - return path != null ? getPathName(path) : null; - } - - public void updateBeforeShow(@NotNull UpdateSession session) { - if (myBestNameComputed) return; - myBestNameComputed = true; - - for (List path : myPaths) { - String name = getActualPathName(path, session); - if (name != null) { - myBestGroupName = name; - return; - } - } - } - - public @NotNull List getAllGroupNames() { - return ContainerUtil.map(myPaths, path -> getPathName(path)); - } - - private @Nls @Nullable String getPathName(@NotNull List path) { - String name = ""; - for (ActionGroup group : path) { - name = appendGroupName(name, group, group.getTemplatePresentation()); - } - return StringUtil.nullize(name); - } - - private @Nls @Nullable String getActualPathName(@NotNull List path, @NotNull UpdateSession session) { - String name = ""; - for (ActionGroup group : path) { - Presentation presentation = session.presentation(group); - if (!presentation.isVisible()) return null; - name = appendGroupName(name, group, presentation); - } - return StringUtil.nullize(name); - } - - private @Nls @NotNull String appendGroupName(@NotNull @Nls String prefix, @NotNull ActionGroup group, @NotNull Presentation presentation) { - if (group.isPopup() || myShowNonPopupGroups) { - String groupName = getActionGroupName(presentation); - if (!StringUtil.isEmptyOrSpaces(groupName)) { - return prefix.isEmpty() - ? groupName - : prefix + " | " + groupName; - } - } - return prefix; - } - - private static @ActionText @Nullable String getActionGroupName(@NotNull Presentation presentation) { - String text = presentation.getText(); - if (text == null) return null; - - Matcher matcher = INNER_GROUP_WITH_IDS.matcher(text); - if (matcher.matches()) return matcher.group(1); - - return text; - } - } - public static class ActionWrapper { private final @NotNull AnAction myAction; private final @NotNull MatchMode myMode; diff --git a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GroupMapping.java b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GroupMapping.java new file mode 100644 index 000000000000..a25dbb4a1c42 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GroupMapping.java @@ -0,0 +1,125 @@ +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.ide.util.gotoByName; + +import com.intellij.openapi.actionSystem.ActionGroup; +import com.intellij.openapi.actionSystem.DefaultActionGroup; +import com.intellij.openapi.actionSystem.Presentation; +import com.intellij.openapi.actionSystem.UpdateSession; +import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.util.NlsActions; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.Nls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public final class GroupMapping implements Comparable { + private static final Pattern INNER_GROUP_WITH_IDS = Pattern.compile("(.*) \\(\\d+\\)"); + + private final boolean myShowNonPopupGroups; + private final List> myPaths = new ArrayList<>(); + + private @Nullable @NlsActions.ActionText String myBestGroupName; + private boolean myBestNameComputed; + + public GroupMapping() { + this(false); + } + + public GroupMapping(boolean showNonPopupGroups) { + myShowNonPopupGroups = showNonPopupGroups; + } + + public static @NotNull GroupMapping createFromText(@NlsActions.ActionText String text, boolean showGroupText) { + GroupMapping mapping = new GroupMapping(showGroupText); + mapping.addPath(Collections.singletonList(new DefaultActionGroup(text, false))); + return mapping; + } + + void addPath(@NotNull List path) { + myPaths.add(path); + } + + + @Override + public int compareTo(@NotNull GroupMapping o) { + return Comparing.compare(getFirstGroupName(), o.getFirstGroupName()); + } + + public @NlsActions.ActionText @Nullable String getBestGroupName() { + if (myBestNameComputed) return myBestGroupName; + return getFirstGroupName(); + } + + public @Nullable List getFirstGroup() { + return ContainerUtil.getFirstItem(myPaths); + } + + private @Nls @Nullable String getFirstGroupName() { + List path = getFirstGroup(); + return path != null ? getPathName(path) : null; + } + + public void updateBeforeShow(@NotNull UpdateSession session) { + if (myBestNameComputed) return; + myBestNameComputed = true; + + for (List path : myPaths) { + String name = getActualPathName(path, session); + if (name != null) { + myBestGroupName = name; + return; + } + } + } + + public @NotNull List getAllGroupNames() { + return ContainerUtil.map(myPaths, path -> getPathName(path)); + } + + private @Nls @Nullable String getPathName(@NotNull List path) { + String name = ""; + for (ActionGroup group : path) { + name = appendGroupName(name, group, group.getTemplatePresentation()); + } + return StringUtil.nullize(name); + } + + private @Nls @Nullable String getActualPathName(@NotNull List path, @NotNull UpdateSession session) { + String name = ""; + for (ActionGroup group : path) { + Presentation presentation = session.presentation(group); + if (!presentation.isVisible()) return null; + name = appendGroupName(name, group, presentation); + } + return StringUtil.nullize(name); + } + + private @Nls @NotNull String appendGroupName(@NotNull @Nls String prefix, @NotNull ActionGroup group, @NotNull Presentation presentation) { + if (group.isPopup() || myShowNonPopupGroups) { + String groupName = getActionGroupName(presentation); + if (!StringUtil.isEmptyOrSpaces(groupName)) { + return prefix.isEmpty() + ? groupName + : prefix + " | " + groupName; + } + } + return prefix; + } + + private static @NlsActions.ActionText @Nullable String getActionGroupName(@NotNull Presentation presentation) { + String text = presentation.getText(); + if (text == null) return null; + + Matcher matcher = INNER_GROUP_WITH_IDS.matcher(text); + if (matcher.matches()) return matcher.group(1); + + return text; + } +}