use of org.codehaus.groovy.reflection.CachedClass in project groovy-core by groovy.
the class MetaClassImpl method populateMethods.
private void populateMethods(LinkedList<CachedClass> superClasses, CachedClass firstGroovySuper) {
MetaMethodIndex.Header header = metaMethodIndex.getHeader(firstGroovySuper.getTheClass());
CachedClass c;
Iterator<CachedClass> iter = superClasses.iterator();
for (; iter.hasNext(); ) {
c = iter.next();
CachedMethod[] cachedMethods = c.getMethods();
for (CachedMethod metaMethod : cachedMethods) {
addToAllMethodsIfPublic(metaMethod);
if (!metaMethod.isPrivate() || c == firstGroovySuper)
addMetaMethodToIndex(metaMethod, header);
}
MetaMethod[] cachedMethods1 = getNewMetaMethods(c);
for (final MetaMethod method : cachedMethods1) {
if (!newGroovyMethodsSet.contains(method)) {
newGroovyMethodsSet.add(method);
addMetaMethodToIndex(method, header);
}
}
if (c == firstGroovySuper)
break;
}
MetaMethodIndex.Header last = header;
for (; iter.hasNext(); ) {
c = iter.next();
header = metaMethodIndex.getHeader(c.getTheClass());
if (last != null) {
metaMethodIndex.copyNonPrivateMethods(last, header);
}
last = header;
for (CachedMethod metaMethod : c.getMethods()) {
addToAllMethodsIfPublic(metaMethod);
addMetaMethodToIndex(metaMethod, header);
}
for (final MetaMethod method : getNewMetaMethods(c)) {
if (method.getName().equals("<init>") && !method.getDeclaringClass().equals(theCachedClass))
continue;
if (!newGroovyMethodsSet.contains(method)) {
newGroovyMethodsSet.add(method);
addMetaMethodToIndex(method, header);
}
}
}
}
use of org.codehaus.groovy.reflection.CachedClass in project groovy-core by groovy.
the class MetaClassImpl method connectMultimethods.
private void connectMultimethods(List<CachedClass> superClasses, CachedClass firstGroovyClass) {
superClasses = DefaultGroovyMethods.reverse(superClasses);
MetaMethodIndex.Header last = null;
for (final CachedClass c : superClasses) {
MetaMethodIndex.Header methodIndex = metaMethodIndex.getHeader(c.getTheClass());
// It saves us a lot of space and some noticeable time
if (last != null)
metaMethodIndex.copyNonPrivateNonNewMetaMethods(last, methodIndex);
last = methodIndex;
if (c == firstGroovyClass)
break;
}
}
use of org.codehaus.groovy.reflection.CachedClass 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);
}
}
}
}
}
use of org.codehaus.groovy.reflection.CachedClass in project groovy-core by groovy.
the class MetaClassImpl method inheritFields.
private void inheritFields(LinkedList<CachedClass> superClasses) {
SingleKeyHashMap last = null;
for (CachedClass klass : superClasses) {
SingleKeyHashMap propertyIndex = classPropertyIndex.getNotNull(klass);
if (last != null) {
copyNonPrivateFields(last, propertyIndex);
}
last = propertyIndex;
addFields(klass, propertyIndex);
}
}
use of org.codehaus.groovy.reflection.CachedClass in project groovy-core by groovy.
the class MetaClassImpl method fillMethodIndex.
/**
* Fills the method index
*/
private void fillMethodIndex() {
mainClassMethodHeader = metaMethodIndex.getHeader(theClass);
LinkedList<CachedClass> superClasses = getSuperClasses();
CachedClass firstGroovySuper = calcFirstGroovySuperClass(superClasses);
Set<CachedClass> interfaces = theCachedClass.getInterfaces();
addInterfaceMethods(interfaces);
populateMethods(superClasses, firstGroovySuper);
inheritInterfaceNewMetaMethods(interfaces);
if (isGroovyObject) {
metaMethodIndex.copyMethodsToSuper();
connectMultimethods(superClasses, firstGroovySuper);
removeMultimethodsOverloadedWithPrivateMethods();
replaceWithMOPCalls(theCachedClass.mopMethods);
}
}
Aggregations