How to list all (groovy) classes in JVM in groovy

Posted by Dan on Stack Overflow See other posts from Stack Overflow or by Dan
Published on 2010-04-26T16:15:31Z Indexed on 2010/04/27 2:33 UTC
Read the original article Hit count: 684

Filed under:
|
|
|

I am writing a DelegatingMetaClass that I would like to apply to all groovy classes in my project, but I do not how to get hold of all classes in the project?

Here is the code:

 /*
 This will work ok, since I know Foo beforehand, but what about classes 
 that do not exist yet?
 */
 def myMetaClass = new DelegatingMetaClass(Foo.class)
 InvokerHelper.metaRegistry.setMetaClass(Foo.class, myMetaClass)    

 /*
 how to do this?
 allGroovyClasses.each{
      def myMetaClass = new DelegatingMetaClass(it)
      InvokerHelper.metaRegistry.setMetaClass(it, myMetaClass)  
         }
 */


 class SimpleInterceptor extends DelegatingMetaClass{


 public SimpleInterceptor(final Class aclass) {
   super(aclass);    
   initialize();
 }

 public Object getProperty(Object object, String prop) {
     println ("I am in a property interceptor!!!")
   return super.getProperty(object, prop)
 }

 public Object invokeMethod(Object a_object, String a_methodName, Object[] a_arguments)
 {
     println ("I am in a method interceptor!!!")
     return super.invokeMethod(a_object, a_methodName, a_arguments) 
 }

© Stack Overflow or respective owner

Related posts about groovy

Related posts about jvm