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 MetaClassImpl method addInterfaceMethods.
private void addInterfaceMethods(Set<CachedClass> interfaces) {
MetaMethodIndex.Header header = metaMethodIndex.getHeader(theClass);
for (CachedClass c : interfaces) {
final CachedMethod[] m = c.getMethods();
for (int i = 0; i != m.length; ++i) {
MetaMethod method = m[i];
addMetaMethodToIndex(method, header);
}
}
}
Aggregations