[Spoon-discuss] some questions
Lionel Seinturier
Lionel.Seinturier at univ-lille1.fr
Sat Jan 31 13:40:00 CET 2009
Hi,
On 31/01/2009 10:58, Lea Hänsenberger wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi all,
> I was wondering whether there's some interface to launch spoon
> programmatically? On the homepage I only found out how to launch it
> from command line and at the moment I just call Launcher.main() in my
> application, but that's not very nice.
A while back I needed also to access Spoon programmatically. I'm not
sure whether this is the best solution, but I somewhat ended up using
the solution which is implemented in:
http://svn.forge.objectweb.org/cgi-bin/viewcvs.cgi/fractal/trunk/juliac/plugin/spoon/src/main/java/org/objectweb/fractal/juliac/spoon/SpoonSupportImpl.java?rev=8747&view=auto
Basically, you can skip all details related to the
org.objectweb.fractal.juliac package and concentrate on spoon.
The init() method creates an Environment, a Factory and a Builder. The
builder is fed with some CtFiles (built from Files). Then
builder.build() is called.
After that, the Factory is populated with the CtElements from the parsed
program. You can then navigate, modify, dump, etc. the AST.
This is a bit of a hacking, but basically this works.
Regards,
Lionel.
> And another question: is there a way to avoid that a class processed
> by a processor is changed? I'm processing JUnit 4 tests which have
> static imports for the assert functions. It seems that spoon removes
> those imports in the original java file and rewrites the method calls
> so the fully qualified method name is invoked, e.g.
> org.junit.Assert.assertTrue(). In my application I only need to read
> the original class to write a new one and it's not very nice this
> original class is changed.
>
> And a last question: I noticed that when writing a field access with
> 'this', e.g. this.aField, the class name is put before the 'this',
> e.g. MyClass.this.aField. Can this be avoided somehow?
>
> Can someone help me?
>
> Thanks very much.
>
> Cheers,
> Lea
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.8 (Darwin)
>
> iEYEARECAAYFAkmEIN0ACgkQbnjxxNQo6DBhlACfSvdJFdJfQR6Iy/h5lcvLpEX6
> FQwAmgKUwCvZMIyHh70O3c+qk9HTdz9w
> =PJK5
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> Spoon-discuss mailing list
> Spoon-discuss at lists.gforge.inria.fr
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/spoon-discuss
>
--
Lionel Seinturier
Univ. Lille (USTL) - Lab. LIFL - INRIA ADAM
http://www.lifl.fr/~seinturi
More information about the Spoon-discuss
mailing list