use of org.codehaus.groovy.reflection.CachedClass in project groovy by apache.
the class MetaClassImpl method findMatchingMethod.
private int findMatchingMethod(CachedMethod[] data, int from, int to, MetaMethod method) {
for (int j = from; j <= to; ++j) {
CachedMethod aMethod = data[j];
CachedClass[] params1 = aMethod.getParameterTypes();
CachedClass[] params2 = method.getParameterTypes();
if (params1.length == params2.length) {
boolean matches = true;
for (int i = 0; i < params1.length; i++) {
if (params1[i] != params2[i]) {
matches = false;
break;
}
}
if (matches) {
return j;
}
}
}
return -1;
}
use of org.codehaus.groovy.reflection.CachedClass in project groovy by apache.
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, klass);
}
last = propertyIndex;
addFields(klass, propertyIndex);
}
}
use of org.codehaus.groovy.reflection.CachedClass in project groovy by apache.
the class MetaClassImpl method inheritStaticInterfaceFields.
private void inheritStaticInterfaceFields(LinkedList superClasses, Set interfaces) {
for (Iterator interfaceIter = interfaces.iterator(); interfaceIter.hasNext(); ) {
CachedClass iclass = (CachedClass) interfaceIter.next();
SingleKeyHashMap iPropertyIndex = classPropertyIndex.getNotNull(iclass);
addFields(iclass, iPropertyIndex);
for (Iterator classIter = superClasses.iterator(); classIter.hasNext(); ) {
CachedClass sclass = (CachedClass) classIter.next();
if (!iclass.getTheClass().isAssignableFrom(sclass.getTheClass()))
continue;
SingleKeyHashMap sPropertyIndex = classPropertyIndex.getNotNull(sclass);
copyNonPrivateFields(iPropertyIndex, sPropertyIndex);
}
}
}
use of org.codehaus.groovy.reflection.CachedClass in project groovy by apache.
the class MetaClassHelper method calculateParameterDistance.
public static long calculateParameterDistance(Class[] arguments, ParameterTypes pt) {
CachedClass[] parameters = pt.getParameterTypes();
if (parameters.length == 0)
return 0;
long ret = 0;
int noVargsLength = parameters.length - 1;
// we can safely iterate to this point
for (int i = 0; i < noVargsLength; i++) {
ret += calculateParameterDistance(arguments[i], parameters[i]);
}
if (arguments.length == parameters.length) {
// case C&D, we use baseType to calculate and set it
// to the value we need according to case C and D
// case C
CachedClass baseType = parameters[noVargsLength];
if (!parameters[noVargsLength].isAssignableFrom(arguments[noVargsLength])) {
// case D
baseType = ReflectionCache.getCachedClass(baseType.getTheClass().getComponentType());
// penalty for vargs
ret += 2L << VARGS_SHIFT;
}
ret += calculateParameterDistance(arguments[noVargsLength], baseType);
} else if (arguments.length > parameters.length) {
// case B
// we give our a vargs penalty for each exceeding argument and iterate
// by using parameters[noVargsLength].getComponentType()
// penalty for vargs
ret += (2L + arguments.length - parameters.length) << VARGS_SHIFT;
CachedClass vargsType = ReflectionCache.getCachedClass(parameters[noVargsLength].getTheClass().getComponentType());
for (int i = noVargsLength; i < arguments.length; i++) {
ret += calculateParameterDistance(arguments[i], vargsType);
}
} else {
// case A
// we give a penalty for vargs, since we have no direct
// match for the last argument
ret += 1L << VARGS_SHIFT;
}
return ret;
}
use of org.codehaus.groovy.reflection.CachedClass in project groovy by apache.
the class CallSiteGenerator method compilePojoMethod.
public static Constructor compilePojoMethod(CachedMethod cachedMethod) {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
final CachedClass declClass = cachedMethod.getDeclaringClass();
final CallSiteClassLoader callSiteLoader = declClass.getCallSiteLoader();
final String name = callSiteLoader.createClassName(cachedMethod.setAccessible());
final byte[] bytes = genPojoMetaMethodSite(cachedMethod, cw, name);
return callSiteLoader.defineClassAndGetConstructor(name, bytes);
}
Aggregations