Search in sources :

Example 26 with CachedClass

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

the class MetaClassImpl method populateMethods.

private void populateMethods(LinkedList<CachedClass> superClasses, CachedClass firstGroovySuper) {
    MetaMethodIndex.Header header = metaMethodIndex.getHeader(firstGroovySuper.getTheClass());
    CachedClass c;
    Iterator<CachedClass> iter = superClasses.iterator();
    for (; iter.hasNext(); ) {
        c = iter.next();
        CachedMethod[] cachedMethods = c.getMethods();
        for (CachedMethod metaMethod : cachedMethods) {
            addToAllMethodsIfPublic(metaMethod);
            if (!metaMethod.isPrivate() || c == firstGroovySuper)
                addMetaMethodToIndex(metaMethod, header);
        }
        MetaMethod[] cachedMethods1 = getNewMetaMethods(c);
        for (final MetaMethod method : cachedMethods1) {
            if (!newGroovyMethodsSet.contains(method)) {
                newGroovyMethodsSet.add(method);
                addMetaMethodToIndex(method, header);
            }
        }
        if (c == firstGroovySuper)
            break;
    }
    MetaMethodIndex.Header last = header;
    for (; iter.hasNext(); ) {
        c = iter.next();
        header = metaMethodIndex.getHeader(c.getTheClass());
        if (last != null) {
            metaMethodIndex.copyNonPrivateMethods(last, header);
        }
        last = header;
        for (CachedMethod metaMethod : c.getMethods()) {
            addToAllMethodsIfPublic(metaMethod);
            addMetaMethodToIndex(metaMethod, header);
        }
        for (final MetaMethod method : getNewMetaMethods(c)) {
            if (method.getName().equals("<init>") && !method.getDeclaringClass().equals(theCachedClass))
                continue;
            if (!newGroovyMethodsSet.contains(method)) {
                newGroovyMethodsSet.add(method);
                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 27 with CachedClass

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

the class MetaClassImpl method connectMultimethods.

private void connectMultimethods(List<CachedClass> superClasses, CachedClass firstGroovyClass) {
    superClasses = DefaultGroovyMethods.reverse(superClasses);
    MetaMethodIndex.Header last = null;
    for (final CachedClass c : superClasses) {
        MetaMethodIndex.Header methodIndex = metaMethodIndex.getHeader(c.getTheClass());
        // It saves us a lot of space and some noticeable time
        if (last != null)
            metaMethodIndex.copyNonPrivateNonNewMetaMethods(last, methodIndex);
        last = methodIndex;
        if (c == firstGroovyClass)
            break;
    }
}
Also used : MetaMethodIndex(org.codehaus.groovy.runtime.metaclass.MetaMethodIndex) CachedClass(org.codehaus.groovy.reflection.CachedClass)

Example 28 with CachedClass

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

the class MetaClassImpl method applyStrayPropertyMethods.

private void applyStrayPropertyMethods(LinkedList<CachedClass> superClasses, Index classPropertyIndex, boolean isThis) {
    // now look for any stray getters that may be used to define a property
    for (CachedClass klass : superClasses) {
        MetaMethodIndex.Header header = metaMethodIndex.getHeader(klass.getTheClass());
        SingleKeyHashMap propertyIndex = classPropertyIndex.getNotNull(klass);
        for (MetaMethodIndex.Entry e = header.head; e != null; e = e.nextClassEntry) {
            String methodName = e.name;
            // name too short?
            if (methodName.length() < 3 || (!methodName.startsWith("is") && methodName.length() < 4))
                continue;
            // possible getter/setter?
            boolean isGetter = methodName.startsWith("get") || methodName.startsWith("is");
            boolean isBooleanGetter = methodName.startsWith("is");
            boolean isSetter = methodName.startsWith("set");
            if (!isGetter && !isSetter)
                continue;
            Object propertyMethods = filterPropertyMethod(isThis ? e.methods : e.methodsForSuper, isGetter, isBooleanGetter);
            if (propertyMethods == null)
                continue;
            String propName = getPropName(methodName);
            if (propertyMethods instanceof MetaMethod) {
                createMetaBeanProperty(propertyIndex, propName, isGetter, (MetaMethod) propertyMethods);
            } else {
                LinkedList<MetaMethod> methods = (LinkedList<MetaMethod>) propertyMethods;
                for (MetaMethod m : methods) {
                    createMetaBeanProperty(propertyIndex, propName, isGetter, m);
                }
            }
        }
    }
}
Also used : SingleKeyHashMap(org.codehaus.groovy.util.SingleKeyHashMap) 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) CachedClass(org.codehaus.groovy.reflection.CachedClass)

Example 29 with CachedClass

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

the class MetaClassImpl method inheritFields.

private void inheritFields(LinkedList<CachedClass> superClasses) {
    SingleKeyHashMap last = null;
    for (CachedClass klass : superClasses) {
        SingleKeyHashMap propertyIndex = classPropertyIndex.getNotNull(klass);
        if (last != null) {
            copyNonPrivateFields(last, propertyIndex);
        }
        last = propertyIndex;
        addFields(klass, propertyIndex);
    }
}
Also used : SingleKeyHashMap(org.codehaus.groovy.util.SingleKeyHashMap) CachedClass(org.codehaus.groovy.reflection.CachedClass)

Example 30 with CachedClass

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

the class MetaClassImpl method fillMethodIndex.

/**
     * Fills the method index
     */
private void fillMethodIndex() {
    mainClassMethodHeader = metaMethodIndex.getHeader(theClass);
    LinkedList<CachedClass> superClasses = getSuperClasses();
    CachedClass firstGroovySuper = calcFirstGroovySuperClass(superClasses);
    Set<CachedClass> interfaces = theCachedClass.getInterfaces();
    addInterfaceMethods(interfaces);
    populateMethods(superClasses, firstGroovySuper);
    inheritInterfaceNewMetaMethods(interfaces);
    if (isGroovyObject) {
        metaMethodIndex.copyMethodsToSuper();
        connectMultimethods(superClasses, firstGroovySuper);
        removeMultimethodsOverloadedWithPrivateMethods();
        replaceWithMOPCalls(theCachedClass.mopMethods);
    }
}
Also used : 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