This page is no longer maintained — Please continue to the home page at www.scala-lang.org

running/debuging compiler plugin from Eclipse

16 replies
Thomas Pawlitzki
Joined: 2009-01-07,
User offline. Last seen 42 years 45 weeks ago.

Hello NG,

for testing purpose I want to write a scala compiler plugin [1]. As I
am usually use Eclipse as IDE so was glad to see that there exists a
plugin for Scala.

But I have difficulties by to compile a scala project by using my
compiler plugin. I have found no possibility to pass the -Xplugin
option to the compiler. In the project preferences I found Scala
Compiler Preferences where i can define a Scala Plugin Directory. But
this would requires AFAIK to jar my compiler plugin. But then I can't
debug it.

Is there a possibility to run my compiler plugin directly from my
Eclipse project (by using a special launch configuration, etc.)?

Thanks in advance!

Cheers,
Thomas

[1] http://www.scala-lang.org/node/140

milessabin
Joined: 2008-08-11,
User offline. Last seen 33 weeks 3 days ago.
Re: running/debuging compiler plugin from Eclipse

On Wed, Jan 7, 2009 at 10:22 AM, Thomas Pawlitzki
wrote:
> Is there a possibility to run my compiler plugin directly from my
> Eclipse project (by using a special launch configuration, etc.)?

Unfortunately there's no easy way to do this at the moment ... it can
be done, but it'd be at least as easy to use the command line tools to
build test projects for your (compiler) plugin.

Patches to add support for additional compiler options to the Eclipse
plugin would be very welcome however ... I you decide to take a crack
at let me know and I'll give you all the help I can.

Cheers,

Miles

Thomas Pawlitzki
Joined: 2009-01-07,
User offline. Last seen 42 years 45 weeks ago.
Re: running/debuging compiler plugin from Eclipse

Hallo Miles

thank you for your reply.

> Unfortunately there's no easy way to do this at the moment ... it can
> be done, but it'd be at least as easy to use the command line tools to
> build test projects for your (compiler) plugin.

How can this be done? I would appreciate it very much to debug my
compiler plugin. During a previous compiler extension I experienced
this as extremly useful feature and would miss this feature very much.

> Patches to add support for additional compiler options to the Eclipse
> plugin would be very welcome however ... I you decide to take a crack
> at let me know and I'll give you all the help I can.

After looking in the compiler options in greater detail I doubt if
this is only an issue of the Eclipse Plugin. In the scala doc on
http://scala-lang.org I found only the possibility to load an compiler
plugin from a jar (by using the -Xplugin option or by copying the jar
into misc/scala-devel/plugins)

Might it be a possibility to provide a jar only with the
scala-plugin.xml and provide the plugin itself in the classpath (or a
referenced project)? Where can I find $SCALA_HOME of the eclipse
plugin in order to copy the jar with the plugin definition into it?

Cheers,
Thomas

milessabin
Joined: 2008-08-11,
User offline. Last seen 33 weeks 3 days ago.
Re: running/debuging compiler plugin from Eclipse

On Wed, Jan 7, 2009 at 12:23 PM, Thomas Pawlitzki
wrote:
>> Unfortunately there's no easy way to do this at the moment ... it can
>> be done, but it'd be at least as easy to use the command line tools to
>> build test projects for your (compiler) plugin.
>
> How can this be done? I would appreciate it very much to debug my
> compiler plugin. During a previous compiler extension I experienced
> this as extremly useful feature and would miss this feature very much.

If you set yourself up for building the Eclipse plugin itself as described here,

http://lampsvn.epfl.ch/trac/scala/wiki/EclipsePlugin

then you'll be able to work on the Scala compiler and libraries using
Eclipse's incremental builder: the modified compiler would be
available in a "child" runtime workspace without having to rerun the
build scripts. But I would have thought this was quite a heavyweight
way of working on a compiler plugin ... if I'm wrong and you've got
experience of doing something like this previously, then please let us
know!

