Search in sources :

Example 1 with CachedField

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

the class MetaClassImpl method makeReplacementMetaProperty.

private static MetaProperty makeReplacementMetaProperty(MetaProperty mp, String propName, boolean isGetter, MetaMethod propertyMethod) {
    if (mp == null) {
        if (isGetter) {
            return new MetaBeanProperty(propName, propertyMethod.getReturnType(), propertyMethod, null);
        } else {
            //isSetter
            return new MetaBeanProperty(propName, propertyMethod.getParameterTypes()[0].getTheClass(), null, propertyMethod);
        }
    }
    if (mp instanceof CachedField) {
        CachedField mfp = (CachedField) mp;
        MetaBeanProperty mbp = new MetaBeanProperty(propName, mfp.getType(), isGetter ? propertyMethod : null, isGetter ? null : propertyMethod);
        mbp.setField(mfp);
        return mbp;
    } else if (mp instanceof MultipleSetterProperty) {
        MultipleSetterProperty msp = (MultipleSetterProperty) mp;
        if (isGetter) {
            msp.setGetter(propertyMethod);
        }
        return msp;
    } else if (mp instanceof MetaBeanProperty) {
        MetaBeanProperty mbp = (MetaBeanProperty) mp;
        if (isGetter) {
            mbp.setGetter(propertyMethod);
            return mbp;
        } else if (mbp.getSetter() == null || mbp.getSetter() == propertyMethod) {
            mbp.setSetter(propertyMethod);
            return mbp;
        } else {
            MultipleSetterProperty msp = new MultipleSetterProperty(propName);
            msp.setField(mbp.getField());
            msp.setGetter(mbp.getGetter());
            return msp;
        }
    } else {
        throw new GroovyBugError("unknown MetaProperty class used. Class is " + mp.getClass());
    }
}
Also used : MultipleSetterProperty(org.codehaus.groovy.runtime.metaclass.MultipleSetterProperty) GroovyBugError(org.codehaus.groovy.GroovyBugError) CachedField(org.codehaus.groovy.reflection.CachedField)

Example 2 with CachedField

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

the class MetaClassImpl method establishStaticMetaProperty.

private static MetaProperty establishStaticMetaProperty(MetaProperty mp) {
    MetaBeanProperty mbp = (MetaBeanProperty) mp;
    MetaProperty result = null;
    final MetaMethod getterMethod = mbp.getGetter();
    final MetaMethod setterMethod = mbp.getSetter();
    final CachedField metaField = mbp.getField();
    boolean getter = getterMethod == null || getterMethod.isStatic();
    boolean setter = setterMethod == null || setterMethod.isStatic();
    boolean field = metaField == null || metaField.isStatic();
    if (!getter && !setter && !field) {
        return result;
    } else {
        final String propertyName = mbp.getName();
        final Class propertyType = mbp.getType();
        if (setter && getter) {
            if (field) {
                // nothing to do
                result = mbp;
            } else {
                result = new MetaBeanProperty(propertyName, propertyType, getterMethod, setterMethod);
            }
        } else if (getter && !setter) {
            if (getterMethod == null) {
                result = metaField;
            } else {
                MetaBeanProperty newmp = new MetaBeanProperty(propertyName, propertyType, getterMethod, null);
                if (field)
                    newmp.setField(metaField);
                result = newmp;
            }
        } else if (setter && !getter) {
            if (setterMethod == null) {
                result = metaField;
            } else {
                MetaBeanProperty newmp = new MetaBeanProperty(propertyName, propertyType, null, setterMethod);
                if (field)
                    newmp.setField(metaField);
                result = newmp;
            }
        } else
            result = metaField;
    }
    return result;
}
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) GetMethodMetaProperty(org.codehaus.groovy.runtime.metaclass.MethodMetaProperty.GetMethodMetaProperty) GetBeanMethodMetaProperty(org.codehaus.groovy.runtime.metaclass.MethodMetaProperty.GetBeanMethodMetaProperty) CachedField(org.codehaus.groovy.reflection.CachedField)

Example 3 with CachedField

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

the class MetaClassImpl method copyNonPrivateFields.

private static void copyNonPrivateFields(SingleKeyHashMap from, SingleKeyHashMap to, CachedClass klass) {
    for (ComplexKeyHashMap.EntryIterator iter = from.getEntrySetIterator(); iter.hasNext(); ) {
        SingleKeyHashMap.Entry entry = (SingleKeyHashMap.Entry) iter.next();
        CachedField mfp = (CachedField) entry.getValue();
        if (!inheritedOrPublic(mfp) && !packageLocal(mfp, klass))
            continue;
        to.put(entry.getKey(), mfp);
    }
}
Also used : SingleKeyHashMap(org.codehaus.groovy.util.SingleKeyHashMap) ComplexKeyHashMap(org.codehaus.groovy.util.ComplexKeyHashMap) CachedField(org.codehaus.groovy.reflection.CachedField)

