Search in sources :

Example 66 with CachedClass

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

the class MetaClassImpl method inheritStaticInterfaceFields.

private void inheritStaticInterfaceFields(LinkedList superClasses, Set interfaces) {
    for (Iterator interfaceIter = interfaces.iterator(); interfaceIter.hasNext(); ) {
        CachedClass iclass = (CachedClass) interfaceIter.next();
        SingleKeyHashMap iPropertyIndex = classPropertyIndex.getNotNull(iclass);
        addFields(iclass, iPropertyIndex);
        for (Iterator classIter = superClasses.iterator(); classIter.hasNext(); ) {
            CachedClass sclass = (CachedClass) classIter.next();
            if (!iclass.getTheClass().isAssignableFrom(sclass.getTheClass()))
                continue;
            SingleKeyHashMap sPropertyIndex = classPropertyIndex.getNotNull(sclass);
            copyNonPrivateFields(iPropertyIndex, sPropertyIndex);
        }
    }
}
Also used : SingleKeyHashMap(org.codehaus.groovy.util.SingleKeyHashMap) CachedClass(org.codehaus.groovy.reflection.CachedClass)

Example 67 with CachedClass

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

the class MetaClassHelper method calculateParameterDistance.

public static long calculateParameterDistance(Class[] arguments, ParameterTypes pt) {
    CachedClass[] parameters = pt.getParameterTypes();
    if (parameters.length == 0)
        return 0;
    long ret = 0;
    int noVargsLength = parameters.length - 1;
    // we can safely iterate to this point
    for (int i = 0; i < noVargsLength; i++) {
        ret += calculateParameterDistance(arguments[i], parameters[i]);
    }
    if (arguments.length == parameters.length) {
        // case C&D, we use baseType to calculate and set it
        // to the value we need according to case C and D
        // case C
        CachedClass baseType = parameters[noVargsLength];
        if (!parameters[noVargsLength].isAssignableFrom(arguments[noVargsLength])) {
            // case D
            baseType = ReflectionCache.getCachedClass(baseType.getTheClass().getComponentType());
            // penalty for vargs
            ret += 2L << VARGS_SHIFT;
        }
        ret += calculateParameterDistance(arguments[noVargsLength], baseType);
    } else if (arguments.length > parameters.length) {
        // case B
        // we give our a vargs penalty for each exceeding argument and iterate
        // by using parameters[noVargsLength].getComponentType()
        // penalty for vargs
        ret += (2L + arguments.length - parameters.length) << VARGS_SHIFT;
        CachedClass vargsType = ReflectionCache.getCachedClass(parameters[noVargsLength].getTheClass().getComponentType());
        for (int i = noVargsLength; i < arguments.length; i++) {
            ret += calculateParameterDistance(arguments[i], vargsType);
        }
    } else {
        // case A
        // we give a penalty for vargs, since we have no direct
        // match for the last argument
        ret += 1L << VARGS_SHIFT;
    }
    return ret;
}
Also used : CachedClass(org.codehaus.groovy.reflection.CachedClass)

Example 68 with CachedClass

use of org.codehaus.groovy.reflection.CachedClass 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)

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