public String getName() { return method.getName(); }
private int findMatchingMethod(MetaMethod method, String mopName, int index, CachedMethod[] mopMethods) { int from = index; while (from > 0 && mopMethods[from-1].getName().equals(mopName)) from--; int to = index; while (to < mopMethods.length-1 && mopMethods[to+1].getName().equals(mopName)) to++; return findMatchingMethod(mopMethods, from, to, method); }
public String getSignature() { return getName() + getDescriptor(); }
private int compareToMethod(Method other) { if (other == null) return -1; final int strComp = getName().compareTo(other.getName()); if (strComp != 0) return strComp; final int retComp = getReturnType().getName().compareTo(other.getReturnType().getName()); if (retComp != 0) return retComp; CachedClass[] params = getParameterTypes(); Class[] mparams = other.getParameterTypes(); final int pd = params.length - mparams.length; if (pd != 0) return pd; for (int i = 0; i != params.length; ++i) { final int nameComp = params[i].getName().compareTo(mparams[i].getName()); if (nameComp != 0) return nameComp; } return 0; }
public CachedClosureClass(Class klazz, ClassInfo classInfo) { super(klazz, classInfo); CachedMethod methods [] = getMethods(); // set it to -1 for starters so parameterTypes will always get a type int maximumNumberOfParameters = -1; Class[] parameterTypes = null; for (CachedMethod method : methods) { if ("doCall".equals(method.getName())) { final Class[] pt = method.getNativeParameterTypes(); if (pt.length > maximumNumberOfParameters) { parameterTypes = pt; maximumNumberOfParameters = parameterTypes.length; } } } // this line should be useless, but well, just in case maximumNumberOfParameters = Math.max(maximumNumberOfParameters,0); this.maximumNumberOfParameters = maximumNumberOfParameters; this.parameterTypes = parameterTypes; }
for (int i = 0; i != declaredMethods.length; ++i) { final CachedMethod cachedMethod = new CachedMethod(CachedClass.this, declaredMethods[i]); final String name = cachedMethod.getName();
public synchronized void initialize() { if (!isInitialized()) { CachedMethod[] methodArray = theCachedClass.getMethods(); synchronized (theCachedClass) { for (final CachedMethod cachedMethod : methodArray) { if (!cachedMethod.getName().equals(CLOSURE_DO_CALL_METHOD)) continue; closureMethods.add(cachedMethod); } } assignMethodChooser(); initialized = true; } }
protected Object noSuchMethod(CachedMethod method, Object object, Object[] arguments) { throw new MissingMethodException(method.getName(), method.getDeclaringClass().getTheClass(), arguments, false); } }
public CachedMethod searchMethods(String name, CachedClass[] parameterTypes) { CachedMethod[] methods = getMethods(); CachedMethod res = null; for (CachedMethod m : methods) { if (m.getName().equals(name) && ReflectionCache.arrayContentsEq(parameterTypes, m.getParameterTypes()) && (res == null || res.getReturnType().isAssignableFrom(m.getReturnType()))) res = m; } return res; }
private int compareToCachedMethod(CachedMethod other) { if (other == null) return -1; final int strComp = getName().compareTo(other.getName()); if (strComp != 0) return strComp; final int retComp = getReturnType().getName().compareTo(other.getReturnType().getName()); if (retComp != 0) return retComp; CachedClass[] params = getParameterTypes(); CachedClass[] otherParams = other.getParameterTypes(); final int pd = params.length - otherParams.length; if (pd != 0) return pd; for (int i = 0; i != params.length; ++i) { final int nameComp = params[i].getName().compareTo(otherParams[i].getName()); if (nameComp != 0) return nameComp; } final int classComp = cachedClass.toString().compareTo(other.getDeclaringClass().toString()); if (classComp != 0) return classComp; throw new RuntimeException("Should never happen"); }
public static boolean isCompilable (CachedMethod method) { return (GroovySunClassLoader.sunVM != null || Modifier.isPublic(method.cachedClass.getModifiers()) && method.isPublic() && publicParams(method)) && !AndroidSupport.isRunningAndroid() && containsOnlyValidChars(method.getName()); }
public static List<MetaMethod> createMethodList(final String name, final Class declaringClass, final Closure closure) { List<MetaMethod> res = new ArrayList<MetaMethod>(); if (closure instanceof MethodClosure) { MethodClosure methodClosure = (MethodClosure) closure; Object owner = closure.getOwner(); Class ownerClass = (Class) (owner instanceof Class ? owner : owner.getClass()); for (CachedMethod method : ReflectionCache.getCachedClass(ownerClass).getMethods() ) { if (method.getName().equals(methodClosure.getMethod())) { MetaMethod metaMethod = new MethodClosureMetaMethod(name, declaringClass, closure, method); res.add(adjustParamTypesForStdMethods(metaMethod, name)); } } } else { if (closure instanceof GeneratedClosure) { for (CachedMethod method : ReflectionCache.getCachedClass(closure.getClass()).getMethods() ) { if (method.getName().equals("doCall")) { MetaMethod metaMethod = new ClosureMetaMethod(name, declaringClass, closure, method); res.add(adjustParamTypesForStdMethods(metaMethod, name)); } } } else { MetaMethod metaMethod = new AnonymousMetaMethod(closure, name, declaringClass); res.add(adjustParamTypesForStdMethods(metaMethod, name)); } } return res; }
/** * @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()) // TODO: should be better check for case when only diff in modifiers can be SYNTHETIC flag // && method.getModifiers() == aMethod.getModifiers() && method.getReturnType().equals(aMethod.getReturnType()) && MetaMethod.equal(method.getParameterTypes(), aMethod.getParameterTypes())) { return method; } } return aMethod; }
records.add(record); record.methodName = method.getName(); record.returnType = method.getReturnType(); record.parameters = method.getNativeParameterTypes();
private void applyUse(CachedClass cachedClass) { CachedMethod[] methods = cachedClass.getMethods(); for (CachedMethod cachedMethod : methods) { if (cachedMethod.isStatic() && cachedMethod.isPublic()) { CachedClass[] paramTypes = cachedMethod.getParameterTypes(); if (paramTypes.length > 0) { CachedClass metaClass = paramTypes[0]; CategoryMethod mmethod = new CategoryMethod(cachedMethod, metaClass.getTheClass()); final String name = cachedMethod.getName(); CategoryMethodList list = get(name); if (list == null || list.level != level) { list = new CategoryMethodList(name, level, list); put(name, list); } list.add(mmethod); Collections.sort(list); cachePropertyAccessor(mmethod); } } } }
private static void createInvokeMethod(CachedMethod method, ClassWriter cw, Class returnType, String methodDescriptor) { MethodVisitor mv; mv = cw.visitMethod(ACC_PUBLIC, "invoke", "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 1); BytecodeHelper.doCast(mv, method.getParameterTypes()[0].getTheClass()); loadParameters(method, 2, mv); mv.visitMethodInsn(INVOKESTATIC, BytecodeHelper.getClassInternalName(method.getDeclaringClass().getTheClass()), method.getName(), methodDescriptor, false); BytecodeHelper.box(mv, returnType); if (method.getReturnType() == void.class) { mv.visitInsn(ACONST_NULL); } mv.visitInsn(ARETURN); mv.visitMaxs(0, 0); mv.visitEnd(); }
mv.visitMethodInsn(invokeMethodCode, type, cachedMethod.getName(), descriptor, useInterface);
loadParameters(method, 2, mv); mv.visitMethodInsn(INVOKESTATIC, BytecodeHelper.getClassInternalName(method.getDeclaringClass().getTheClass()), method.getName(), methodDescriptor, false); BytecodeHelper.box(mv, returnType); if (method.getReturnType() == void.class) {