final String newTypeName = method.getDeclaringClass().getSimpleName().replace('.', '/') + "$"
+ method.getName() + "$" + Math.abs(method.hashCode()) + "$" + (++classLoadCounter);
logger.debug("Trying to make class for " + newTypeName);
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, newTypeName, null, "java/lang/Object", new String[] {"java/io/Serializable"});
{
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
mv.visitInsn(RETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
StringBuilder valueLists = new StringBuilder();
java.lang.reflect.Type[] types = method.getGenericParameterTypes();
String[] names = provider.parameterNamesFor(method);
for (int i = 0; i < names.length; i++) {
names[i] = Info.capitalize(names[i]);
}
if (logger.isDebugEnabled()) {
logger.debug("Parameter names found for creating type are: " + Arrays.toString(names));
}
for (int i = 0; i < types.length; i++) {
java.lang.reflect.Type type = types[i];
if (type instanceof ParameterizedType) {
parse(cw, (ParameterizedType) type, valueLists, newTypeName, names[i]);
} else if (type instanceof Class<?>) {
parse(cw, (Class<?>) type, valueLists, newTypeName, names[i]);
} else if (type instanceof TypeVariable<?>) {
ParameterizedType superclass = (ParameterizedType) resourceMethod.getResource().getType().getGenericSuperclass();
parse(cw, (Class<?>) superclass.getActualTypeArguments()[0], valueLists, newTypeName, names[i]);
} else {
throw new IllegalArgumentException("Unable to identify field " + type + " of type "
+ type.getClass().getName());
}
}
cw.visitEnd();
final byte[] bytes = cw.toByteArray();
ClassLoader loader = new ClassLoader(this.getClass().getClassLoader()) {
@Override
public Class<?> loadClass(String name) throws ClassNotFoundException {
if (name.equals(newTypeName)) {