> After looking in the compiler options in greater detail I doubt if
> this is only an issue of the Eclipse Plugin. In the scala doc on
> http://scala-lang.org I found only the possibility to load an compiler
> plugin from a jar (by using the -Xplugin option or by copying the jar
> into misc/scala-devel/plugins)
>
> Might it be a possibility to provide a jar only with the
> scala-plugin.xml and provide the plugin itself in the classpath (or a
> referenced project)? Where can I find $SCALA_HOME of the eclipse
> plugin in order to copy the jar with the plugin definition into it?

That would be a local modification you could make if you took the
runtime workspace route I just mentioned. I think something along
these lines might be valuable as an enhancement to the compiler ...
maybe someone else can chip in on that?

Cheers,

Miles

Thomas Pawlitzki
Joined: 2009-01-07,
User offline. Last seen 42 years 45 weeks ago.
Re: running/debuging compiler plugin from Eclipse

Hello Miles,

> If you set yourself up for building the Eclipse plugin itself as described here,
> [...]

OK, i have tried to set myself up for building the Eclipse plugin.
But I think you are right and this is really a heavyweight for
developing a compiler plugin. So further down to see my more
lightweight idea.

> But I would have thought this was quite a heavyweight
> way of working on a compiler plugin ... if I'm wrong and you've got
> experience of doing something like this previously, then please let us
> know!

I recently developed a extension for the AspectBench Compiler[1].
There the compiler runs in a normal JVM and therefore I was able to
create a normal launch configuration which starts the compiler with my
extension and I was able to debug my extension entirely.

But I have another idea:
I have found a scala-compiler.jar. Is it possible to instantiate and
run the compiler programatically, something like

object CompilerLauncher {
def main(args : Array[Strimg] ) = {
val compiler = new Compiler(...)
compiler.addPlugin("myPlugin")
compiler.run()
}
}

This would make it possible to run/debug the compiler with my plugin
without hacking the Eclipse plugin. Is there a way to do this?

Cheers,
Thomas

[1] http://abc.comlab.ox.ac.uk/introduction

rytz
Joined: 2008-07-01,
User offline. Last seen 45 weeks 5 days ago.
Re: running/debuging compiler plugin from Eclipse



But I have another idea:
I have found a scala-compiler.jar. Is it possible to instantiate and
run the compiler programatically, something like

object CompilerLauncher {
 def main(args : Array[Strimg] ) = {
   val compiler = new Compiler(...)
   compiler.addPlugin("myPlugin")
   compiler.run()
 }
}

This would make it possible to run/debug the compiler with my plugin
without hacking the Eclipse plugin. Is there a way to do this?


Have a look at http://lampsvn.epfl.ch/trac/scala/browser/scala/trunk/docs/examples/plugintemplate/src/plugintemplate/standalone

Cheers: Lukas
 
Thomas Pawlitzki
Joined: 2009-01-07,
User offline. Last seen 42 years 45 weeks ago.
Re: running/debuging compiler plugin from Eclipse

Hello Lukas,
hello Milles,
hello all,

> Have a look at
> http://lampsvn.epfl.ch/trac/scala/browser/scala/trunk/docs/examples/plug...

Thank you for this link.
But there are a few things I do not understand in detail (and IMO they
do not realy fit to my needs).

So I tried to find a more standard way to launch my compiler plugin.
Therefore I looked into the scalac file. There I found that scalac
only launches
scala.tools.nsc.Main

I tried to create a launch-configuration for "scala.tools.nsc.Main"
and offer the arguments to load my plugin.

First of all I launched my configuration without any arguments and
receive the same result as launching scalac.
After that I create a jar containing only the scala-plugin.xml and
extend my launching configuration with the arguments:
-Xplugin:myplugin.jar -Xplugin-list

