public static void generateResolvable( ClassLoader classLoader, String resolvableName, Class ownerClass, Method nonProxiedMethod, Type[] genericArguments, boolean isStatic, TransformGenerator[] tg) { Type ownerType = Type.getType(ownerClass); ClassGenerator w = new ClassGenerator(ACC_SUPER, resolvableName, OBJECT_TYPE, RESOLVABLE_TYPE); Type resolvableType = w.getThisType(); if (tg != null) { int index = 0; for (TransformGenerator generator : tg) { generator.generateFields(resolvableType, index, w); index += generator.getFieldCount(); } } Type[] arguments = nonProxiedMethod.getArgumentTypes(); if (!isStatic) { w.defineField(ACC_PRIVATE | ACC_FINAL, OWNER_FIELD_NAME, ownerType); } Type[] stored = new Type[arguments.length]; for (int i = 0; i < arguments.length; i++) { Type arg = genericArguments[i]; if (tg != null) { stored[i] = Type.getType(tg[i].getTransformedType(toClass(classLoader, arg))); } else { stored[i] = arg; } w.defineField(ACC_PRIVATE | ACC_FINAL, "arg" + i, stored[i]); } Type[] ctorArguments = isStatic ? arguments : CodegenHelper.insertFirst(arguments, ownerType); MxConstructorGenerator ctor = w.defineConstructor(ACC_PUBLIC, ctorArguments); generateResolvableCtor( ownerType, resolvableType, arguments, genericArguments, ctor, isStatic, tg, stored); MxGeneratorAdapter getValue = w.defineMethod(ACC_PUBLIC, GET_VALUE_METHOD); generateGetValue( ownerClass, ownerType, nonProxiedMethod, isStatic, resolvableType, arguments, getValue, tg, stored); w.toClass(classLoader); }
private static TransformGenerator[] getKeyTransformers(Class ownerClass, Method method) { TransformGeneratorFactory tgf = TransformGeneratorFactoryImpl.getInstance(); Class[] params = CodegenHelper.getClasses(ownerClass.getClassLoader(), method.getArgumentTypes()); Annotation[][] annotations; try { annotations = ownerClass.getDeclaredMethod(method.getName(), params).getParameterAnnotations(); } catch (NoSuchMethodException e) { throw new IllegalStateException(e); } TransformGenerator[] tg = new TransformGenerator[params.length]; for (int i = 0; i < params.length; i++) { tg[i] = tgf.forArgument(annotations[i], params[i]); } return tg; }