Search in sources :

Example 31 with CachedClass

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

the class MetaClassImpl method getCategoryMethodSetter.

private static MetaMethod getCategoryMethodSetter(Class sender, String name, boolean useLongVersion) {
    List possibleGenericMethods = GroovyCategorySupport.getCategoryMethods(name);
    if (possibleGenericMethods != null) {
        for (Iterator iter = possibleGenericMethods.iterator(); iter.hasNext(); ) {
            MetaMethod mmethod = (MetaMethod) iter.next();
            if (!mmethod.getDeclaringClass().getTheClass().isAssignableFrom(sender))
                continue;
            CachedClass[] paramTypes = mmethod.getParameterTypes();
            if (useLongVersion) {
                if (paramTypes.length == 2 && paramTypes[0].getTheClass() == String.class) {
                    return mmethod;
                }
            } else {
                if (paramTypes.length == 1)
                    return mmethod;
            }
        }
    }
    return null;
}
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) CachedClass(org.codehaus.groovy.reflection.CachedClass)

Example 32 with CachedClass

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

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

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

the class MetaClassImpl method getCategoryMethodGetter.

private static MetaMethod getCategoryMethodGetter(Class sender, String name, boolean useLongVersion) {
    List possibleGenericMethods = GroovyCategorySupport.getCategoryMethods(name);
    if (possibleGenericMethods != null) {
        for (Iterator iter = possibleGenericMethods.iterator(); iter.hasNext(); ) {
            MetaMethod mmethod = (MetaMethod) iter.next();
            if (!mmethod.getDeclaringClass().getTheClass().isAssignableFrom(sender))
                continue;
            CachedClass[] paramTypes = mmethod.getParameterTypes();
            if (useLongVersion) {
                if (paramTypes.length == 1 && paramTypes[0].getTheClass() == String.class) {
                    return mmethod;
                }
            } else {
                if (paramTypes.length == 0)
                    return mmethod;
            }
        }
    }
    return null;
}
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) CachedClass(org.codehaus.groovy.reflection.CachedClass)

Example 34 with CachedClass

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

the class MetaClassImpl method getMetaProperty.

private MetaProperty getMetaProperty(String name, boolean useStatic) {
    CachedClass clazz = theCachedClass;
    SingleKeyHashMap propertyMap;
    if (useStatic) {
        propertyMap = staticPropertyIndex;
    } else {
        propertyMap = classPropertyIndex.getNullable(clazz);
    }
    if (propertyMap == null) {
        return null;
    }
    return (MetaProperty) propertyMap.get(name);
}
Also used : SingleKeyHashMap(org.codehaus.groovy.util.SingleKeyHashMap) CachedClass(org.codehaus.groovy.reflection.CachedClass) GetMethodMetaProperty(org.codehaus.groovy.runtime.metaclass.MethodMetaProperty.GetMethodMetaProperty) GetBeanMethodMetaProperty(org.codehaus.groovy.runtime.metaclass.MethodMetaProperty.GetBeanMethodMetaProperty)

Example 35 with CachedClass

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

the class MetaClassImpl method findPropertyInClassHierarchy.

protected MetaBeanProperty findPropertyInClassHierarchy(String propertyName, CachedClass theClass) {
    MetaBeanProperty property = null;
    if (theClass == null)
        return null;
    final CachedClass superClass = theClass.getCachedSuperClass();
    if (superClass == null)
        return null;
    MetaClass metaClass = this.registry.getMetaClass(superClass.getTheClass());
    if (metaClass instanceof MutableMetaClass) {
        property = getMetaPropertyFromMutableMetaClass(propertyName, metaClass);
        if (property == null) {
            if (superClass != ReflectionCache.OBJECT_CLASS) {
                property = findPropertyInClassHierarchy(propertyName, superClass);
            }
            if (property == null) {
                final Class[] interfaces = theClass.getTheClass().getInterfaces();
                property = searchInterfacesForMetaProperty(propertyName, interfaces);
            }
        }
    }
    return property;
}
Also used : CachedClass(org.codehaus.groovy.reflection.CachedClass) 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