Java Mailing List Archive

http://www.gg3721.com/

Home » user.groovy »

[groovy-user] problems getting info about groovy class

david kment

2008-08-13

Replies: Find Java Web Hosting

Author LoginPost Reply
hi folks.

i am new to groovy, and i want to integrate groovy into a Java application for scripting
plugins via groovy.

for a related feature i need to know some information about a groovy class
defined in some script file, namely the classes methods and member variables.

i am trying to get this information using the following code:

       GroovyShell shell = new GroovyShell();
       Script script = shell.parse(new File(fileName));

       MetaClass meta = script.getMetaClass();

       ClassNode cnode = meta.getClassNode();

       List methods = cnode.getAllDeclaredMethods();

       Iterator it = methods.iterator();
       while(it.hasNext())
       {
          MetaMethod method = (MetaMethod)it.next();
          System.out.println(method.getName());
       }

but all i get is a NullPointerException at line "List methods = cnode.getAllDeclaredMethods();".

can someone point out what i am doing wrong, or if there is another/better way to do this?

also, i already tried loading the script using a ClassLoader into a Class and getting the information
using the java.lang.reflect features. but this gave me all information from the compiled class,
which was not exactly what is needed. and i am sure there must be a way to get the needed info
from the sourcecode.

any help appreciated.

regards,

David

____________________________________________________________
Großes Kino für zu Hause - Kostenlos für alle WEB.DE Nutzer!
Jetzt kostenlos anmelden unter http://www.blockbuster.web.de


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email


©2008 gg3721.com - Jax Systems, LLC, U.S.A.