diff --git a/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnAction.java b/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnAction.java index adf8567b1750..1d1540910539 100644 --- a/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnAction.java +++ b/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnAction.java @@ -28,7 +28,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import java.util.ArrayList; import java.util.List; /** @@ -145,7 +144,8 @@ public abstract class AnAction implements PossiblyDumbAware { public final void registerCustomShortcutSet(@NotNull ShortcutSet shortcutSet, @Nullable JComponent component){ myShortcutSet = shortcutSet; if (component != null){ - @SuppressWarnings("unchecked") List actionList = (ArrayList)component.getClientProperty(ourClientProperty); + @SuppressWarnings("unchecked") + List actionList = (List)component.getClientProperty(ourClientProperty); if (actionList == null){ actionList = new SmartList(); component.putClientProperty(ourClientProperty, actionList); @@ -172,7 +172,8 @@ public abstract class AnAction implements PossiblyDumbAware { public final void unregisterCustomShortcutSet(JComponent component){ if (component != null){ - @SuppressWarnings("unchecked") ArrayList actionList = (ArrayList)component.getClientProperty(ourClientProperty); + @SuppressWarnings("unchecked") + List actionList = (List)component.getClientProperty(ourClientProperty); if (actionList != null){ actionList.remove(this); } diff --git a/platform/platform-api/src/com/intellij/openapi/actionSystem/EmptyAction.java b/platform/platform-api/src/com/intellij/openapi/actionSystem/EmptyAction.java index 4ae67c9da5d7..9e53c35f7cac 100644 --- a/platform/platform-api/src/com/intellij/openapi/actionSystem/EmptyAction.java +++ b/platform/platform-api/src/com/intellij/openapi/actionSystem/EmptyAction.java @@ -15,11 +15,11 @@ */ package com.intellij.openapi.actionSystem; +import com.intellij.openapi.actionSystem.ex.ActionUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import java.util.ArrayList; /** * This class purpose is to reserve action-id in a plugin.xml so the action appears in Keymap. @@ -74,13 +74,8 @@ public final class EmptyAction extends AnAction { } public static void registerActionShortcuts(JComponent component, final JComponent fromComponent) { - @SuppressWarnings("unchecked") - final ArrayList actionList = - (ArrayList)fromComponent.getClientProperty(ourClientProperty); - if (actionList != null) { - for (AnAction anAction : actionList) { - anAction.registerCustomShortcutSet(anAction.getShortcutSet(), component); - } + for (AnAction anAction : ActionUtil.getActions(fromComponent)) { + anAction.registerCustomShortcutSet(anAction.getShortcutSet(), component); } } diff --git a/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ActionUtil.java b/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ActionUtil.java index 8132f9e65990..e0dc548fd452 100644 --- a/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ActionUtil.java +++ b/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ActionUtil.java @@ -27,7 +27,9 @@ import com.intellij.openapi.util.text.StringUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import javax.swing.*; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class ActionUtil { @@ -166,5 +168,10 @@ public class ActionUtil { } } - + @NotNull + public static List getActions(@NotNull JComponent component) { + Object property = component.getClientProperty(AnAction.ourClientProperty); + //noinspection unchecked + return property == null ? Collections.emptyList() : (List)property; + } } diff --git a/platform/platform-impl/src/com/intellij/openapi/keymap/impl/IdeKeyEventDispatcher.java b/platform/platform-impl/src/com/intellij/openapi/keymap/impl/IdeKeyEventDispatcher.java index 77e55ea28d26..817cdaa5e458 100644 --- a/platform/platform-impl/src/com/intellij/openapi/keymap/impl/IdeKeyEventDispatcher.java +++ b/platform/platform-impl/src/com/intellij/openapi/keymap/impl/IdeKeyEventDispatcher.java @@ -651,8 +651,8 @@ public final class IdeKeyEventDispatcher implements Disposable { if (!(component instanceof JComponent)) { continue; } - ArrayList listOfActions = (ArrayList)((JComponent)component).getClientProperty(AnAction.ourClientProperty); - if (listOfActions == null) { + List listOfActions = ActionUtil.getActions((JComponent)component); + if (listOfActions.isEmpty()) { continue; } for (Object listOfAction : listOfActions) { diff --git a/platform/platform-impl/src/com/intellij/openapi/keymap/impl/IdeMouseEventDispatcher.java b/platform/platform-impl/src/com/intellij/openapi/keymap/impl/IdeMouseEventDispatcher.java index b8095397e016..94f72f6da840 100644 --- a/platform/platform-impl/src/com/intellij/openapi/keymap/impl/IdeMouseEventDispatcher.java +++ b/platform/platform-impl/src/com/intellij/openapi/keymap/impl/IdeMouseEventDispatcher.java @@ -19,6 +19,7 @@ import com.intellij.featureStatistics.FeatureUsageTracker; import com.intellij.ide.DataManager; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.actionSystem.ex.ActionManagerEx; +import com.intellij.openapi.actionSystem.ex.ActionUtil; import com.intellij.openapi.actionSystem.impl.PresentationFactory; import com.intellij.openapi.keymap.Keymap; import com.intellij.openapi.keymap.KeymapManager; @@ -78,21 +79,16 @@ public final class IdeMouseEventDispatcher { // here we try to find "local" shortcuts if (component instanceof JComponent) { - @SuppressWarnings("unchecked") - final ArrayList listOfActions = (ArrayList)((JComponent)component).getClientProperty(AnAction.ourClientProperty); - if (listOfActions != null) { - for (AnAction action : listOfActions) { - final Shortcut[] shortcuts = action.getShortcutSet().getShortcuts(); - for (Shortcut shortcut : shortcuts) { - if (mouseShortcut.equals(shortcut) && !myActions.contains(action)) { - myActions.add(action); - } + for (AnAction action : ActionUtil.getActions((JComponent)component)) { + for (Shortcut shortcut : action.getShortcutSet().getShortcuts()) { + if (mouseShortcut.equals(shortcut) && !myActions.contains(action)) { + myActions.add(action); } } - // once we've found a proper local shortcut(s), we exit - if (! myActions.isEmpty()) { - return; - } + } + // once we've found a proper local shortcut(s), we exit + if (!myActions.isEmpty()) { + return; } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTrackerDrawing.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTrackerDrawing.java index 0f941a3a9c21..24884b4a101c 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTrackerDrawing.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTrackerDrawing.java @@ -18,6 +18,7 @@ package com.intellij.openapi.vcs.ex; import com.intellij.codeInsight.hint.EditorFragmentComponent; import com.intellij.codeInsight.hint.HintManagerImpl; import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.actionSystem.ex.ActionUtil; import com.intellij.openapi.diff.DiffColors; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; @@ -165,9 +166,6 @@ public class LineStatusTrackerDrawing { group.add(new ShowLineStatusRangeDiffAction(tracker, range, editor)); group.add(new CopyLineStatusRangeAction(tracker, range)); - @SuppressWarnings("unchecked") - final List actionList = (List)editorComponent.getClientProperty(AnAction.ourClientProperty); - final JComponent toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.FILEHISTORY_VIEW_TOOLBAR, group, true).getComponent(); final Color background = ((EditorEx)editor).getBackgroundColor(); @@ -218,6 +216,7 @@ public class LineStatusTrackerDrawing { EditorFactory.getInstance().releaseEditor(uEditor); } + final List actionList = ActionUtil.getActions(editorComponent); final LightweightHint lightweightHint = new LightweightHint(component); HintListener closeListener = new HintListener() { public void hintHidden(final EventObject event) {