use of org.codehaus.groovy.reflection.CachedClass in project groovy by apache.
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 by apache.
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);
}
}
use of org.codehaus.groovy.reflection.CachedClass in project groovy by apache.
the class MetaClassImpl method getMatchKindForCategory.
/**
* return false: add method
* null: ignore method
* true: replace
*/
private static Boolean getMatchKindForCategory(MetaMethod aMethod, MetaMethod categoryMethod) {
CachedClass[] params1 = aMethod.getParameterTypes();
CachedClass[] params2 = categoryMethod.getParameterTypes();
if (params1.length != params2.length)
return Boolean.FALSE;
for (int i = 0; i < params1.length; i++) {
if (params1[i] != params2[i])
return Boolean.FALSE;
}
Class aMethodClass = aMethod.getDeclaringClass().getTheClass();
Class categoryMethodClass = categoryMethod.getDeclaringClass().getTheClass();
if (aMethodClass == categoryMethodClass)
return Boolean.TRUE;
boolean match = aMethodClass.isAssignableFrom(categoryMethodClass);
if (match)
return Boolean.TRUE;
return null;
}
use of org.codehaus.groovy.reflection.CachedClass in project groovy by apache.
the class MetaClassImpl method getCategoryMethodSetter.
private static MetaMethod getCategoryMethodSetter(Class sender, String name, boolean useLongVersion) {
List possibleGenericMethods = GroovyCategorySupport.getCategoryMethods(name);
if (possibleGenericMethods != null) {
for (Iterator iter = possibleGenericMethods.iterator(); iter.hasNext(); ) {
MetaMethod mmethod = (MetaMethod) iter.next();
if (!mmethod.getDeclaringClass().getTheClass().isAssignableFrom(sender))
continue;
CachedClass[] paramTypes = mmethod.getParameterTypes();
if (useLongVersion) {
if (paramTypes.length == 2 && paramTypes[0].getTheClass() == String.class) {
return mmethod;
}
} else {
if (paramTypes.length == 1)
return mmethod;
}
}
}
return null;
}
use of org.codehaus.groovy.reflection.CachedClass 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);
}
}
}
}
}
Aggregations