Then I get the error:
Exception in thread "main" java.util.NoSuchElementException: None.get
at scala.None$.get(Option.scala:150)
at scala.None$.get(Option.scala:148)
at scala.tools.nsc.plugins.Plugin$.loadFrom(Plugin.scala:106)
at scala.tools.nsc.plugins.Plugin$$anonfun$loadAllFrom$5.apply(Plugin.scala:142)
at scala.tools.nsc.plugins.Plugin$$anonfun$loadAllFrom$5.apply(Plugin.scala:142)
at scala.List.map(List.scala:805)
at scala.tools.nsc.plugins.Plugin$.loadAllFrom(Plugin.scala:142)
at scala.tools.nsc.plugins.Plugins$class.loadRoughPluginsList(Plugins.scala:28)
at scala.tools.nsc.Global.loadRoughPluginsList(Global.scala:35)
at scala.tools.nsc.plugins.Plugins$class.roughPluginsList(Plugins.scala:38)
at scala.tools.nsc.Global.roughPluginsList(Global.scala:35)
at scala.tools.nsc.plugins.Plugins$class.loadPlugins(Plugins.scala:91)
at scala.tools.nsc.Global.loadPlugins(Global.scala:35)
at scala.tools.nsc.plugins.Plugins$class.plugins(Plugins.scala:123)
at scala.tools.nsc.Global.plugins(Global.scala:35)
at scala.tools.nsc.plugins.Plugins$class.computePhaseDescriptors(Plugins.scala:155)
at scala.tools.nsc.Global.computePhaseDescriptors(Global.scala:35)
at scala.tools.nsc.Global.phaseDescriptors(Global.scala:447)
at scala.tools.nsc.Global$Run.(Global.scala:495)
at scala.tools.nsc.Main$.process(Main.scala:83)
at scala.tools.nsc.Main$.main(Main.scala:98)
at scala.tools.nsc.Main.main(Main.scala)

I tried different combinations of -Xplugin and other arguments and
also created a Jar including also the .class files of my plugin, but
still the same error appears.
(e.g.
I tried
-sourcepath <...> -d <...> myScalaTest.scala
which works perfectly without -Xplugin:<...>
)

I also tried this with the standard scalac and there I notice the same
behaviour.
Is there anything I do fundamentally wrong? Or is this a bug in the
scalac plugin loading?

Cheers,
Thomas

PS:
This my launch configuration:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

rytz
Joined: 2008-07-01,
User offline. Last seen 45 weeks 5 days ago.
Re: running/debuging compiler plugin from Eclipse
But this attempt would again not allow you to use the debugger, since the plugin loads from a jar file, right?

The example in the link I sent you below is essentailly a main method which creates a compiler (the "class PluginRunner extends Global" is a compiler), but instead of using the compiler's plugin system to generate the list of phases to run, this list is built manually. This happens in the class PluginRunner.

This way you don't need to have a jar-file for your plugin.



On Thu, Jan 8, 2009 at 10:43, Thomas Pawlitzki <thomas [dot] pawlitzki [at] gmail [dot] com> wrote:
Hello Lukas,
hello Milles,
hello all,

> Have a look at
> http://lampsvn.epfl.ch/trac/scala/browser/scala/trunk/docs/examples/plugintemplate/src/plugintemplate/standalone

Thank you for this link.
But there are a few things I do not understand in detail (and IMO they
do not realy fit to my needs).

So I tried to find a more standard way to launch my compiler plugin.
Therefore I looked into the scalac file. There I found that scalac
only launches
scala.tools.nsc.Main

I tried to create a launch-configuration for "scala.tools.nsc.Main"
and offer the arguments to load my plugin.

First of all I launched my configuration without any arguments and
receive the same result as launching scalac.
After that I create a jar containing only the scala-plugin.xml and
extend my launching configuration with the arguments:
-Xplugin:myplugin.jar -Xplugin-list

