use of org.codehaus.groovy.util.FastArray in project groovy-core by groovy.
the class MetaMethodIndex method copyNonPrivateNonNewMetaMethods.
private void copyNonPrivateNonNewMetaMethods(Entry from, Header to) {
Object oldListOrMethod = from.methods;
if (oldListOrMethod == null)
return;
if (oldListOrMethod instanceof FastArray) {
FastArray oldList = (FastArray) oldListOrMethod;
Entry e = null;
int len1 = oldList.size();
Object[] list = oldList.getArray();
for (int j = 0; j != len1; ++j) {
MetaMethod method = (MetaMethod) list[j];
if (method instanceof NewMetaMethod || method.isPrivate())
continue;
if (e == null)
e = getOrPutMethods(from.name, to);
e.methods = addMethodToList(e.methods, method);
}
} else {
MetaMethod method = (MetaMethod) oldListOrMethod;
if (method instanceof NewMetaMethod || method.isPrivate())
return;
Entry e = getOrPutMethods(from.name, to);
e.methods = addMethodToList(e.methods, method);
}
}
use of org.codehaus.groovy.util.FastArray in project groovy by apache.
the class MetaClassImpl method findMethod.
/**
* @return the matching method which should be found
*/
private MetaMethod findMethod(CachedMethod aMethod) {
Object methods = getMethods(theClass, aMethod.getName(), false);
if (methods instanceof FastArray) {
FastArray m = (FastArray) methods;
final int len = m.size;
final Object[] data = m.getArray();
for (int i = 0; i != len; ++i) {
MetaMethod method = (MetaMethod) data[i];
if (method.isMethod(aMethod)) {
return method;
}
}
} else {
MetaMethod method = (MetaMethod) methods;
if (method.getName().equals(aMethod.getName()) && // && method.getModifiers() == aMethod.getModifiers()
method.getReturnType().equals(aMethod.getReturnType()) && MetaMethod.equal(method.getParameterTypes(), aMethod.getParameterTypes())) {
return method;
}
}
return aMethod;
}
use of org.codehaus.groovy.util.FastArray in project groovy by apache.
the class ExpandoMetaClass method registerSubclassInstanceMethod.
public void registerSubclassInstanceMethod(MetaMethod metaMethod) {
modified = true;
final String name = metaMethod.getName();
Object methodOrList = expandoSubclassMethods.get(name);
if (methodOrList == null) {
expandoSubclassMethods.put(name, metaMethod);
} else {
if (methodOrList instanceof MetaMethod) {
FastArray arr = new FastArray(2);
arr.add(methodOrList);
arr.add(metaMethod);
expandoSubclassMethods.put(name, arr);
} else {
((FastArray) methodOrList).add(metaMethod);
}
}
}
use of org.codehaus.groovy.util.FastArray in project groovy by apache.
the class MetaClassImpl method filterPropertyMethod.
/**
* return null if nothing valid has been found, a MetaMethod (for getter always the case if not null) or
* a LinkedList<MetaMethod> if there are multiple setter
*/
private static Object filterPropertyMethod(Object methodOrList, boolean isGetter, boolean booleanGetter) {
// Method has been optimized to reach a target of 325 bytecode size, making it JIT'able
Object ret = null;
if (methodOrList instanceof MetaMethod) {
MetaMethod element = (MetaMethod) methodOrList;
int parameterCount = element.getParameterTypes().length;
if (!isGetter && //(element.getReturnType() == Void.class || element.getReturnType() == Void.TYPE) &&
parameterCount == 1) {
ret = element;
}
Class returnType = element.getReturnType();
if (isGetter && !(returnType == Void.class || returnType == Void.TYPE) && (!booleanGetter || returnType == Boolean.class || returnType == Boolean.TYPE) && parameterCount == 0) {
ret = element;
}
}
if (methodOrList instanceof FastArray) {
FastArray methods = (FastArray) methodOrList;
final int len = methods.size();
final Object[] data = methods.getArray();
for (int i = 0; i != len; ++i) {
MetaMethod element = (MetaMethod) data[i];
int parameterCount = element.getParameterTypes().length;
if (!isGetter && //(element.getReturnType() == Void.class || element.getReturnType() == Void.TYPE) &&
parameterCount == 1) {
ret = addElementToList(ret, element);
}
Class returnType = element.getReturnType();
if (isGetter && !(returnType == Void.class || returnType == Void.TYPE) && parameterCount == 0) {
ret = addElementToList(ret, element);
}
}
}
if (ret == null || (ret instanceof MetaMethod) || !isGetter) {
return ret;
}
// we found multiple matching methods
// this is a problem, because we can use only one
// if it is a getter, then use the most general return
// type to decide which method to use. If it is a setter
// we use the type of the first parameter
MetaMethod method = null;
int distance = -1;
for (final Object o : ((List) ret)) {
MetaMethod element = (MetaMethod) o;
int localDistance = distanceToObject(element.getReturnType());
//TODO: maybe implement the case localDistance==distance
if (distance == -1 || distance > localDistance) {
distance = localDistance;
method = element;
}
}
return method;
}
use of org.codehaus.groovy.util.FastArray in project groovy by apache.
the class MetaMethodIndex method copyAllMethodsToSuper.
private void copyAllMethodsToSuper(Entry from, Header to) {
Object oldListOrMethod = from.methods;
if (oldListOrMethod instanceof FastArray) {
FastArray oldList = (FastArray) oldListOrMethod;
Entry e = null;
int len1 = oldList.size();
Object[] list = oldList.getArray();
for (int j = 0; j != len1; ++j) {
MetaMethod method = (MetaMethod) list[j];
if (e == null)
e = getOrPutMethods(from.name, to);
e.methodsForSuper = addMethodToList(e.methodsForSuper, method);
}
} else {
MetaMethod method = (MetaMethod) oldListOrMethod;
Entry e = getOrPutMethods(from.name, to);
e.methodsForSuper = addMethodToList(e.methodsForSuper, method);
}
}
Aggregations