public String toString() { if (size() == 0) return "[]"; return toList().toString(); } }
private static int findMatchingMethod(FastArray list, MetaMethod method) { int len = list.size(); Object data[] = list.getArray(); for (int j = 0; j != len; ++j) { MetaMethod aMethod = (MetaMethod) data[j]; if (isMatchingMethod(aMethod, method)) return j; } return -1; }
private int selectConstructorAndTransformArguments0(final int numberOfConstructors, Object[] arguments) { //TODO: that is just a quick prototype, not the real thing! if (numberOfConstructors != constructors.size()) { throw new IncompatibleClassChangeError("the number of constructors during runtime and compile time for " + this.theClass.getName() + " do not match. Expected " + numberOfConstructors + " but got " + constructors.size()); } CachedConstructor constructor = createCachedConstructor(arguments); List l = new ArrayList(constructors.toList()); Comparator comp = new Comparator() { public int compare(Object arg0, Object arg1) { CachedConstructor c0 = (CachedConstructor) arg0; CachedConstructor c1 = (CachedConstructor) arg1; String descriptor0 = BytecodeHelper.getMethodDescriptor(Void.TYPE, c0.getNativeParameterTypes()); String descriptor1 = BytecodeHelper.getMethodDescriptor(Void.TYPE, c1.getNativeParameterTypes()); return descriptor0.compareTo(descriptor1); } }; Collections.sort(l, comp); int found = -1; for (int i = 0; i < l.size(); i++) { if (l.get(i) != constructor) continue; found = i; break; } // NOTE: must be changed to "1 |" if constructor was vargs return (found << 8); }
public Object chooseMethod(Class[] arguments, boolean coerce) { if (arguments.length == 0) { return MetaClassHelper.chooseEmptyMethodParams(methods); } else if (arguments.length == 1 && arguments[0] == null) { return MetaClassHelper.chooseMostGeneralMethodWith1NullParam(methods); } else { List matchingMethods = new ArrayList(); final Object[] data = methods.getArray(); for (int i = 0, len = methods.size(); i != len; ++i) { Object method = data[i]; // making this false helps find matches if (((ParameterTypes) method).isValidMethod(arguments)) { matchingMethods.add(method); } } int size = matchingMethods.size(); if (0 == size) { return null; } else if (1 == size) { return matchingMethods.get(0); } return chooseMostSpecificParams(CLOSURE_DO_CALL_METHOD, matchingMethods, arguments); } }
/** * @param methods the methods to choose from * @return the method with 1 parameter which takes the most general type of * object (e.g. Object) */ public static Object chooseEmptyMethodParams(FastArray methods) { Object vargsMethod = null; final int len = methods.size(); final Object[] data = methods.getArray(); for (int i = 0; i != len; ++i) { Object method = data[i]; final ParameterTypes pt = (ParameterTypes) method; CachedClass[] paramTypes = pt.getParameterTypes(); int paramLength = paramTypes.length; if (paramLength == 0) { return method; } else if (paramLength == 1 && pt.isVargsMethod(EMPTY_ARRAY)) { vargsMethod = method; } } return vargsMethod; }
private static MetaMethod findSubClassMethod(Class instanceKlazz, String methodName, Class[] arguments, MetaClass metaClass, MetaMethod method) { if (metaClass instanceof MetaClassImpl) { Object list = ((MetaClassImpl) metaClass).getSubclassMetaMethods(methodName); if (list != null) { if (list instanceof MetaMethod) { MetaMethod m = (MetaMethod) list; method = findSubClassMethod(instanceKlazz, arguments, method, m); } else { FastArray arr = (FastArray) list; for (int i = 0; i != arr.size(); ++i) { MetaMethod m = (MetaMethod) arr.get(i); method = findSubClassMethod(instanceKlazz, arguments, method, m); } } } } return method; }
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); } }
int methodCount = methods.size(); if (methodCount <= 0) { return null;
private void copyNonPrivateMethodsFromSuper(Entry e) { Object oldListOrMethod = e.methodsForSuper; if (oldListOrMethod == null) return; if (oldListOrMethod instanceof FastArray) { FastArray oldList = (FastArray) oldListOrMethod; int len1 = oldList.size(); Object list[] = oldList.getArray(); for (int j = 0; j != len1; ++j) { MetaMethod method = (MetaMethod) list[j]; if (method.isPrivate()) continue; e.methods = addMethodToList(e.methods, method); } } else { MetaMethod method = (MetaMethod) oldListOrMethod; if (!method.isPrivate()) { e.methods = addMethodToList(e.methods, method); } } }
private static void filterMatchingMethodForCategory(FastArray list, MetaMethod method) { int len = list.size(); if (len==0) { list.add(method); return; } Object data[] = list.getArray(); for (int j = 0; j != len; ++j) { MetaMethod aMethod = (MetaMethod) data[j]; Boolean match = getMatchKindForCategory(aMethod, method); // true == replace if (match==Boolean.TRUE) { list.set(j, method); return; // null == ignore (we have a better method already) } else if (match==null) { return; } } // the casese true and null for a match are through, the // remaining case is false and that means adding the method // to our list list.add(method); }
private void assignMethodChooser() { if (closureMethods.size() == 1) { final MetaMethod doCall = (MetaMethod) closureMethods.get(0); final CachedClass[] c = doCall.getParameterTypes(); } else if (closureMethods.size() == 2) { MetaMethod m0 = null, m1 = null; for (int i = 0; i != closureMethods.size(); ++i) { MetaMethod m = (MetaMethod) closureMethods.get(i); CachedClass[] c = m.getParameterTypes();
private void copyAllMethods(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.methods = addMethodToList(e.methods, method); } } else { MetaMethod method = (MetaMethod) oldListOrMethod; if (!method.isPrivate()) { Entry e = getOrPutMethods(from.name, to); e.methods = addMethodToList(e.methods, method); } } }
private void copyNonPrivateMethods(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 (method.isPrivate()) continue; if (e == null) e = getOrPutMethods(from.name, to); e.methods = addMethodToList(e.methods, method); } } else { MetaMethod method = (MetaMethod) oldListOrMethod; if (!method.isPrivate()) { Entry e = getOrPutMethods(from.name, to); e.methods = addMethodToList(e.methods, method); } } }
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); } }
if (e.methods instanceof FastArray) { FastArray methods = (FastArray) e.methods; final int len = methods.size(); final Object[] data = methods.getArray(); for (int i = 0; i != len; ++i) {
final int len = methods.size(); final Object[] data = methods.getArray(); for (int i = 0; i != len; ++i) {
Object answer = null; int closestDist = -1; final int len = methods.size(); for (int i = 0; i != len; ++i) { final Object[] data = methods.getArray();
public String toString() { if (size() == 0) return "[]"; return toList().toString(); } }
public String toString() { if (size() == 0) return "[]"; return toList().toString(); } }
private int findMatchingMethod(FastArray list, MetaMethod method) { int len = list.size(); Object data[] = list.getArray(); for (int j = 0; j != len; ++j) { MetaMethod aMethod = (MetaMethod) data[j]; if (isMatchingMethod(aMethod, method)) return j; } return -1; }