Example 4 with CachedField

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

the class MetaClassImpl method makeReplacementMetaProperty.

private MetaProperty makeReplacementMetaProperty(MetaProperty mp, String propName, boolean isGetter, MetaMethod propertyMethod) {
    if (mp == null) {
        if (isGetter) {
            return new MetaBeanProperty(propName, propertyMethod.getReturnType(), propertyMethod, null);
        } else {
            //isSetter
            return new MetaBeanProperty(propName, propertyMethod.getParameterTypes()[0].getTheClass(), null, propertyMethod);
        }
    }
    if (mp instanceof CachedField) {
        CachedField mfp = (CachedField) mp;
        MetaBeanProperty mbp = new MetaBeanProperty(propName, mfp.getType(), isGetter ? propertyMethod : null, isGetter ? null : propertyMethod);
        mbp.setField(mfp);
        return mbp;
    } else if (mp instanceof MultipleSetterProperty) {
        MultipleSetterProperty msp = (MultipleSetterProperty) mp;
        if (isGetter) {
            msp.setGetter(propertyMethod);
        }
        return msp;
    } else if (mp instanceof MetaBeanProperty) {
        MetaBeanProperty mbp = (MetaBeanProperty) mp;
        if (isGetter) {
            mbp.setGetter(propertyMethod);
            return mbp;
        } else if (mbp.getSetter() == null || mbp.getSetter() == propertyMethod) {
            mbp.setSetter(propertyMethod);
            return mbp;
        } else {
            MultipleSetterProperty msp = new MultipleSetterProperty(propName);
            msp.setField(mbp.getField());
            msp.setGetter(mbp.getGetter());
            return msp;
        }
    } else {
        throw new GroovyBugError("unknown MetaProperty class used. Class is " + mp.getClass());
    }
}
Also used : MultipleSetterProperty(org.codehaus.groovy.runtime.metaclass.MultipleSetterProperty) GroovyBugError(org.codehaus.groovy.GroovyBugError) CachedField(org.codehaus.groovy.reflection.CachedField)

Example 5 with CachedField

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

the class MetaClassImpl method copyNonPrivateFields.

private void copyNonPrivateFields(SingleKeyHashMap from, SingleKeyHashMap to) {
    for (ComplexKeyHashMap.EntryIterator iter = from.getEntrySetIterator(); iter.hasNext(); ) {
        SingleKeyHashMap.Entry entry = (SingleKeyHashMap.Entry) iter.next();
        CachedField mfp = (CachedField) entry.getValue();
        if (!Modifier.isPublic(mfp.getModifiers()) && !Modifier.isProtected(mfp.getModifiers()))
            continue;
        to.put(entry.getKey(), mfp);
    }
}
Also used : SingleKeyHashMap(org.codehaus.groovy.util.SingleKeyHashMap) ComplexKeyHashMap(org.codehaus.groovy.util.ComplexKeyHashMap) CachedField(org.codehaus.groovy.reflection.CachedField)

Aggregations

CachedField (org.codehaus.groovy.reflection.CachedField)12 GetBeanMethodMetaProperty (org.codehaus.groovy.runtime.metaclass.MethodMetaProperty.GetBeanMethodMetaProperty)8 GetMethodMetaProperty (org.codehaus.groovy.runtime.metaclass.MethodMetaProperty.GetMethodMetaProperty)8 SingleKeyHashMap (org.codehaus.groovy.util.SingleKeyHashMap)8 MultipleSetterProperty (org.codehaus.groovy.runtime.metaclass.MultipleSetterProperty)6 ComplexKeyHashMap (org.codehaus.groovy.util.ComplexKeyHashMap)6 GeneratedMetaMethod (org.codehaus.groovy.reflection.GeneratedMetaMethod)4 NewInstanceMetaMethod (org.codehaus.groovy.runtime.metaclass.NewInstanceMetaMethod)4 GroovyBugError (org.codehaus.groovy.GroovyBugError)2 CachedClass (org.codehaus.groovy.reflection.CachedClass)2 ClosureMetaMethod (org.codehaus.groovy.runtime.metaclass.ClosureMetaMethod)2 MixinInstanceMetaMethod (org.codehaus.groovy.runtime.metaclass.MixinInstanceMetaMethod)2 NewMetaMethod (org.codehaus.groovy.runtime.metaclass.NewMetaMethod)2 NewStaticMetaMethod (org.codehaus.groovy.runtime.metaclass.NewStaticMetaMethod)2 TransformMetaMethod (org.codehaus.groovy.runtime.metaclass.TransformMetaMethod)2