Then I get the error:
Exception in thread "main" java.util.NoSuchElementException: None.get
       at scala.None$.get(Option.scala:150)
       at scala.None$.get(Option.scala:148)
       at scala.tools.nsc.plugins.Plugin$.loadFrom(Plugin.scala:106)
       at scala.tools.nsc.plugins.Plugin$$anonfun$loadAllFrom$5.apply(Plugin.scala:142)
       at scala.tools.nsc.plugins.Plugin$$anonfun$loadAllFrom$5.apply(Plugin.scala:142)
       at scala.List.map(List.scala:805)
       at scala.tools.nsc.plugins.Plugin$.loadAllFrom(Plugin.scala:142)
       at scala.tools.nsc.plugins.Plugins$class.loadRoughPluginsList(Plugins.scala:28)
       at scala.tools.nsc.Global.loadRoughPluginsList(Global.scala:35)
       at scala.tools.nsc.plugins.Plugins$class.roughPluginsList(Plugins.scala:38)
       at scala.tools.nsc.Global.roughPluginsList(Global.scala:35)
       at scala.tools.nsc.plugins.Plugins$class.loadPlugins(Plugins.scala:91)
       at scala.tools.nsc.Global.loadPlugins(Global.scala:35)
       at scala.tools.nsc.plugins.Plugins$class.plugins(Plugins.scala:123)
       at scala.tools.nsc.Global.plugins(Global.scala:35)
       at scala.tools.nsc.plugins.Plugins$class.computePhaseDescriptors(Plugins.scala:155)
       at scala.tools.nsc.Global.computePhaseDescriptors(Global.scala:35)
       at scala.tools.nsc.Global.phaseDescriptors(Global.scala:447)
       at scala.tools.nsc.Global$Run.<init>(Global.scala:495)
       at scala.tools.nsc.Main$.process(Main.scala:83)
       at scala.tools.nsc.Main$.main(Main.scala:98)
       at scala.tools.nsc.Main.main(Main.scala)

I tried different combinations of -Xplugin and other arguments and
also created a Jar including also the .class files of my plugin, but
still the same error appears.
(e.g.
I tried
-sourcepath <...> -d <...> myScalaTest.scala
which works perfectly without -Xplugin:<...>
)

I also tried this with the standard scalac and there I notice the same
behaviour.
Is there anything I do fundamentally wrong? Or is this a bug in the
scalac plugin loading?

Cheers,
Thomas

PS:
This my launch configuration:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="scala.application">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/scala-eventtype-plugin/lib/scala-compiler.jar"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE"
value="scala.tools.nsc.Main"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS"
value="-Xplugin:eventtype-plugin-xml.jar -sourcepath
../ScalaTest/src -d
../ScalaTest/bin2 ../ScalaTest/src/list/ListTest.scala"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR"
value="scala-eventtype-plugin"/>
</launchConfiguration>

Thomas Pawlitzki
Joined: 2009-01-07,
User offline. Last seen 42 years 45 weeks ago.
Re: running/debuging compiler plugin from Eclipse

Hello Lukas,

> But this attempt would again not allow you to use the debugger, since the
> plugin loads from a jar file, right?

No, not in the way I was planning to do it.
I planned, as described in my post yesterday, to provide a .jar which
_only_ contains the scala-plugin.xml and the classes for the plugin in
the classpath (in my example a project referenced from my launch
configuration). The workaround with the jar is only done, because I
find no possibility to tell the compiler to load a plugin without a
jar.

> The example in the link I sent you below is essentailly a main method which
> creates a compiler (the "class PluginRunner extends Global" is a compiler),
> but instead of using the compiler's plugin system to generate the list of
> phases to run, this list is built manually. This happens in the class
> PluginRunner.

How can I define what the compiler should compile? I started the Main
by using a scalafile as argument but this file was not compiled
And how do I ensure that my Main runs the same phases as the normal
scala.tools.nsc.Main would do with my plugin? Do I have to define this
also manually?

> This way you don't need to have a jar-file for your plugin.

OK, I have a closer look at it, but I am still convinced that it would
be easier for compiler plugin development to use the normal Main
class. This would guarantee that the plugin execution from the IDE is
the same as the plugin execution without the IDE.

Cheers,
Thomas

rytz
Joined: 2008-07-01,
User offline. Last seen 45 weeks 5 days ago.
Re: running/debuging compiler plugin from Eclipse


> But this attempt would again not allow you to use the debugger, since the
> plugin loads from a jar file, right?

No, not in the way I was planning to do it.
I planned, as described in my post yesterday, to provide a .jar which
_only_ contains the scala-plugin.xml and the classes for the plugin in
the classpath (in my example a project referenced from my launch
configuration). The workaround with the jar is only done, because I
find no possibility to tell the compiler to load a plugin without a
jar.

