use of org.codehaus.groovy.util.SingleKeyHashMap 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.util.SingleKeyHashMap in project groovy-core by groovy.
the class MetaClassImpl method getProperties.
/**
* Get all the properties defined for this type
*
* @return a list of MetaProperty objects
*/
public List<MetaProperty> getProperties() {
checkInitalised();
SingleKeyHashMap propertyMap = classPropertyIndex.getNullable(theCachedClass);
if (propertyMap == null) {
// GROOVY-6903: May happen in some special environment, like under Android, due
// to classloading issues
propertyMap = new SingleKeyHashMap();
}
// simply return the values of the metaproperty map as a List
List ret = new ArrayList(propertyMap.size());
for (ComplexKeyHashMap.EntryIterator iter = propertyMap.getEntrySetIterator(); iter.hasNext(); ) {
MetaProperty element = (MetaProperty) ((SingleKeyHashMap.Entry) iter.next()).value;
if (element instanceof CachedField)
continue;
// filter out DGM beans
if (element instanceof MetaBeanProperty) {
MetaBeanProperty mp = (MetaBeanProperty) element;
boolean setter = true;
boolean getter = true;
if (mp.getGetter() == null || mp.getGetter() instanceof GeneratedMetaMethod || mp.getGetter() instanceof NewInstanceMetaMethod) {
getter = false;
}
if (mp.getSetter() == null || mp.getSetter() instanceof GeneratedMetaMethod || mp.getSetter() instanceof NewInstanceMetaMethod) {
setter = false;
}
if (!setter && !getter)
continue;
// TODO: I (ait) don't know why these strange tricks needed and comment following as it effects some Grails tests
// if (!setter && mp.getSetter() != null) {
// element = new MetaBeanProperty(mp.getName(), mp.getType(), mp.getGetter(), null);
// }
// if (!getter && mp.getGetter() != null) {
// element = new MetaBeanProperty(mp.getName(), mp.getType(), null, mp.getSetter());
// }
}
ret.add(element);
}
return ret;
}
use of org.codehaus.groovy.util.SingleKeyHashMap 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);
}
}
use of org.codehaus.groovy.util.SingleKeyHashMap in project groovy-core by groovy.
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);
}
use of org.codehaus.groovy.util.SingleKeyHashMap in project groovy-core by groovy.
the class MetaClassImpl method setupProperties.
/**
* This will build up the property map (Map of MetaProperty objects, keyed on
* property name).
*
* @param propertyDescriptors
*/
@SuppressWarnings("unchecked")
private void setupProperties(PropertyDescriptor[] propertyDescriptors) {
if (theCachedClass.isInterface) {
LinkedList<CachedClass> superClasses = new LinkedList<CachedClass>();
superClasses.add(ReflectionCache.OBJECT_CLASS);
Set interfaces = theCachedClass.getInterfaces();
LinkedList<CachedClass> superInterfaces = new LinkedList<CachedClass>(interfaces);
// ambiguous fields (class implementing two interfaces using the same field)
if (superInterfaces.size() > 1) {
Collections.sort(superInterfaces, CACHED_CLASS_NAME_COMPARATOR);
}
SingleKeyHashMap iPropertyIndex = classPropertyIndex.getNotNull(theCachedClass);
for (CachedClass iclass : superInterfaces) {
SingleKeyHashMap sPropertyIndex = classPropertyIndex.getNotNull(iclass);
copyNonPrivateFields(sPropertyIndex, iPropertyIndex);
addFields(iclass, iPropertyIndex);
}
addFields(theCachedClass, iPropertyIndex);
applyPropertyDescriptors(propertyDescriptors);
applyStrayPropertyMethods(superClasses, classPropertyIndex, true);
makeStaticPropertyIndex();
} else {
LinkedList<CachedClass> superClasses = getSuperClasses();
LinkedList<CachedClass> interfaces = new LinkedList<CachedClass>(theCachedClass.getInterfaces());
// ambiguous fields (class implementing two interfaces using the same field)
if (interfaces.size() > 1) {
Collections.sort(interfaces, CACHED_CLASS_NAME_COMPARATOR);
}
// if this an Array, then add the special read-only "length" property
if (theCachedClass.isArray) {
SingleKeyHashMap map = new SingleKeyHashMap();
map.put("length", arrayLengthProperty);
classPropertyIndex.put(theCachedClass, map);
}
inheritStaticInterfaceFields(superClasses, new LinkedHashSet(interfaces));
inheritFields(superClasses);
applyPropertyDescriptors(propertyDescriptors);
applyStrayPropertyMethods(superClasses, classPropertyIndex, true);
applyStrayPropertyMethods(superClasses, classPropertyIndexForSuper, false);
copyClassPropertyIndexForSuper(classPropertyIndexForSuper);
makeStaticPropertyIndex();
}
}
Aggregations