Search in sources :

Example 1 with MultipleSetterProperty

use of org.codehaus.groovy.runtime.metaclass.MultipleSetterProperty 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 MultipleSetterProperty

use of org.codehaus.groovy.runtime.metaclass.MultipleSetterProperty 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 3 with MultipleSetterProperty

use of org.codehaus.groovy.runtime.metaclass.MultipleSetterProperty in project groovy-core by groovy.

the class MetaClassImpl method addMetaBeanProperty.

/**
     * Adds a new MetaBeanProperty to this MetaClass
     *
     * @param mp The MetaBeanProperty
     */
public void addMetaBeanProperty(MetaBeanProperty mp) {
    MetaProperty staticProperty = establishStaticMetaProperty(mp);
    if (staticProperty != null) {
        staticPropertyIndex.put(mp.getName(), mp);
    } else {
        SingleKeyHashMap propertyMap = classPropertyIndex.getNotNull(theCachedClass);
        //keep field
        CachedField field;
        MetaProperty old = (MetaProperty) propertyMap.get(mp.getName());
        if (old != null) {
            if (old instanceof MetaBeanProperty) {
                field = ((MetaBeanProperty) old).getField();
            } else if (old instanceof MultipleSetterProperty) {
                field = ((MultipleSetterProperty) old).getField();
            } else {
                field = (CachedField) old;
            }
            mp.setField(field);
        }
        // put it in the list
        // this will overwrite a possible field property
        propertyMap.put(mp.getName(), mp);
    }
}
Also used : SingleKeyHashMap(org.codehaus.groovy.util.SingleKeyHashMap) MultipleSetterProperty(org.codehaus.groovy.runtime.metaclass.MultipleSetterProperty) GetMethodMetaProperty(org.codehaus.groovy.runtime.metaclass.MethodMetaProperty.GetMethodMetaProperty) GetBeanMethodMetaProperty(org.codehaus.groovy.runtime.metaclass.MethodMetaProperty.GetBeanMethodMetaProperty) CachedField(org.codehaus.groovy.reflection.CachedField)

Example 4 with MultipleSetterProperty

use of org.codehaus.groovy.runtime.metaclass.MultipleSetterProperty in project groovy-core by groovy.

the class MetaClassImpl method makeStaticPropertyIndex.

private void makeStaticPropertyIndex() {
    SingleKeyHashMap propertyMap = classPropertyIndex.getNotNull(theCachedClass);
    for (ComplexKeyHashMap.EntryIterator iter = propertyMap.getEntrySetIterator(); iter.hasNext(); ) {
        SingleKeyHashMap.Entry entry = ((SingleKeyHashMap.Entry) iter.next());
        MetaProperty mp = (MetaProperty) entry.getValue();
        if (mp instanceof CachedField) {
            CachedField mfp = (CachedField) mp;
            if (!mfp.isStatic())
                continue;
        } else if (mp instanceof MetaBeanProperty) {
            MetaProperty result = establishStaticMetaProperty(mp);
            if (result == null)
                continue;
            else {
                mp = result;
            }
        } else if (mp instanceof MultipleSetterProperty) {
            MultipleSetterProperty msp = (MultipleSetterProperty) mp;
            mp = msp.createStaticVersion();
        } else {
            // ignore all other types
            continue;
        }
        staticPropertyIndex.put(entry.getKey(), mp);
    }
}
Also used : SingleKeyHashMap(org.codehaus.groovy.util.SingleKeyHashMap) MultipleSetterProperty(org.codehaus.groovy.runtime.metaclass.MultipleSetterProperty) ComplexKeyHashMap(org.codehaus.groovy.util.ComplexKeyHashMap) GetMethodMetaProperty(org.codehaus.groovy.runtime.metaclass.MethodMetaProperty.GetMethodMetaProperty) GetBeanMethodMetaProperty(org.codehaus.groovy.runtime.metaclass.MethodMetaProperty.GetBeanMethodMetaProperty) CachedField(org.codehaus.groovy.reflection.CachedField)

Example 5 with MultipleSetterProperty

use of org.codehaus.groovy.runtime.metaclass.MultipleSetterProperty in project groovy by apache.

the class MetaClassImpl method addMetaBeanProperty.

/**
     * Adds a new MetaBeanProperty to this MetaClass
     *
     * @param mp The MetaBeanProperty
     */
public void addMetaBeanProperty(MetaBeanProperty mp) {
    MetaProperty staticProperty = establishStaticMetaProperty(mp);
    if (staticProperty != null) {
        staticPropertyIndex.put(mp.getName(), mp);
    } else {
        SingleKeyHashMap propertyMap = classPropertyIndex.getNotNull(theCachedClass);
        //keep field
        CachedField field;
        MetaProperty old = (MetaProperty) propertyMap.get(mp.getName());
        if (old != null) {
            if (old instanceof MetaBeanProperty) {
                field = ((MetaBeanProperty) old).getField();
            } else if (old instanceof MultipleSetterProperty) {
                field = ((MultipleSetterProperty) old).getField();
            } else {
                field = (CachedField) old;
            }
            mp.setField(field);
        }
        // put it in the list
        // this will overwrite a possible field property
        propertyMap.put(mp.getName(), mp);
    }
}
Also used : SingleKeyHashMap(org.codehaus.groovy.util.SingleKeyHashMap) MultipleSetterProperty(org.codehaus.groovy.runtime.metaclass.MultipleSetterProperty) GetMethodMetaProperty(org.codehaus.groovy.runtime.metaclass.MethodMetaProperty.GetMethodMetaProperty) GetBeanMethodMetaProperty(org.codehaus.groovy.runtime.metaclass.MethodMetaProperty.GetBeanMethodMetaProperty) CachedField(org.codehaus.groovy.reflection.CachedField)

Aggregations

CachedField (org.codehaus.groovy.reflection.CachedField)6 MultipleSetterProperty (org.codehaus.groovy.runtime.metaclass.MultipleSetterProperty)6 GetBeanMethodMetaProperty (org.codehaus.groovy.runtime.metaclass.MethodMetaProperty.GetBeanMethodMetaProperty)4 GetMethodMetaProperty (org.codehaus.groovy.runtime.metaclass.MethodMetaProperty.GetMethodMetaProperty)4 SingleKeyHashMap (org.codehaus.groovy.util.SingleKeyHashMap)4 GroovyBugError (org.codehaus.groovy.GroovyBugError)2 ComplexKeyHashMap (org.codehaus.groovy.util.ComplexKeyHashMap)2