Sorry I missed  that.


How can I define what the compiler should compile?

You need to create a CompilerCommand with the right arguments

val command = new CompilerCommand(List("file1.scala"), new Settings, println, false)
val compiler = new PluginRunner(settings)
val run = new compiler.Run
run.compile(command.files)


I started the Main
by using a scalafile as argument but this file was not compiled
And how do I ensure that my Main runs the same phases as the normal
scala.tools.nsc.Main would do with my plugin? Do I have to define this
also manually?

Yes, you'd need to specify all phases which appear in Global.scala (def builtInPhaseDescriptors). The example (PluginRunner) only runs a few phases and stops quite early. It does not do any code generation.
 

[...] This would guarantee that the plugin execution from the IDE is
the same as the plugin execution without the IDE.

That's right.

Cheers: Lukas

Sean McDirmid
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: running/debuging compiler plugin from Eclipse
Would it be possible/useful to make Scala plugins OSGI modules that can then be installed in Eclipse? Then, someone could just provide a UI in the Scala project preferences to check what compiler plugins they want to activate (from the list of plugins that were installed in Eclipse). 
Or maybe I'm not getting the problem. 

On Thu, Jan 8, 2009 at 6:56 PM, Lukas Rytz <lukas [dot] rytz [at] epfl [dot] ch> wrote:


> But this attempt would again not allow you to use the debugger, since the
> plugin loads from a jar file, right?

No, not in the way I was planning to do it.
I planned, as described in my post yesterday, to provide a .jar which
_only_ contains the scala-plugin.xml and the classes for the plugin in
the classpath (in my example a project referenced from my launch
configuration). The workaround with the jar is only done, because I
find no possibility to tell the compiler to load a plugin without a
jar.

Sorry I missed  that.


How can I define what the compiler should compile?

You need to create a CompilerCommand with the right arguments

val command = new CompilerCommand(List("file1.scala"), new Settings, println, false)
val compiler = new PluginRunner(settings)
val run = new compiler.Run
run.compile(command.files)


I started the Main
by using a scalafile as argument but this file was not compiled
And how do I ensure that my Main runs the same phases as the normal
scala.tools.nsc.Main would do with my plugin? Do I have to define this
also manually?

Yes, you'd need to specify all phases which appear in Global.scala (def builtInPhaseDescriptors). The example (PluginRunner) only runs a few phases and stops quite early. It does not do any code generation.
 

[...] This would guarantee that the plugin execution from the IDE is
the same as the plugin execution without the IDE.

That's right.

Cheers: Lukas


milessabin
Joined: 2008-08-11,
User offline. Last seen 33 weeks 3 days ago.
Re: running/debuging compiler plugin from Eclipse

On Thu, Jan 8, 2009 at 1:00 PM, Sean McDirmid wrote:
> Would it be possible/useful to make Scala plugins OSGI modules that can then
> be installed in Eclipse? Then, someone could just provide a UI in the Scala
> project preferences to check what compiler plugins they want to activate
> (from the list of plugins that were installed in Eclipse).
> Or maybe I'm not getting the problem.

OSGi doesn't help here. But it would certainly be possible in
principle to support "Compiler plugin projects" in Eclipse (or
Netbeans) which behaved that way.

It'd be an interesting project for someone to take on :-)

Cheers,

Miles

Joshua.Suereth
Joined: 2008-09-02,
User offline. Last seen 32 weeks 5 days ago.
Re: running/debuging compiler plugin from Eclipse
I've thought about that myself, and I definitely see it as possible to do.   I've just recently added some support to the maven plugin to allow a user to specify scalac plugins.  I know it would be possible to accomplish in eclipse.

Sean's suggestion could actually be the easiest to implement *if* we made scala start depending on OSGi (which i doubt would ever happen). 

In lieu of that, the eclipse plugin would need some kind of custom run configuration to "run the current project as a scalac plugin" or some such fun.  The other piece is should the compiler preferences allow uses to add scalac plugins?   That's a different story.

As I'm strapped for time, I doubt I'll be able to put anything out there, but to whoever *does* have time, let me know if you need any help getting things set up.


