use of org.apache.xbean.asm6.MethodVisitor in project tomee by apache.
the class MakeTxLookup method createTopLinkStrategy.
private static void createTopLinkStrategy(final File baseDir) throws Exception {
final String factory = TOPLINK_FACTORY;
final String classFilePath = factory.replace('.', '/');
final String sourceFileName = factory.substring(factory.lastIndexOf('.') + 1, factory.length()) + ".java";
final ClassWriter cw = new ClassWriter(0);
MethodVisitor mv;
cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, classFilePath, null, "oracle/toplink/essentials/transaction/JTATransactionController", null);
cw.visitSource(sourceFileName, null);
{
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, "oracle/toplink/essentials/transaction/JTATransactionController", "<init>", "()V", false);
mv.visitInsn(RETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
{
mv = cw.visitMethod(ACC_PROTECTED, "acquireTransactionManager", "()Ljavax/transaction/TransactionManager;", null, new String[] { "java/lang/Exception" });
mv.visitCode();
mv.visitMethodInsn(INVOKESTATIC, "org/apache/openejb/OpenEJB", "getTransactionManager", "()Ljavax/transaction/TransactionManager;", false);
mv.visitInsn(ARETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
cw.visitEnd();
write(baseDir, cw, classFilePath);
}
use of org.apache.xbean.asm6.MethodVisitor in project tomee by apache.
the class ReturnValidationGenerator method generateMethods.
protected void generateMethods(final ClassWriter cw) {
for (final MethodConstraints methodConstraints : constraints) {
final Method method = methodConstraints.getMethod();
final String name = method.getName();
// Declare a method of return type JsonWebToken for use with
// a call to BeanValidation's ExecutableValidator.validateReturnValue
final Type returnType = Type.getReturnType(method);
final Type[] parameterTypes = Type.getArgumentTypes(method);
final String descriptor = Type.getMethodDescriptor(returnType, parameterTypes);
final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, name, descriptor, null, null);
// Put the method name on the
final AnnotationVisitor av = mv.visitAnnotation(Type.getDescriptor(Generated.class), true);
av.visit("value", this.getClass().getName());
av.visitEnd();
// track the MethodVisitor
// We will later copy over the annotations
generatedMethods.put(method.getName() + Type.getMethodDescriptor(method), new ConstrainedMethodVisitor(mv, methodConstraints));
if (method.getReturnType().equals(Void.TYPE)) {
mv.visitCode();
mv.visitInsn(RETURN);
mv.visitMaxs(0, 1);
} else if (method.getReturnType().equals(Long.TYPE)) {
mv.visitCode();
mv.visitInsn(LCONST_0);
mv.visitInsn(LRETURN);
mv.visitMaxs(2, 4);
mv.visitEnd();
} else if (method.getReturnType().equals(Float.TYPE)) {
mv.visitCode();
mv.visitInsn(FCONST_0);
mv.visitInsn(FRETURN);
mv.visitMaxs(1, 3);
mv.visitEnd();
} else if (method.getReturnType().equals(Double.TYPE)) {
mv.visitCode();
mv.visitInsn(DCONST_0);
mv.visitInsn(DRETURN);
mv.visitMaxs(2, 4);
mv.visitEnd();
} else if (method.getReturnType().isPrimitive()) {
mv.visitCode();
mv.visitInsn(ICONST_0);
mv.visitInsn(IRETURN);
mv.visitMaxs(1, 3);
mv.visitEnd();
} else {
// The method will simply return null
mv.visitCode();
mv.visitInsn(ACONST_NULL);
mv.visitInsn(ARETURN);
mv.visitMaxs(1, 1);
}
}
}
use of org.apache.xbean.asm6.MethodVisitor in project tomee by apache.
the class JwtValidationGenerator method generateMethods.
protected void generateMethods(final ClassWriter cw) {
for (final MethodConstraints methodConstraints : constraints) {
final Method method = methodConstraints.getMethod();
final String name = method.getName();
// Declare a method of return type JsonWebToken for use with
// a call to BeanValidation's ExecutableValidator.validateReturnValue
final Type returnType = Type.getType(JsonWebToken.class);
final Type[] parameterTypes = Type.getArgumentTypes(method);
final String descriptor = Type.getMethodDescriptor(returnType, parameterTypes);
final int access = method.isVarArgs() ? ACC_PUBLIC + ACC_VARARGS : ACC_PUBLIC;
final MethodVisitor mv = cw.visitMethod(access, name, descriptor, null, null);
// Put the method name on the
final AnnotationVisitor av = mv.visitAnnotation(Type.getDescriptor(Generated.class), true);
av.visit("value", this.getClass().getName());
av.visitEnd();
// track the MethodVisitor
// We will later copy over the annotations
generatedMethods.put(method.getName() + Type.getMethodDescriptor(method), new ConstrainedMethodVisitor(mv, methodConstraints));
// The method will simply return null
mv.visitCode();
mv.visitInsn(ACONST_NULL);
mv.visitInsn(ARETURN);
mv.visitMaxs(1, 1);
}
}
Aggregations