IDEA-144069 DevKit: <action> "use-shortcut-of" support
authorYann Cébron <yann.cebron@jetbrains.com>
Mon, 24 Aug 2015 11:08:49 +0000 (13:08 +0200)
committerYann Cébron <yann.cebron@jetbrains.com>
Mon, 24 Aug 2015 11:08:49 +0000 (13:08 +0200)
plugins/devkit/src/dom/Action.java
plugins/devkit/src/dom/impl/ActionOrGroupResolveConverter.java
plugins/devkit/testData/codeInsight/ActionHighlighting.xml

index 18710077852cc74b888fd68fe36089cfd1be5f1b..34b6a25585a64f3624776deea58ca8555bd79068 100644 (file)
@@ -22,6 +22,7 @@ package org.jetbrains.idea.devkit.dom;
 import com.intellij.psi.PsiClass;
 import com.intellij.util.xml.*;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.idea.devkit.dom.impl.ActionOrGroupResolveConverter;
 import org.jetbrains.idea.devkit.dom.impl.PluginPsiClassConverter;
 
 import java.util.List;
@@ -163,7 +164,8 @@ public interface Action extends ActionOrGroup {
        AddToGroup addAddToGroup();
 
         @NotNull
-        GenericAttributeValue<String> getUseShortcutOf();
+       @Convert(ActionOrGroupResolveConverter.OnlyActions.class)
+        GenericAttributeValue<ActionOrGroup> getUseShortcutOf();
 
         @NotNull
         GenericAttributeValue<String> getKeymap();
index c86d11cda5ee73034f67ad51bde2792123eb8ddf..9c2c2286752fa6e12344733920ff8448f26ad4a0 100644 (file)
@@ -48,7 +48,9 @@ public class ActionOrGroupResolveConverter extends ResolvingConverter<ActionOrGr
     PairProcessor<String, ActionOrGroup> collectProcessor = new PairProcessor<String, ActionOrGroup>() {
       @Override
       public boolean process(String s, ActionOrGroup actionOrGroup) {
-        variants.add(actionOrGroup);
+        if (isRelevant(actionOrGroup)) {
+          variants.add(actionOrGroup);
+        }
         return true;
       }
     };
@@ -65,7 +67,8 @@ public class ActionOrGroupResolveConverter extends ResolvingConverter<ActionOrGr
     PairProcessor<String, ActionOrGroup> findProcessor = new PairProcessor<String, ActionOrGroup>() {
       @Override
       public boolean process(String s, ActionOrGroup actionOrGroup) {
-        if (Comparing.strEqual(value, s)) {
+        if (isRelevant(actionOrGroup) &&
+            Comparing.strEqual(value, s)) {
           result[0] = actionOrGroup;
           return false;
         }
@@ -78,8 +81,8 @@ public class ActionOrGroupResolveConverter extends ResolvingConverter<ActionOrGr
 
   @Nullable
   @Override
-  public String toString(@Nullable ActionOrGroup group, ConvertContext context) {
-    return group == null ? null : getName(group);
+  public String toString(@Nullable ActionOrGroup actionGroup, ConvertContext context) {
+    return actionGroup == null ? null : getName(actionGroup);
   }
 
   @Override
@@ -113,6 +116,22 @@ public class ActionOrGroupResolveConverter extends ResolvingConverter<ActionOrGr
     return super.createLookupElement(actionOrGroup);
   }
 
+  protected boolean isRelevant(ActionOrGroup actionOrGroup) {
+    return true;
+  }
+
+  public static class OnlyActions extends ActionOrGroupResolveConverter {
+    @Override
+    protected boolean isRelevant(ActionOrGroup actionOrGroup) {
+      return actionOrGroup instanceof Action;
+    }
+
+    @Override
+    public String getErrorMessage(@Nullable String s, ConvertContext context) {
+      return "Cannot resolve action '" + s + "'";
+    }
+  }
+
   private static boolean processActionOrGroup(ConvertContext context, final PairProcessor<String, ActionOrGroup> processor) {
     final Project project = context.getProject();
 
index d2f1d704b847a43483e2ea2a14b41dc0ca34bbeb..c2ae8874cda67c2ebb28072fbd9eef659d2d877e 100644 (file)
     <action id=<error descr="Value must not be empty">""</error> class="foo.bar.BarAction"/>
     <action id="invalidClass" class="<error descr="'java.lang.String' is not assignable to 'com.intellij.openapi.actionSystem.AnAction'">java.lang.String</error>" />
 
+    <action id="withUseShortcutOf" class="foo.bar.BarAction" use-shortcut-of="myAction"/>
+    <action id="withUseShortcutOfGroupInvalid" class="foo.bar.BarAction" use-shortcut-of="<error descr="Cannot resolve action 'myGroup'">myGroup</error>"/>
+    <action id="withUseShortcutOfInvalid" class="foo.bar.BarAction" use-shortcut-of="<error descr="Cannot resolve action 'INVALID_VALUE'">INVALID_VALUE</error>"/>
+
     <reference id="myGroup"/>
     <reference id="myAction"/>
     <reference id="myRecursiveGroup"/>