use of org.codehaus.groovy.util.FastArray in project groovy by apache.
the class MetaMethodIndex method addMethodToList.
public Object addMethodToList(Object o, MetaMethod method) {
if (o == null) {
return method;
}
if (o instanceof MetaMethod) {
MetaMethod match = (MetaMethod) o;
if (!isMatchingMethod(match, method)) {
FastArray list = new FastArray(2);
list.add(match);
list.add(method);
return list;
} else {
if (match.isPrivate() || (!isNonRealMethod(match) && match.getDeclaringClass().isInterface() && !method.getDeclaringClass().isInterface())) {
// do not overwrite interface methods with instance methods
// do not overwrite private methods
// Note: private methods from parent classes are not shown here,
// but when doing the multimethod connection step, we overwrite
// methods of the parent class with methods of a subclass and
// in that case we want to keep the private methods
} else {
CachedClass methodC = method.getDeclaringClass();
CachedClass matchC = match.getDeclaringClass();
if (methodC == matchC) {
if (isNonRealMethod(method)) {
return method;
}
} else if (!methodC.isAssignableFrom(matchC.getTheClass())) {
return method;
}
}
}
return o;
}
if (o instanceof FastArray) {
FastArray list = (FastArray) o;
int found = findMatchingMethod(list, method);
if (found == -1) {
list.add(method);
} else {
MetaMethod match = (MetaMethod) list.get(found);
if (match == method)
return o;
if (match.isPrivate() || (!isNonRealMethod(match) && match.getDeclaringClass().isInterface() && !method.getDeclaringClass().isInterface())) {
// do not overwrite interface methods with instance methods
// do not overwrite private methods
// Note: private methods from parent classes are not shown here,
// but when doing the multimethod connection step, we overwrite
// methods of the parent class with methods of a subclass and
// in that case we want to keep the private methods
} else {
CachedClass methodC = method.getDeclaringClass();
CachedClass matchC = match.getDeclaringClass();
if (methodC == matchC) {
if (isNonRealMethod(method)) {
list.set(found, method);
}
} else if (!methodC.isAssignableFrom(matchC.getTheClass())) {
list.set(found, method);
}
}
}
}
return o;
}
use of org.codehaus.groovy.util.FastArray in project groovy by apache.
the class MetaClassImpl method pickStaticMethod.
private MetaMethod pickStaticMethod(String methodName, Class[] arguments) {
MetaMethod method = null;
MethodSelectionException mse = null;
Object methods = getStaticMethods(theClass, methodName);
if (!(methods instanceof FastArray) || !((FastArray) methods).isEmpty()) {
try {
method = (MetaMethod) chooseMethod(methodName, methods, arguments);
} catch (MethodSelectionException msex) {
mse = msex;
}
}
if (method == null && theClass != Class.class) {
MetaClass classMetaClass = registry.getMetaClass(Class.class);
method = classMetaClass.pickMethod(methodName, arguments);
}
if (method == null) {
method = (MetaMethod) chooseMethod(methodName, methods, MetaClassHelper.convertToTypeArray(arguments));
}
if (method == null && mse != null) {
throw mse;
} else {
return method;
}
}
use of org.codehaus.groovy.util.FastArray in project groovy by apache.
the class MetaClassImpl method getMethods.
/**
* Gets all instance methods available on this class for the given name
*
* @return all the normal instance methods available on this class for the
* given name
*/
private Object getMethods(Class sender, String name, boolean isCallToSuper) {
Object answer;
final MetaMethodIndex.Entry entry = metaMethodIndex.getMethods(sender, name);
if (entry == null)
answer = FastArray.EMPTY_LIST;
else if (isCallToSuper) {
answer = entry.methodsForSuper;
} else {
answer = entry.methods;
}
if (answer == null)
answer = FastArray.EMPTY_LIST;
if (!isCallToSuper) {
List used = GroovyCategorySupport.getCategoryMethods(name);
if (used != null) {
FastArray arr;
if (answer instanceof MetaMethod) {
arr = new FastArray();
arr.add(answer);
} else
arr = ((FastArray) answer).copy();
for (Iterator iter = used.iterator(); iter.hasNext(); ) {
MetaMethod element = (MetaMethod) iter.next();
if (!element.getDeclaringClass().getTheClass().isAssignableFrom(sender))
continue;
filterMatchingMethodForCategory(arr, element);
}
answer = arr;
}
}
return answer;
}
Aggregations