Search in sources :

Example 21 with CachedMethod

use of org.codehaus.groovy.reflection.CachedMethod in project groovy by apache.

the class SimpleExtensionModule method createMetaMethods.

private static void createMetaMethods(final Class extensionClass, final List<MetaMethod> metaMethods, final boolean isStatic) {
    CachedClass cachedClass = ReflectionCache.getCachedClass(extensionClass);
    CachedMethod[] methods = cachedClass.getMethods();
    for (CachedMethod method : methods) {
        if (method.isStatic() && method.isPublic() && method.getParamsCount() > 0) {
            // an extension method is found
            metaMethods.add(isStatic ? new NewStaticMetaMethod(method) : new NewInstanceMetaMethod(method));
        }
    }
}
Also used : NewInstanceMetaMethod(org.codehaus.groovy.runtime.metaclass.NewInstanceMetaMethod) NewStaticMetaMethod(org.codehaus.groovy.runtime.metaclass.NewStaticMetaMethod) CachedMethod(org.codehaus.groovy.reflection.CachedMethod) CachedClass(org.codehaus.groovy.reflection.CachedClass)

Example 22 with CachedMethod

use of org.codehaus.groovy.reflection.CachedMethod in project groovy by apache.

the class MetaClassImpl method addInterfaceMethods.

private void addInterfaceMethods(Set<CachedClass> interfaces) {
    MetaMethodIndex.Header header = metaMethodIndex.getHeader(theClass);
    for (CachedClass c : interfaces) {
        final CachedMethod[] m = c.getMethods();
        for (int i = 0; i != m.length; ++i) {
            MetaMethod method = m[i];
            addMetaMethodToIndex(method, header);
        }
    }
}
Also used : NewInstanceMetaMethod(org.codehaus.groovy.runtime.metaclass.NewInstanceMetaMethod) NewMetaMethod(org.codehaus.groovy.runtime.metaclass.NewMetaMethod) MixinInstanceMetaMethod(org.codehaus.groovy.runtime.metaclass.MixinInstanceMetaMethod) NewStaticMetaMethod(org.codehaus.groovy.runtime.metaclass.NewStaticMetaMethod) GeneratedMetaMethod(org.codehaus.groovy.reflection.GeneratedMetaMethod) ClosureMetaMethod(org.codehaus.groovy.runtime.metaclass.ClosureMetaMethod) TransformMetaMethod(org.codehaus.groovy.runtime.metaclass.TransformMetaMethod) MetaMethodIndex(org.codehaus.groovy.runtime.metaclass.MetaMethodIndex) CachedMethod(org.codehaus.groovy.reflection.CachedMethod) CachedClass(org.codehaus.groovy.reflection.CachedClass)

Example 23 with CachedMethod

use of org.codehaus.groovy.reflection.CachedMethod in project groovy by apache.

the class A_GroovyReflector method doIt.

static void doIt() {
    new A().protectedMethod();
    try {
        CachedMethod m = CachedMethod.find(A.class.getDeclaredMethod("protectedMethod", new Class[0]));
        Object[] arguments = new Object[0];
        m.setAccessible().invoke(new A(), arguments);
    } catch (NoSuchMethodException e) {
    } catch (IllegalAccessException e) {
    } catch (InvocationTargetException e) {
    }
}
Also used : CachedMethod(org.codehaus.groovy.reflection.CachedMethod) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

CachedMethod (org.codehaus.groovy.reflection.CachedMethod)23 CachedClass (org.codehaus.groovy.reflection.CachedClass)19 NewInstanceMetaMethod (org.codehaus.groovy.runtime.metaclass.NewInstanceMetaMethod)10 NewStaticMetaMethod (org.codehaus.groovy.runtime.metaclass.NewStaticMetaMethod)10 GeneratedMetaMethod (org.codehaus.groovy.reflection.GeneratedMetaMethod)8 ClosureMetaMethod (org.codehaus.groovy.runtime.metaclass.ClosureMetaMethod)6 MixinInstanceMetaMethod (org.codehaus.groovy.runtime.metaclass.MixinInstanceMetaMethod)6 NewMetaMethod (org.codehaus.groovy.runtime.metaclass.NewMetaMethod)6 TransformMetaMethod (org.codehaus.groovy.runtime.metaclass.TransformMetaMethod)6 Method (java.lang.reflect.Method)5 ArrayList (java.util.ArrayList)4 MetaMethodIndex (org.codehaus.groovy.runtime.metaclass.MetaMethodIndex)4 MetaMethod (groovy.lang.MetaMethod)2 PropertyDescriptor (java.beans.PropertyDescriptor)2 FileOutputStream (java.io.FileOutputStream)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 GeneratedClosure (org.codehaus.groovy.runtime.GeneratedClosure)2 MethodClosure (org.codehaus.groovy.runtime.MethodClosure)2 ClassWriter (org.objectweb.asm.ClassWriter)2 Label (org.objectweb.asm.Label)2