EditorAction implementation issue

I'm trying to implement an EditorAction but whenever the assigned key is pressed, I get the following:

Error during dispatching of java.awt.event.KeyEvent[KEY_PRESSED,keyCode=74,keyText=J,keyChar='j',keyLocation=KEY_LOCATION_STANDARD] on frame0: cannot create class "com.nerdworx.idea.ckm.CKMDown" [Plugin: com.nerdworx.idea.ckm]
com.intellij.diagnostic.PluginException: cannot create class "com.nerdworx.idea.ckm.CKMDown" [Plugin: com.nerdworx.idea.ckm]
 at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.convert(ActionManagerImpl.java:275)
 at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.getActionImpl(ActionManagerImpl.java:228)
 at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.getAction(ActionManagerImpl.java:221)
 at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.updateCurrentContext(IdeKeyEventDispatcher.java:676)
 at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.inInitState(IdeKeyEventDispatcher.java:417)
 at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.java:208)
 at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:479)
 at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:333)
 at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
 at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
 at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
 at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
Caused by: java.lang.NoSuchMethodException: com.nerdworx.idea.ckm.CKMDown.<init>()
 at java.lang.Class.getConstructor0(Class.java:2706)
 at java.lang.Class.getDeclaredConstructor(Class.java:1985)
 at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.convert(ActionManagerImpl.java:250)
 ... 13 more



Obviously, I'm doing something wrong. I have been unable to find any documentation for the plugin api, does this exist?  Help would be appreciated.  Here's the pertinent plugin.xml and source code

      <action id="CKMDown" text="CKMDown">
          <keyboard-shortcut keymap="$default" first-keystroke="J"/>
      </action>


*******************************************************

public class CKMDown extends EditorAction
{
  public CKMDown(EditorActionHandler handler)
  {
    super(new Handler(handler));
  }

  private static class Handler extends EditorActionHandler
  {
    public Handler(EditorActionHandler handler)
    {
      m_handler = handler;
    }

    public void execute(Editor editor,DataContext context)
    {
      int nOffset;
      LogicalPosition pos;

      if (editor != null)
      {
        pos = editor.getCaretModel().getLogicalPosition();
        int nNextLineStart = editor.getDocument().getLineStartOffset(pos.line + 1);
        int nNextLineEnd = editor.getDocument().getLineEndOffset(pos.line + 1);
        nOffset = Math.min(editor.getDocument().getLineStartOffset(pos.line + 1) + pos.column,editor.getDocument().getLineEndOffset(pos.line + 1));

        editor.getCaretModel().moveToOffset(nOffset);
      }
      else
        m_handler.execute(editor,context);
    }

    private EditorActionHandler m_handler;
  }
}
3 comments

Try to create constructor without parameters

0

Ok, that works but that means the default handler is null.  How can I get the default handler in the case I just want the default behavior?   What's the advantage of using an EditorAction vs AnAction?   Thanks!

0

That doesn't mean that default handler is null - you can define no-args ctor and call super(new MyHandler()) as its first instruction.

The benefit of using EditorAction is that it simplifies editor processing - the action is automatically disabled if no editor is available at the current context and the editor is extracted from the environment and provided to EditorActionHandler.

Denis

0

Please sign in to leave a comment.