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); }
public void addAll(FastArray newData) { addAll(newData.data, newData.size); }
MetaMethod match = (MetaMethod) o; if (!isMatchingMethod(match, method)) { FastArray list = new FastArray(2); list.add(match); list.add(method); return list; } else { list.add(method); } else { MetaMethod match = (MetaMethod) list.get(found); if (match==method) return o; if (match.isPrivate() if (methodC == matchC) { if (isNonRealMethod(method)) { list.set(found, method); list.set(found, method);
int methodCount = methods.size(); if (methodCount <= 0) { return null; } else if (methodCount == 1) { Object method = methods.get(0); if (((ParameterTypes) method).isValidMethod(arguments)) { return method; Object data[] = methods.getArray(); for (int i = 0; i != len; ++i) { Object method = data[i];
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); } } }
private void createMetaMethodFromClass(Map<CachedClass, List<MetaMethod>> map, Class aClass) { try { MetaMethod method = (MetaMethod) aClass.newInstance(); final CachedClass declClass = method.getDeclaringClass(); List<MetaMethod> arr = map.get(declClass); if (arr == null) { arr = new ArrayList<MetaMethod>(4); map.put(declClass, arr); } arr.add(method); instanceMethods.add(method); } catch (InstantiationException | IllegalAccessException e) { /* ignore */ } }
public Object get(int index) { return FastArray.this.get(index); }
@Override public List<MetaMethod> getMethods() { List<MetaMethod> answer = CLOSURE_METACLASS.getMetaMethods(); answer.addAll(closureMethods.toList()); return answer; }
public void copyMethodsToSuper() { Entry[] table = this.table; int length = table.length; for (int j = 0; j < length; j++) { for (Entry e = table[j]; e != null; e = e.nextHashEntry) { if (e.methods instanceof FastArray) e.methodsForSuper = ((FastArray) e.methods).copy(); else e.methodsForSuper = e.methods; } } }
public FastArray copy() { final Object[] newData = new Object[size]; System.arraycopy(data, 0, newData, 0, size); return new FastArray(newData); }
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 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; } }
public void testRegistry () { final MetaClassRegistryImpl metaClassRegistry = new MetaClassRegistryImpl(); final Object [] instanceMethods = metaClassRegistry.getInstanceMethods().getArray(); for (int i = 0; i < instanceMethods.length; i++) { System.out.println(instanceMethods[i]); } } }
MetaMethod match = (MetaMethod) o; if (!isMatchingMethod(match, method)) { FastArray list = new FastArray(2); list.add(match); list.add(method); return list; } else { list.add(method); } else { MetaMethod match = (MetaMethod) list.get(found); if (match==method) return o; if (match.isPrivate() if (methodC == matchC) { if (isNonRealMethod(method)) { list.set(found, method); list.set(found, method);
/** * @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; }