use of org.apache.xbean.asm9.MethodVisitor in project tomee by apache.
the class Cmp2Generator method createEjbActivate.
public void createEjbActivate() {
final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "ejbActivate", "()V", null, null);
mv.visitCode();
mv.visitInsn(RETURN);
mv.visitMaxs(0, 1);
mv.visitEnd();
}
use of org.apache.xbean.asm9.MethodVisitor in project tomee by apache.
the class ValidationGenerator method generate.
public byte[] generate() throws ProxyGenerationException {
generatedMethods.clear();
final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
final String generatedClassName = getName().replace('.', '/');
cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, generatedClassName, null, "java/lang/Object", null);
{
// public constructor
final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
mv.visitInsn(RETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
generateMethods(cw);
/**
* Read all parent classes and copy the public methods we need
* into our new class.
*/
Class current = clazz;
while (current != null && !current.equals(Object.class)) {
try {
final ClassReader classReader = new ClassReader(DynamicSubclass.readClassFile(current));
classReader.accept(new CopyMethodAnnotations(), ClassReader.SKIP_CODE);
} catch (final IOException e) {
throw new ProxyGenerationException(e);
}
current = current.getSuperclass();
}
return cw.toByteArray();
}
use of org.apache.xbean.asm9.MethodVisitor in project tomee by apache.
the class ServiceClasspathTest method subclass.
public static File subclass(final Class<?> parent, final String subclassName) throws Exception {
final String subclassNameInternal = subclassName.replace('.', '/');
final byte[] bytes;
{
final ClassWriter cw = new ClassWriter(0);
final String parentClassNameInternal = parent.getName().replace('.', '/');
cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC + ACC_SUPER, subclassNameInternal, null, parentClassNameInternal, null);
final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, parentClassNameInternal, "<init>", "()V", false);
mv.visitInsn(RETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
cw.visitEnd();
bytes = cw.toByteArray();
}
return Archive.archive().add(subclassNameInternal + ".class", bytes).asJar();
}
use of org.apache.xbean.asm9.MethodVisitor in project tomee by apache.
the class DynamicSubclass method visitConstructor.
private static MethodVisitor visitConstructor(final ClassWriter cw, final String proxyClassFileName, final String classFileName, final Constructor<?> constructor) {
final String descriptor = Type.getConstructorDescriptor(constructor);
final String[] exceptions = new String[constructor.getExceptionTypes().length];
for (int i = 0; i < exceptions.length; i++) {
exceptions[i] = Type.getInternalName(constructor.getExceptionTypes()[i]);
}
final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", descriptor, null, exceptions);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
int index = 1;
for (final Type type : Type.getArgumentTypes(descriptor)) {
mv.visitVarInsn(type.getOpcode(ILOAD), index);
index += size(type);
}
mv.visitMethodInsn(INVOKESPECIAL, classFileName, "<init>", descriptor, false);
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(PUTFIELD, proxyClassFileName, "this$handler", "Ljava/lang/reflect/InvocationHandler;");
mv.visitInsn(RETURN);
mv.visitMaxs(2, 1);
return mv;
}
use of org.apache.xbean.asm9.MethodVisitor in project tomee by apache.
the class DynamicSubclass method copyMethodAnnotations.
public static void copyMethodAnnotations(final Class<?> classToProxy, final Map<String, MethodVisitor> visitors) throws ProxyGenerationException {
// Move all the annotations onto the newly implemented methods
// Ensures CDI and JAX-RS and JAX-WS still work
Class clazz = classToProxy;
while (clazz != null && !clazz.equals(Object.class)) {
try {
final ClassReader classReader = new ClassReader(readClassFile(clazz));
final ClassVisitor copyMethodAnnotations = new CopyMethodAnnotations(visitors);
classReader.accept(copyMethodAnnotations, ClassReader.SKIP_CODE);
} catch (final IOException e) {
throw new ProxyGenerationException(e);
}
clazz = clazz.getSuperclass();
}
}
Aggregations