-Josh

On Thu, Jan 8, 2009 at 8:08 AM, Miles Sabin <miles [at] milessabin [dot] com> wrote:
On Thu, Jan 8, 2009 at 1:00 PM, Sean McDirmid <sean [dot] mcdirmid [at] gmail [dot] com> wrote:
> Would it be possible/useful to make Scala plugins OSGI modules that can then
> be installed in Eclipse? Then, someone could just provide a UI in the Scala
> project preferences to check what compiler plugins they want to activate
> (from the list of plugins that were installed in Eclipse).
> Or maybe I'm not getting the problem.

OSGi doesn't help here. But it would certainly be possible in
principle to support "Compiler plugin projects" in Eclipse (or
Netbeans) which behaved that way.

It'd be an interesting project for someone to take on :-)

Cheers,


Miles

milessabin
Joined: 2008-08-11,
User offline. Last seen 33 weeks 3 days ago.
Re: running/debuging compiler plugin from Eclipse

On Thu, Jan 8, 2009 at 1:38 PM, Josh Suereth wrote:
> Sean's suggestion could actually be the easiest to implement *if* we made
> scala start depending on OSGi (which i doubt would ever happen).

Yup ... scalac would have to be an OSGi application and I don't see
that happening any time soon.

> In lieu of that, the eclipse plugin would need some kind of custom run
> configuration to "run the current project as a scalac plugin" or some such
> fun. The other piece is should the compiler preferences allow uses to add
> scalac plugins? That's a different story.

Exactly that :-)

> As I'm strapped for time, I doubt I'll be able to put anything out there,
> but to whoever *does* have time, let me know if you need any help getting
> things set up.

Ditto ...

Cheers,

Miles

Thomas Pawlitzki
Joined: 2009-01-07,
User offline. Last seen 42 years 45 weeks ago.
Re: running/debuging compiler plugin from Eclipse

Hello,

> In lieu of that, the eclipse plugin would need some kind of custom run
> configuration to "run the current project as a scalac plugin" or some such
> fun. The other piece is should the compiler preferences allow uses to add
> scalac plugins?

At the risk of repeating myself I think the easiest way of run
compiler plugins directly from Eclipse (or any other IDE) is the
following:

- put scala-compiler.jar in the class path
- create a launch configuration for scala.tools.nsc.Main
- pass the -Xplugin argument within this configuration which points to
a jar containing the scala-plugin-xml
- provide the plugin-implementation in a project referenced from the
launch configuration

The advantages of this approach is that your plugin behaves exactly
like it is started outside your IDE but is still full under the
control of the IDE (including debugging, profiling, etc.)

The point is that I am not able to load a plugin like that (and have
no more ideas to analyse further as I am just starting to work with
Scala). Perhaps one of the Scala experts can have a look at this.
IMO this might be a bug in the "scala -Xplugin" functionality as I
also get the same error when I want to load like described in
http://www.scala-lang.org/node/140

Alwyas (from the IDE or the console) the following Exception is
generated as soon as the -Xplugin argument is used:
Exception in thread "main" java.util.NoSuchElementException: None.get
at scala.None$.get(Option.scala:150)
at scala.None$.get(Option.scala:148)
at scala.tools.nsc.plugins.Plugin$.loadFrom(Plugin.scala:106)
at scala.tools.nsc.plugins.Plugin$$anonfun$loadAllFrom$5.apply(Plugin.scala:142)
at scala.tools.nsc.plugins.Plugin$$anonfun$loadAllFrom$5.apply(Plugin.scala:142)
at scala.List.map(List.scala:805)
at scala.tools.nsc.plugins.Plugin$.loadAllFrom(Plugin.scala:142)
at scala.tools.nsc.plugins.Plugins$class.loadRoughPluginsList(Plugins.scala:28)
at scala.tools.nsc.Global.loadRoughPluginsList(Global.scala:35)
at scala.tools.nsc.plugins.Plugins$class.roughPluginsList(Plugins.scala:38)
at scala.tools.nsc.Global.roughPluginsList(Global.scala:35)
at scala.tools.nsc.plugins.Plugins$class.loadPlugins(Plugins.scala:91)
at scala.tools.nsc.Global.loadPlugins(Global.scala:35)
at scala.tools.nsc.plugins.Plugins$class.plugins(Plugins.scala:123)
at scala.tools.nsc.Global.plugins(Global.scala:35)
at scala.tools.nsc.plugins.Plugins$class.computePhaseDescriptors(Plugins.scala:155)
at scala.tools.nsc.Global.computePhaseDescriptors(Global.scala:35)
at scala.tools.nsc.Global.phaseDescriptors(Global.scala:447)
at scala.tools.nsc.Global$Run.(Global.scala:495)
at scala.tools.nsc.Main$.process(Main.scala:83)
at scala.tools.nsc.Main$.main(Main.scala:98)
at scala.tools.nsc.Main.main(Main.scala)

