use of org.apache.xbean.asm9.AnnotationVisitor in project component-runtime by Talend.
the class PluginGenerator method createService.
private byte[] createService(final JarOutputStream outputStream, final String packageName, final String name) throws IOException {
final String className = packageName + "/AService.class";
outputStream.putNextEntry(new ZipEntry(className));
final ClassWriter writer = new ClassWriter(COMPUTE_FRAMES);
writer.visitAnnotation(Type.getDescriptor(Service.class), true).visitEnd();
writer.visit(V1_8, ACC_PUBLIC + ACC_SUPER, className.substring(0, className.length() - ".class".length()), null, Type.getInternalName(Object.class), null);
writer.visitSource(className.replace(".class", ".java"), null);
addConstructor(writer);
final MethodVisitor action = writer.visitMethod(ACC_PUBLIC, "doAction", "(L" + packageName + "/AModel;)L" + packageName + "/AModel;", null, new String[0]);
final AnnotationVisitor actionAnnotation = action.visitAnnotation(Type.getDescriptor(Action.class), true);
actionAnnotation.visit("family", "proc");
actionAnnotation.visit("value", name + "Action");
actionAnnotation.visitEnd();
action.visitCode();
action.visitTypeInsn(NEW, packageName + "/AModel");
action.visitInsn(DUP);
action.visitMethodInsn(INVOKESPECIAL, packageName + "/AModel", "<init>", "()V", false);
action.visitInsn(ARETURN);
action.visitInsn(ARETURN);
action.visitMaxs(1, 1);
action.visitEnd();
writer.visitEnd();
return writer.toByteArray();
}
use of org.apache.xbean.asm9.AnnotationVisitor in project component-runtime by Talend.
the class PluginGenerator method createProcessor.
private byte[] createProcessor(final JarOutputStream outputStream, final String packageName) throws IOException {
final String className = packageName + "/AProcessor.class";
outputStream.putNextEntry(new ZipEntry(className));
final ClassWriter writer = new ClassWriter(COMPUTE_FRAMES);
final AnnotationVisitor processorAnnotation = writer.visitAnnotation(Type.getDescriptor(Processor.class), true);
processorAnnotation.visit("family", "comp");
processorAnnotation.visit("name", "proc");
processorAnnotation.visitEnd();
writer.visit(V1_8, ACC_PUBLIC + ACC_SUPER, className.substring(0, className.length() - ".class".length()), null, Type.getInternalName(Object.class), new String[] { Serializable.class.getName().replace(".", "/") });
writer.visitSource(className.replace(".class", ".java"), null);
addConstructor(writer);
// generate a processor
final MethodVisitor emitMethod = writer.visitMethod(ACC_PUBLIC, "emit", "(L" + packageName + "/AModel;)L" + packageName + "/AModel;", null, new String[0]);
emitMethod.visitAnnotation(Type.getDescriptor(ElementListener.class), true).visitEnd();
emitMethod.visitCode();
emitMethod.visitTypeInsn(NEW, packageName + "/AModel");
emitMethod.visitInsn(DUP);
emitMethod.visitMethodInsn(INVOKESPECIAL, packageName + "/AModel", "<init>", "()V", false);
emitMethod.visitInsn(ARETURN);
emitMethod.visitInsn(ARETURN);
emitMethod.visitMaxs(1, 1);
emitMethod.visitEnd();
writer.visitEnd();
return writer.toByteArray();
}
use of org.apache.xbean.asm9.AnnotationVisitor 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.asm9.AnnotationVisitor 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