List of usage examples for org.objectweb.asm AnnotationVisitor visitEnum
public void visitEnum(final String name, final String descriptor, final String value)
From source file:blue.lapis.pore.event.PoreListenerGenerator.java
License:Open Source License
private static byte[] generate(String name, Class<?> pore, Class<?> sponge, EventPriority priority, Order order) {// w ww . ja v a 2 s. co m name = name.replace('.', '/'); String poreName = Type.getInternalName(pore); String spongeSignature = "(L" + Type.getInternalName(sponge) + ";)V"; ClassWriter cw = new ClassWriter(0); MethodVisitor mv; AnnotationVisitor av; cw.visit(V1_6, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, name, null, "java/lang/Object", null); { 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(); } { mv = cw.visitMethod(ACC_PUBLIC, "on" + sponge.getSimpleName(), spongeSignature, null, null); { av = mv.visitAnnotation(ANNOTATION_DESCRIPTOR, true); av.visitEnum("order", ORDER_DESCRIPTOR, order.name()); av.visitEnd(); } mv.visitCode(); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKESTATIC, EVENT_WRAPPER_CLASS, "get", GET_CACHE, false); mv.visitTypeInsn(CHECKCAST, poreName); mv.visitVarInsn(ASTORE, 2); mv.visitVarInsn(ALOAD, 2); Label l0 = new Label(); mv.visitJumpInsn(IFNONNULL, l0); mv.visitVarInsn(ALOAD, 1); mv.visitTypeInsn(NEW, poreName); mv.visitInsn(DUP); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKESPECIAL, poreName, "<init>", spongeSignature, false); mv.visitInsn(DUP); mv.visitVarInsn(ASTORE, 2); mv.visitMethodInsn(INVOKESTATIC, EVENT_WRAPPER_CLASS, "set", SET_CACHE, false); mv.visitLabel(l0); mv.visitFrame(F_APPEND, 1, new Object[] { poreName }, 0, null); mv.visitVarInsn(ALOAD, 2); mv.visitFieldInsn(GETSTATIC, PRIORITY_CLASS, priority.name(), PRIORITY_DESCRIPTOR); mv.visitMethodInsn(INVOKESTATIC, EVENT_WRAPPER_CLASS, "call", CALL_EVENT, false); mv.visitInsn(RETURN); mv.visitMaxs(4, 3); mv.visitEnd(); } cw.visitEnd(); return cw.toByteArray(); }
From source file:com.facebook.buck.java.abi.AnnotationValueMirror.java
License:Apache License
public void accept(@Nullable String name, AnnotationVisitor visitor) { if (primitiveValue != null) { visitor.visit(name, primitiveValue); } else if (enumValue != null) { visitor.visitEnum(name, enumValue.desc, enumValue.value); } else if (annotationValue != null) { annotationValue.appendTo(visitor, name); } else if (arrayValue != null) { AnnotationVisitor arrayVisitor = visitor.visitArray(name); for (AnnotationValueMirror element : arrayValue) { element.accept(null, arrayVisitor); }//ww w. j a v a 2 s. co m arrayVisitor.visitEnd(); } }
From source file:com.facebook.presto.byteCode.AnnotationDefinition.java
License:Apache License
private void visit(AnnotationVisitor visitor, String name, Object value) { if (value instanceof AnnotationDefinition) { AnnotationDefinition annotation = (AnnotationDefinition) value; AnnotationVisitor annotationVisitor = visitor.visitAnnotation(name, annotation.type.getType()); annotation.visit(annotationVisitor); } else if (value instanceof Enum) { Enum<?> enumConstant = (Enum<?>) value; visitor.visitEnum(name, type(enumConstant.getDeclaringClass()).getClassName(), enumConstant.name()); } else if (value instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) value; visitor.visit(name, Type.getType(parameterizedType.getType())); } else if (value instanceof Class) { Class<?> clazz = (Class<?>) value; visitor.visit(name, Type.getType(clazz)); } else if (value instanceof List) { AnnotationVisitor arrayVisitor = visitor.visitArray(name); for (Object element : (List<?>) value) { visit(arrayVisitor, null, element); }/*from w w w . j a va2s.c om*/ arrayVisitor.visitEnd(); } else { visitor.visit(name, value); } }
From source file:com.google.code.nanorm.internal.introspect.asm.MapperBuilder.java
License:Apache License
/** * Visit annotation property (String, primitive value, class reference or * other annotation)/* w w w. j a va 2s . co m*/ * @param name annotation name * @param obj value * @param visitor annotation visitar */ private static void visitAnnotationProperty(String name, Object obj, AnnotationVisitor visitor) { final Class<?> objClass = obj.getClass(); if (objClass.isArray()) { // Array final AnnotationVisitor arrayVisitor = visitor.visitArray(name); for (Object o : (Object[]) obj) { visitAnnotationProperty(name, o, arrayVisitor); } arrayVisitor.visitEnd(); } else if (objClass.isEnum()) { // Enumeration visitor.visitEnum(name, Type.getDescriptor(obj.getClass()), obj.toString()); } else if (Annotation.class.isAssignableFrom(obj.getClass())) { // Nested annotation Annotation nested = (Annotation) obj; AnnotationVisitor nestedVisitor = visitor.visitAnnotation(name, Type.getDescriptor(nested.annotationType())); visitAnnotation(nestedVisitor, nested); } else if (obj instanceof Class<?>) { // Class reference visitor.visit(name, Type.getDescriptor((Class<?>) obj)); } else { // String or primitive type visitor.visit(name, obj); } }
From source file:com.googlecode.ddom.weaver.asm.AnnotationVisitorTee.java
License:Apache License
public void visitEnum(String name, String desc, String value) { for (AnnotationVisitor visitor : visitors) { visitor.visitEnum(name, desc, value); }//w w w .ja v a 2s .c o m }
From source file:com.googlecode.dex2jar.v3.AnnotationNode.java
License:Apache License
@SuppressWarnings("unchecked") public static void accept(String name, Object v, AnnotationVisitor av) { if (v instanceof AnnotationNode) { AnnotationNode a = (AnnotationNode) v; AnnotationVisitor av1 = av.visitAnnotation(name, a.type); accept(a.items, av1);/*from w w w . jav a2 s. co m*/ av1.visitEnd(); } else if (v instanceof Field) { Field e = (Field) v; av.visitEnum(name, e.getOwner(), e.getName()); } else if (v instanceof List) { List<Object> list = (List<Object>) v; AnnotationVisitor av1 = av.visitArray(name); for (Object i : list) { accept(null, i, av1); } av1.visitEnd(); } else if (v instanceof Method) { // Method method = (Method) v; // AnnotationVisitor av1 = av.visitAnnotation(item.name, "Lcom.googlecode.Method;"); // av1.visit("owner", method.getOwner()); // av1.visit("name", method.getName()); // av1.visit("desc", method.getType().getDesc()); // av1.visitEnd(); av.visit(name, v); } else if (v instanceof DexType) { av.visit(name, ((DexType) v).desc); } else { av.visit(name, v); } }
From source file:com.googlecode.dex2jar.v3.V3AnnAdapter.java
License:Apache License
public static void accept(List<Item> items, AnnotationVisitor av) { if (av == null) { return;//from w w w . j av a 2 s . com } for (Item item : items) { Object v = item.value; if (v instanceof Annotation) { Annotation a = (Annotation) v; if (a.type != null) { AnnotationVisitor av1 = av.visitAnnotation(item.name, a.type); accept(a.items, av1); av1.visitEnd(); } else {// array AnnotationVisitor av1 = av.visitArray(item.name); accept(a.items, av1); av1.visitEnd(); } } else if (v instanceof Field) { Field e = (Field) v; av.visitEnum(item.name, e.getType(), e.getName()); } else if (v instanceof Method) { // Method method = (Method) v; // AnnotationVisitor av1 = av.visitAnnotation(item.name, "Lcom.googlecode.Method;"); // av1.visit("owner", method.getOwner()); // av1.visit("name", method.getName()); // av1.visit("desc", method.getType().getDesc()); // av1.visitEnd(); av.visit(item.name, v); } else { av.visit(item.name, v); } } }
From source file:egovframework.rte.itl.webservice.service.impl.EgovWebServiceClassLoaderImpl.java
License:Apache License
private byte[] createRecordClass(final String className, final RecordType recordType) throws ClassNotFoundException { String asmClassName = className.replace('.', '/'); // ClassWriter classWriter = new // ClassWriter(0); ClassWriter classWriter = new ClassWriter(0); classWriter.visit(V1_5, // version ACC_PUBLIC, // access asmClassName, // name null, // signature "java/lang/Object", // superName null); // interfaces // Create Annotation AnnotationVisitor annotationVisitor = classWriter.visitAnnotation(DESC_OF_XML_ACCESSOR_TYPE, true); annotationVisitor.visitEnum("value", // name DESC_OF_XML_ACCESS_TYPE, // desc "FIELD"); // value annotationVisitor.visitEnd();/*w w w. ja v a2 s .c om*/ // Create Fields for (Entry<String, Type> entry : recordType.getFieldTypes().entrySet()) { String fieldName = entry.getKey(); Type fieldType = entry.getValue(); Class<?> fieldTypeClass = loadClass(fieldType); String desc = org.objectweb.asm.Type.getDescriptor(fieldTypeClass); classWriter.visitField(ACC_PUBLIC, // access fieldName, // name desc, // desc null, // signature null); // value } // Create Constructor MethodVisitor methodVisitor = classWriter.visitMethod(ACC_PUBLIC, // access "<init>", // name "()V", // desc null, // signature null); // exceptions methodVisitor.visitCode(); methodVisitor.visitVarInsn(ALOAD, 0); methodVisitor.visitMethodInsn(INVOKESPECIAL, // opcode "java/lang/Object", // owner "<init>", // name "()V"); // desc methodVisitor.visitInsn(RETURN); methodVisitor.visitMaxs(1, 1); methodVisitor.visitEnd(); // Class finalize classWriter.visitEnd(); // try // { // DataOutputStream dos = new DataOutputStream( // new FileOutputStream("EgovType" + // recordType.getId() + ".class")); // dos.write(classWriter.toByteArray()); // dos.close(); // } // catch (IOException e) // { // e.printStackTrace(); // } return classWriter.toByteArray(); }
From source file:egovframework.rte.itl.webservice.service.impl.EgovWebServiceClassLoaderImpl.java
License:Apache License
private byte[] createServiceEndpointInterfaceClass( final ServiceEndpointInterfaceInfo serviceEndpointInterfaceInfo) throws ClassNotFoundException { // CHECKSTYLE:OFF String serviceEndpointInterfaceClassName = getServiceEndpointInterfaceClassName( serviceEndpointInterfaceInfo.getServiceName()); String asmServiceEndpointInterfaceClassName = serviceEndpointInterfaceClassName.replace('.', '/'); // CHECKSTYLE:ON // ClassWriter classWriter = new ClassWriter(false); ClassWriter classWriter = new ClassWriter(0); classWriter.visit(V1_5, // version ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, // access asmServiceEndpointInterfaceClassName, // name null, // signature "java/lang/Object", // superName null); // interfaces // Create Annotation AnnotationVisitor annotationVisitor = classWriter.visitAnnotation(DESC_OF_WEB_SERVICE, true); annotationVisitor.visit("targetNamespace", serviceEndpointInterfaceInfo.getNamespace()); annotationVisitor.visitEnd();//w ww. j a va 2 s.com annotationVisitor = classWriter.visitAnnotation(DESC_OF_SOAP_BINDING, true); annotationVisitor.visitEnum("parameterStyle", DESC_OF_SOAP_BINDING_PARAMETER_STYLE, "BARE"); // Create Method ServiceParamInfo returnInfo = serviceEndpointInterfaceInfo.getReturnInfo(); Collection<ServiceParamInfo> paramInfos = serviceEndpointInterfaceInfo.getParamInfos(); StringBuffer desc = new StringBuffer("("); StringBuffer signature = new StringBuffer("("); for (ServiceParamInfo info : paramInfos) { Class<?> paramClass = loadClass(info.getType()); org.objectweb.asm.Type paramType = org.objectweb.asm.Type.getType(paramClass); String paramSign = paramType.getDescriptor(); if (info.getMode().equals(OUT) || info.getMode().equals(INOUT)) { if (paramClass.isPrimitive()) { paramClass = wrapperClasses.get(paramClass); paramType = org.objectweb.asm.Type.getType(paramClass); paramSign = paramType.getDescriptor(); } paramClass = Holder.class; paramType = TYPE_OF_HOLDER; paramSign = "Ljavax/xml/ws/Holder<" + paramSign + ">;"; } desc.append(paramType.getDescriptor()); signature.append(paramSign); } desc.append(")"); signature.append(")"); // CHECKSTYLE:OFF org.objectweb.asm.Type returnType = (returnInfo == null ? returnType = org.objectweb.asm.Type.VOID_TYPE : org.objectweb.asm.Type.getType(loadClass(returnInfo.getType()))); // CHECKSTYLE:ON desc.append(returnType.getDescriptor()); signature.append(returnType.getDescriptor()); MethodVisitor methodVisitor = classWriter.visitMethod(ACC_PUBLIC | ACC_ABSTRACT, // access serviceEndpointInterfaceInfo.getOperationName(), // name desc.toString(), // desc signature.toString(), // signature null); // exceptions // @WebMethod annotationVisitor = methodVisitor.visitAnnotation(DESC_OF_WEB_METHOD, true); annotationVisitor.visit("operationName", serviceEndpointInterfaceInfo.getOperationName()); annotationVisitor.visitEnd(); // @WebResult if (returnInfo != null) { annotationVisitor = methodVisitor.visitAnnotation(DESC_OF_WEB_RESULT, true); annotationVisitor.visit("name", returnInfo.getName()); // annotationVisitor.visit("partName", // returnInfo.getName()); annotationVisitor.visit("header", returnInfo.isHeader()); annotationVisitor.visit("targetNamespace", serviceEndpointInterfaceInfo.getNamespace()); annotationVisitor.visitEnd(); } // @WebParam int index = 0; for (ServiceParamInfo info : serviceEndpointInterfaceInfo.getParamInfos()) { annotationVisitor = methodVisitor.visitParameterAnnotation(index, DESC_OF_WEB_PARAM, true); annotationVisitor.visit("name", info.getName()); // annotationVisitor.visit("partName", // info.getName()); annotationVisitor.visitEnum("mode", DESC_OF_WEB_PARAM_MODE, info.getMode().toString()); annotationVisitor.visit("header", info.isHeader()); annotationVisitor.visit("targetNamespace", serviceEndpointInterfaceInfo.getNamespace()); annotationVisitor.visitEnd(); index++; } methodVisitor.visitEnd(); // Class finalize classWriter.visitEnd(); // try // { // DataOutputStream dos = new DataOutputStream( // new FileOutputStream("EgovType" + // serviceInfo.getServiceName() + ".class")); // dos.write(classWriter.toByteArray()); // dos.close(); // } // catch (IOException e) // { // e.printStackTrace(); // } return classWriter.toByteArray(); }
From source file:jnr.ffi.provider.jffi.CodegenUtils.java
License:Apache License
public static void visitAnnotationFields(AnnotationVisitor visitor, Map<String, Object> fields) { for (Map.Entry<String, Object> fieldEntry : fields.entrySet()) { Object value = fieldEntry.getValue(); if (value.getClass().isArray()) { Object[] values = (Object[]) value; AnnotationVisitor arrayV = visitor.visitArray(fieldEntry.getKey()); for (int i = 0; i < values.length; i++) { arrayV.visit(null, values[i]); }//from w w w. j a v a 2 s . com arrayV.visitEnd(); } else if (value.getClass().isEnum()) { visitor.visitEnum(fieldEntry.getKey(), ci(value.getClass()), value.toString()); } else if (value instanceof Class) { visitor.visit(fieldEntry.getKey(), Type.getType((Class) value)); } else { visitor.visit(fieldEntry.getKey(), value); } } }