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