Cheers,
Thomas

Sean McDirmid
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: running/debuging compiler plugin from Eclipse
That is basically an NPE happening in the compiler plugin load code. So its probably not finding something that it should be. (I don't have the code on this computer, but I would look at line 106 in scala.tools.nsc.plugins/Plugin.scala for more details).
Sean

On Thu, Jan 8, 2009 at 10:20 PM, Thomas Pawlitzki <thomas [dot] pawlitzki [at] gmail [dot] com> wrote:
Alwyas (from the IDE or the console) the following Exception is
generated as soon as the -Xplugin argument is used:
Exception in thread "main" java.util.NoSuchElementException: None.get
       at scala.None$.get(Option.scala:150)
       at scala.None$.get(Option.scala:148)
       at scala.tools.nsc.plugins.Plugin$.loadFrom(Plugin.scala:106)
       at scala.tools.nsc.plugins.Plugin$$anonfun$loadAllFrom$5.apply(Plugin.scala:142)
       at scala.tools.nsc.plugins.Plugin$$anonfun$loadAllFrom$5.apply(Plugin.scala:142)
       at scala.List.map(List.scala:805)
       at scala.tools.nsc.plugins.Plugin$.loadAllFrom(Plugin.scala:142)
       at scala.tools.nsc.plugins.Plugins$class.loadRoughPluginsList(Plugins.scala:28)
       at scala.tools.nsc.Global.loadRoughPluginsList(Global.scala:35)
       at scala.tools.nsc.plugins.Plugins$class.roughPluginsList(Plugins.scala:38)
       at scala.tools.nsc.Global.roughPluginsList(Global.scala:35)
       at scala.tools.nsc.plugins.Plugins$class.loadPlugins(Plugins.scala:91)
       at scala.tools.nsc.Global.loadPlugins(Global.scala:35)
       at scala.tools.nsc.plugins.Plugins$class.plugins(Plugins.scala:123)
       at scala.tools.nsc.Global.plugins(Global.scala:35)
       at scala.tools.nsc.plugins.Plugins$class.computePhaseDescriptors(Plugins.scala:155)
       at scala.tools.nsc.Global.computePhaseDescriptors(Global.scala:35)
       at scala.tools.nsc.Global.phaseDescriptors(Global.scala:447)
       at scala.tools.nsc.Global$Run.<init>(Global.scala:495)
       at scala.tools.nsc.Main$.process(Main.scala:83)
       at scala.tools.nsc.Main$.main(Main.scala:98)
       at scala.tools.nsc.Main.main(Main.scala)

Cheers,
Thomas

Thomas Pawlitzki
Joined: 2009-01-07,
User offline. Last seen 42 years 45 weeks ago.
Re: running/debuging compiler plugin from Eclipse

Hello all,

after a lot of trying and debugging I finally get it working as I planned:
> - put scala-compiler.jar in the class path
> - create a launch configuration for scala.tools.nsc.Main
> - pass the -Xplugin argument within this configuration which points to
> a jar containing the scalac-plugin-xml
> - provide the plugin-implementation in a project referenced from the
> launch configuration

In the end I am not able to discover the error exactly but my guess is
that it was a pathing (shared directories) problem.

For compiler plugin developers this topic might be a wiki page worth.

Cheers,
Thomas

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland