Search in sources :

Example 11 with CachedMethod

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

the class MetaClassImpl method addNewStaticMethod.

/**
     *Adds a static method to this metaclass.
     *
     * @param method The method to be added
     */
public void addNewStaticMethod(Method method) {
    final CachedMethod cachedMethod = CachedMethod.find(method);
    NewStaticMetaMethod newMethod = new NewStaticMetaMethod(cachedMethod);
    final CachedClass declaringClass = newMethod.getDeclaringClass();
    addNewStaticMethodToIndex(newMethod, metaMethodIndex.getHeader(declaringClass.getTheClass()));
}
Also used : NewStaticMetaMethod(org.codehaus.groovy.runtime.metaclass.NewStaticMetaMethod) CachedMethod(org.codehaus.groovy.reflection.CachedMethod) CachedClass(org.codehaus.groovy.reflection.CachedClass)

Example 12 with CachedMethod

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

the class MetaClassImpl method applyPropertyDescriptors.

protected void applyPropertyDescriptors(PropertyDescriptor[] propertyDescriptors) {
    // MetaBeanProperty objects
    for (PropertyDescriptor pd : propertyDescriptors) {
        // which is not a valid property)
        if (pd.getPropertyType() == null)
            continue;
        // get the getter method
        Method method = pd.getReadMethod();
        MetaMethod getter;
        if (method != null) {
            CachedMethod cachedGetter = CachedMethod.find(method);
            getter = cachedGetter == null ? null : findMethod(cachedGetter);
        } else {
            getter = null;
        }
        // get the setter method
        MetaMethod setter;
        method = pd.getWriteMethod();
        if (method != null) {
            CachedMethod cachedSetter = CachedMethod.find(method);
            setter = cachedSetter == null ? null : findMethod(cachedSetter);
        } else {
            setter = null;
        }
        // now create the MetaProperty object
        MetaBeanProperty mp = new MetaBeanProperty(pd.getName(), pd.getPropertyType(), getter, setter);
        addMetaBeanProperty(mp);
    }
}
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) PropertyDescriptor(java.beans.PropertyDescriptor) CachedMethod(org.codehaus.groovy.reflection.CachedMethod) NewInstanceMetaMethod(org.codehaus.groovy.runtime.metaclass.NewInstanceMetaMethod) Method(java.lang.reflect.Method) CachedMethod(org.codehaus.groovy.reflection.CachedMethod) 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)

Example 13 with CachedMethod

use of org.codehaus.groovy.reflection.CachedMethod in project groovy-core by groovy.

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)

Example 14 with CachedMethod

use of org.codehaus.groovy.reflection.CachedMethod in project groovy-core by groovy.

the class MetaClassImpl method addNewInstanceMethod.

/**
     *Adds an instance method to this metaclass.
     *
     * @param method The method to be added
     */
public void addNewInstanceMethod(Method method) {
    final CachedMethod cachedMethod = CachedMethod.find(method);
    NewInstanceMetaMethod newMethod = new NewInstanceMetaMethod(cachedMethod);
    final CachedClass declaringClass = newMethod.getDeclaringClass();
    addNewInstanceMethodToIndex(newMethod, metaMethodIndex.getHeader(declaringClass.getTheClass()));
}
Also used : NewInstanceMetaMethod(org.codehaus.groovy.runtime.metaclass.NewInstanceMetaMethod) CachedMethod(org.codehaus.groovy.reflection.CachedMethod) CachedClass(org.codehaus.groovy.reflection.CachedClass)

Example 15 with CachedMethod

use of org.codehaus.groovy.reflection.CachedMethod in project groovy-core by groovy.

the class MetaClassImpl method addNewStaticMethod.

/**
     *Adds a static method to this metaclass.
     *
     * @param method The method to be added
     */
public void addNewStaticMethod(Method method) {
    final CachedMethod cachedMethod = CachedMethod.find(method);
    NewStaticMetaMethod newMethod = new NewStaticMetaMethod(cachedMethod);
    final CachedClass declaringClass = newMethod.getDeclaringClass();
    addNewStaticMethodToIndex(newMethod, metaMethodIndex.getHeader(declaringClass.getTheClass()));
}
Also used : NewStaticMetaMethod(org.codehaus.groovy.runtime.metaclass.NewStaticMetaMethod) CachedMethod(org.codehaus.groovy.reflection.CachedMethod) CachedClass(org.codehaus.groovy.reflection.CachedClass)

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