Search in sources :

Example 56 with CachedClass

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

the class CallSiteGenerator method compilePojoMethod.

public static Constructor compilePojoMethod(CachedMethod cachedMethod) {
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    final CachedClass declClass = cachedMethod.getDeclaringClass();
    final CallSiteClassLoader callSiteLoader = declClass.getCallSiteLoader();
    final String name = callSiteLoader.createClassName(cachedMethod.setAccessible());
    final byte[] bytes = genPojoMetaMethodSite(cachedMethod, cw, name);
    return callSiteLoader.defineClassAndGetConstructor(name, bytes);
}
Also used : CachedClass(org.codehaus.groovy.reflection.CachedClass) ClassWriter(org.objectweb.asm.ClassWriter)

Example 57 with CachedClass

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

the class CallSiteGenerator method compileStaticMethod.

public static Constructor compileStaticMethod(CachedMethod cachedMethod) {
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    final CachedClass declClass = cachedMethod.getDeclaringClass();
    final CallSiteClassLoader callSiteLoader = declClass.getCallSiteLoader();
    final String name = callSiteLoader.createClassName(cachedMethod.setAccessible());
    final byte[] bytes = genStaticMetaMethodSite(cachedMethod, cw, name);
    return callSiteLoader.defineClassAndGetConstructor(name, bytes);
}
Also used : CachedClass(org.codehaus.groovy.reflection.CachedClass) ClassWriter(org.objectweb.asm.ClassWriter)

Example 58 with CachedClass

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

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 59 with CachedClass

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

the class MetaClassImpl method addMetaMethod.

// Implementation methods
//-------------------------------------------------------------------------
/**
     * adds a MetaMethod to this class. WARNING: this method will not
     * do the neccessary steps for multimethod logic and using this
     * method doesn't mean, that a method added here is replacing another
     * method from a parent class completely. These steps are usually done
     * by initialize, which means if you need these steps, you have to add
     * the method before running initialize the first time.
     *
     * @param method the MetaMethod
     * @see #initialize()
     */
public void addMetaMethod(MetaMethod method) {
    if (isInitialized()) {
        throw new RuntimeException("Already initialized, cannot add new method: " + method);
    }
    final CachedClass declaringClass = method.getDeclaringClass();
    addMetaMethodToIndex(method, metaMethodIndex.getHeader(declaringClass.getTheClass()));
}
Also used : CachedClass(org.codehaus.groovy.reflection.CachedClass)

Example 60 with CachedClass

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

the class MetaClassImpl method calcFirstGroovySuperClass.

private CachedClass calcFirstGroovySuperClass(Collection superClasses) {
    if (theCachedClass.isInterface)
        return ReflectionCache.OBJECT_CLASS;
    CachedClass firstGroovy = null;
    Iterator iter = superClasses.iterator();
    for (; iter.hasNext(); ) {
        CachedClass c = (CachedClass) iter.next();
        if (GroovyObject.class.isAssignableFrom(c.getTheClass())) {
            firstGroovy = c;
            break;
        }
    }
    if (firstGroovy == null)
        firstGroovy = theCachedClass;
    else {
        if (firstGroovy.getTheClass() == GroovyObjectSupport.class && iter.hasNext()) {
            firstGroovy = (CachedClass) iter.next();
            if (firstGroovy.getTheClass() == Closure.class && iter.hasNext()) {
                firstGroovy = (CachedClass) iter.next();
            }
        }
    }
    return GroovyObject.class.isAssignableFrom(firstGroovy.getTheClass()) ? firstGroovy.getCachedSuperClass() : firstGroovy;
}
Also used : MethodClosure(org.codehaus.groovy.runtime.MethodClosure) GeneratedClosure(org.codehaus.groovy.runtime.GeneratedClosure) CurriedClosure(org.codehaus.groovy.runtime.CurriedClosure) ConvertedClosure(org.codehaus.groovy.runtime.ConvertedClosure) CachedClass(org.codehaus.groovy.reflection.CachedClass)

Aggregations

CachedClass (org.codehaus.groovy.reflection.CachedClass)68 NewInstanceMetaMethod (org.codehaus.groovy.runtime.metaclass.NewInstanceMetaMethod)17 NewStaticMetaMethod (org.codehaus.groovy.runtime.metaclass.NewStaticMetaMethod)17 GeneratedMetaMethod (org.codehaus.groovy.reflection.GeneratedMetaMethod)15 ClosureMetaMethod (org.codehaus.groovy.runtime.metaclass.ClosureMetaMethod)15 MixinInstanceMetaMethod (org.codehaus.groovy.runtime.metaclass.MixinInstanceMetaMethod)15 CachedMethod (org.codehaus.groovy.reflection.CachedMethod)13 NewMetaMethod (org.codehaus.groovy.runtime.metaclass.NewMetaMethod)13 TransformMetaMethod (org.codehaus.groovy.runtime.metaclass.TransformMetaMethod)13 SingleKeyHashMap (org.codehaus.groovy.util.SingleKeyHashMap)10 MetaMethodIndex (org.codehaus.groovy.runtime.metaclass.MetaMethodIndex)8 ClassWriter (org.objectweb.asm.ClassWriter)6 ParameterTypes (org.codehaus.groovy.reflection.ParameterTypes)4 GetBeanMethodMetaProperty (org.codehaus.groovy.runtime.metaclass.MethodMetaProperty.GetBeanMethodMetaProperty)4 GetMethodMetaProperty (org.codehaus.groovy.runtime.metaclass.MethodMetaProperty.GetMethodMetaProperty)4 MetaMethod (groovy.lang.MetaMethod)3 FastArray (org.codehaus.groovy.util.FastArray)3 MixinInMetaClass (org.codehaus.groovy.reflection.MixinInMetaClass)2 ConvertedClosure (org.codehaus.groovy.runtime.ConvertedClosure)2 CurriedClosure (org.codehaus.groovy.runtime.CurriedClosure)2