/** * {@inheritDoc} */ @Override public IProxyClassInfo createProxyClass(IProxyBuildPlan plan) { String internalName = AsmUtil.getAsmInternalName(plan.getProxyClassName()); Type proxyType = Type.getObjectType(internalName); String[] interfaces = getInternalNames(plan.getImplementedInterfaces()); String superClass = Type.getInternalName(plan.getSuperClass()); // generate a new class for the proxy with the defined interfaces and superclass ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); cw.visit(V1_5, ACC_PUBLIC, internalName, null, superClass, interfaces); // create the subject field cw.visitField(ACC_PUBLIC, SUBJECT_FIELD, IInstrumenterConstant.OBJECT_TYPE.getDescriptor(), null, null).visitEnd(); // create the fields for the delegation-target methods // The result map maps the proxied methods to their generated field's names Map<IMethodBuildPlan, String> methodFields = generateDelegationMethodTargetFields(plan, cw); generateConstructor(plan, proxyType, cw); // create the proxied methods for (Entry<IMethodBuildPlan, String> entry : methodFields.entrySet()) { createDelegationMethod(proxyType, entry.getKey(), entry.getValue(), cw); } cw.visitEnd(); byte[] bytecode = cw.toByteArray(); Class<?> cl = loadClass(bytecode, plan.getProxyClassName(), plan.getTargetClassLoader()); // inject the method fields injectDelegationTargetFields(plan, methodFields, cl); return new ASMProxyClassInfo(cl); }