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());
}
}
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());
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations