use of org.codehaus.groovy.util.SingleKeyHashMap in project groovy by apache.
the class MetaClassImpl method applyStrayPropertyMethods.
private void applyStrayPropertyMethods(LinkedList<CachedClass> superClasses, Index classPropertyIndex, boolean isThis) {
// now look for any stray getters that may be used to define a property
for (CachedClass klass : superClasses) {
MetaMethodIndex.Header header = metaMethodIndex.getHeader(klass.getTheClass());
SingleKeyHashMap propertyIndex = classPropertyIndex.getNotNull(klass);
for (MetaMethodIndex.Entry e = header.head; e != null; e = e.nextClassEntry) {
String methodName = e.name;
// name too short?
if (methodName.length() < 3 || (!methodName.startsWith("is") && methodName.length() < 4))
continue;
// possible getter/setter?
boolean isGetter = methodName.startsWith("get") || methodName.startsWith("is");
boolean isBooleanGetter = methodName.startsWith("is");
boolean isSetter = methodName.startsWith("set");
if (!isGetter && !isSetter)
continue;
Object propertyMethods = filterPropertyMethod(isThis ? e.methods : e.methodsForSuper, isGetter, isBooleanGetter);
if (propertyMethods == null)
continue;
String propName = getPropName(methodName);
if (propertyMethods instanceof MetaMethod) {
createMetaBeanProperty(propertyIndex, propName, isGetter, (MetaMethod) propertyMethods);
} else {
LinkedList<MetaMethod> methods = (LinkedList<MetaMethod>) propertyMethods;
for (MetaMethod m : methods) {
createMetaBeanProperty(propertyIndex, propName, isGetter, m);
}
}
}
}
}
use of org.codehaus.groovy.util.SingleKeyHashMap in project groovy by apache.
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 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.util.SingleKeyHashMap in project groovy by apache.
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();
}
}
use of org.codehaus.groovy.util.SingleKeyHashMap in project groovy-core by groovy.
the class MetaClassImpl method applyStrayPropertyMethods.
private void applyStrayPropertyMethods(LinkedList<CachedClass> superClasses, Index classPropertyIndex, boolean isThis) {
// now look for any stray getters that may be used to define a property
for (CachedClass klass : superClasses) {
MetaMethodIndex.Header header = metaMethodIndex.getHeader(klass.getTheClass());
SingleKeyHashMap propertyIndex = classPropertyIndex.getNotNull(klass);
for (MetaMethodIndex.Entry e = header.head; e != null; e = e.nextClassEntry) {
String methodName = e.name;
// name too short?
if (methodName.length() < 3 || (!methodName.startsWith("is") && methodName.length() < 4))
continue;
// possible getter/setter?
boolean isGetter = methodName.startsWith("get") || methodName.startsWith("is");
boolean isBooleanGetter = methodName.startsWith("is");
boolean isSetter = methodName.startsWith("set");
if (!isGetter && !isSetter)
continue;
Object propertyMethods = filterPropertyMethod(isThis ? e.methods : e.methodsForSuper, isGetter, isBooleanGetter);
if (propertyMethods == null)
continue;
String propName = getPropName(methodName);
if (propertyMethods instanceof MetaMethod) {
createMetaBeanProperty(propertyIndex, propName, isGetter, (MetaMethod) propertyMethods);
} else {
LinkedList<MetaMethod> methods = (LinkedList<MetaMethod>) propertyMethods;
for (MetaMethod m : methods) {
createMetaBeanProperty(propertyIndex, propName, isGetter, m);
}
}
}
}
}
Aggregations