Problem with scala class
hi,
i am trying to use the following action:
<action id="ScalaCollider.ExecuteInInterpreter"
text="Execute In Interpreter" description="Executes the selected text in the Scala interpreter">
<!-- <keyboard-shortcut first-keystroke="meta BACKSLASH" keymap="$default"/> -->
<add-to-group group-id="GoToCodeGroup" anchor="last"/>
</action>
( side question : how can i get meta + backslash as a keyboard stroke? i tried both meta \ and meta BACKSLASH (java.awt.event.KeyEvent style), neither seem to work )
now the class is ( peeked at the scala plugin's GoToImplicitConversionAction class) :
package de.sciss.idea.actions
import com.intellij.openapi.ui.Messages
import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile
import com.intellij.openapi.actionSystem.{DataKey, LangDataKeys, AnActionEvent, AnAction}
class ExecuteInInterpreterAction extends AnAction( "Execute-In-Interpreter Action" ) {
override def update(e: AnActionEvent): Unit = {
val presentation = e.getPresentation
def enable {
presentation.setEnabled( true )
presentation.setVisible( true )
}
def disable {
presentation.setEnabled( false )
presentation.setVisible( false )
}
try {
val dataContext = e.getDataContext
val file = LangDataKeys.PSI_FILE.getData( dataContext )
file match {
case _: ScalaFile => enable
case _ => disable
}
}
catch {
case e: Exception => disable
}
}
def actionPerformed(e: AnActionEvent): Unit = {
Messages.showMessageDialog( "Welcome to //// ScalaCollider", "ScalaCollider", null )
}
}
As soon as the action is involved, i get the following runtime error:
java.lang.reflect.InvocationTargetException
at apple.awt.CToolkit.invokeAndWait(CToolkit.java:1149)
at apple.awt.CToolkit.invokeAndWait(CToolkit.java:1094)
at com.apple.laf.ScreenMenu.invokeOpenLater(ScreenMenu.java:115)
Caused by: java.lang.IllegalStateException: class with name "de.sciss.idea.actions.ExecuteInInterpreterAction" should be instance of com.intellij.openapi.actionSystem.AnAction
at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.convert(ActionManagerImpl.java:275)
at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.getActionImpl(ActionManagerImpl.java:220)
at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.getAction(ActionManagerImpl.java:213)
at com.intellij.openapi.actionSystem.DefaultActionGroup.unstub(DefaultActionGroup.java:260)
at com.intellij.openapi.actionSystem.DefaultActionGroup.getChildren(DefaultActionGroup.java:239)
at com.intellij.openapi.actionSystem.impl.Utils.expandActionGroup(Utils.java:108)
at com.intellij.openapi.actionSystem.impl.Utils.expandActionGroup(Utils.java:82)
at com.intellij.openapi.actionSystem.impl.Utils.expandActionGroup(Utils.java:139)
at com.intellij.openapi.actionSystem.impl.Utils.expandActionGroup(Utils.java:82)
at com.intellij.openapi.actionSystem.impl.Utils.fillMenu(Utils.java:233)
at com.intellij.openapi.actionSystem.impl.ActionMenu.fillMenu(ActionMenu.java:244)
at com.intellij.openapi.actionSystem.impl.ActionMenu.access$400(ActionMenu.java:42)
at com.intellij.openapi.actionSystem.impl.ActionMenu$MenuListenerImpl.menuSelected(ActionMenu.java:207)
at javax.swing.JMenu.fireMenuSelected(JMenu.java:1028)
at javax.swing.JMenu$MenuChangeListener.stateChanged(JMenu.java:1107)
...
So I don't know what to do heren next? Obviously my class _is_ an instance of AnAction.
?
thanks a lot!
best, -sciss-
Please sign in to leave a comment.
This is actually not a Scala problem. I tried with a Java class instead, the same kind of error occurs! I created this second action using the New -> Action wizard, so I am sure everything in plugin.xml is fine.
java.lang.reflect.InvocationTargetException
at apple.awt.CToolkit.invokeAndWait(CToolkit.java:1149)
at apple.awt.CToolkit.invokeAndWait(CToolkit.java:1094)
at com.apple.laf.ScreenMenu.invokeOpenLater(ScreenMenu.java:115)
Caused by: java.lang.IllegalStateException: class with name "de.sciss.idea.actions.ExecuteREPL" should be instance of com.intellij.openapi.actionSystem.AnAction
at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.convert(ActionManagerImpl.java:275)
With
package de.sciss.idea.actions;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.ui.Messages;
public class ExecuteREPL extends AnAction {
public void actionPerformed(AnActionEvent e) {
Messages.showMessageDialog("Welcome to !! ScalaCollider", "ScalaCollider", null);
}
}
My IDEA SDK is the same as my IDEA 10 installation i am using to develop the plugin, so there can't be any mismatches between the compile time libraries and the runtime library.
I really don't know what's going on here. By the way the constructor is executed, i verified that, so the class is actually instantiated.
Thanks, -sciss-
Hold on, i see another message coming up repeatedly:
java.lang.ClassNotFoundException: gnu.trove.THashSet
?! This may be the actual cause of the problem, so that the error message captured in InvocationTargetException is acutally misleading...?
I had these added to my project
annotations.jar -> /Applications/IntelliJ IDEA 10 CE.app/lib/annotations.jar
extensions.jar -> /Applications/IntelliJ IDEA 10 CE.app/lib/extensions.jar
idea.jar -> /Applications/IntelliJ IDEA 10 CE.app/lib/idea.jar
openapi.jar -> /Applications/IntelliJ IDEA 10 CE.app/lib/openapi.jar
picocontainer.jar -> /Applications/IntelliJ IDEA 10 CE.app/lib/picocontainer.jar
util.jar -> /Applications/IntelliJ IDEA 10 CE.app/lib/util.jar
so that i can compile with sbt. after removing them from dependancies (leaving just IDEA SDK), the problem seems to have gone. doesn't make sense to me because they are exactly the same jars as in the IDEA SDK i set up.....
best, -sciss-
Hello Hanns,
If you add these jars as dependencies of your plugin, you will end up with
two copies of classes in those jars, one loaded with the standard Java classloader
and another with the IDEA plugin classloader.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"