Java Code Examples for org.objectweb.asm.AnnotationVisitor#visitArray()
The following examples show how to use
org.objectweb.asm.AnnotationVisitor#visitArray() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnnotationNode.java From Cafebabe with GNU General Public License v3.0 | 6 votes |
/** * Makes the given visitor visit a given annotation value. * * @param annotationVisitor * an annotation visitor. Maybe {@literal null}. * @param name * the value name. * @param value * the actual value. */ static void accept(final AnnotationVisitor annotationVisitor, final String name, final Object value) { if (annotationVisitor != null) { if (value instanceof String[]) { String[] typeValue = (String[]) value; annotationVisitor.visitEnum(name, typeValue[0], typeValue[1]); } else if (value instanceof AnnotationNode) { AnnotationNode annotationValue = (AnnotationNode) value; annotationValue.accept(annotationVisitor.visitAnnotation(name, annotationValue.desc)); } else if (value instanceof List) { AnnotationVisitor arrayAnnotationVisitor = annotationVisitor.visitArray(name); if (arrayAnnotationVisitor != null) { List<?> arrayValue = (List<?>) value; for (int i = 0, n = arrayValue.size(); i < n; ++i) { accept(arrayAnnotationVisitor, null, arrayValue.get(i)); } arrayAnnotationVisitor.visitEnd(); } } else { annotationVisitor.visit(name, value); } } }
Example 2
Source File: MethodFlow.java From Concurnas with MIT License | 6 votes |
public static void acceptAnnotation(final AnnotationVisitor av, final String name, final Object value) { if (value instanceof String[]) { String[] typeconst = (String[]) value; av.visitEnum(name, typeconst[0], typeconst[1]); } else if (value instanceof AnnotationNode) { AnnotationNode an = (AnnotationNode) value; an.accept(av.visitAnnotation(name, an.desc)); } else if (value instanceof List<?>) { AnnotationVisitor v = av.visitArray(name); List<?> array = (List<?>) value; for (int j = 0; j < array.size(); ++j) { acceptAnnotation(v, null, array.get(j)); } v.visitEnd(); } else { av.visit(name, value); } }
Example 3
Source File: AnnotationNode.java From Concurnas with MIT License | 6 votes |
/** * Makes the given visitor visit a given annotation value. * * @param annotationVisitor an annotation visitor. Maybe {@literal null}. * @param name the value name. * @param value the actual value. */ static void accept( final AnnotationVisitor annotationVisitor, final String name, final Object value) { if (annotationVisitor != null) { if (value instanceof String[]) { String[] typeValue = (String[]) value; annotationVisitor.visitEnum(name, typeValue[0], typeValue[1]); } else if (value instanceof AnnotationNode) { AnnotationNode annotationValue = (AnnotationNode) value; annotationValue.accept(annotationVisitor.visitAnnotation(name, annotationValue.desc)); } else if (value instanceof List) { AnnotationVisitor arrayAnnotationVisitor = annotationVisitor.visitArray(name); if (arrayAnnotationVisitor != null) { List<?> arrayValue = (List<?>) value; for (int i = 0, n = arrayValue.size(); i < n; ++i) { accept(arrayAnnotationVisitor, null, arrayValue.get(i)); } arrayAnnotationVisitor.visitEnd(); } } else { annotationVisitor.visit(name, value); } } }
Example 4
Source File: StateTrackingClassVisitor.java From scott with MIT License | 6 votes |
@Override public void visitEnd() { if (instrumentationActions.isJUnit4RuleInjectionRequired) { FieldVisitor fv = super.visitField(Opcodes.ACC_PUBLIC, "scottReportingRule", Type.getDescriptor(ScottReportingRule.class), null, null); fv.visitAnnotation(Type.getDescriptor(Rule.class), true).visitEnd(); } if (instrumentationActions.isJUnit5ExtensionInjectionRequired) { AnnotationVisitor av0 = super.visitAnnotation("Lorg/junit/jupiter/api/extension/ExtendWith;", true); AnnotationVisitor av1 = av0.visitArray("value"); av1.visit(null, Type.getType("Lhu/advancedweb/scott/runtime/ScottJUnit5Extension;")); av1.visitEnd(); av0.visitEnd(); } super.visitEnd(); }
Example 5
Source File: AnnotationNode.java From JReFrameworker with MIT License | 6 votes |
/** * Makes the given visitor visit a given annotation value. * * @param annotationVisitor an annotation visitor. Maybe {@literal null}. * @param name the value name. * @param value the actual value. */ static void accept( final AnnotationVisitor annotationVisitor, final String name, final Object value) { if (annotationVisitor != null) { if (value instanceof String[]) { String[] typeValue = (String[]) value; annotationVisitor.visitEnum(name, typeValue[0], typeValue[1]); } else if (value instanceof AnnotationNode) { AnnotationNode annotationValue = (AnnotationNode) value; annotationValue.accept(annotationVisitor.visitAnnotation(name, annotationValue.desc)); } else if (value instanceof List) { AnnotationVisitor arrayAnnotationVisitor = annotationVisitor.visitArray(name); if (arrayAnnotationVisitor != null) { List<?> arrayValue = (List<?>) value; for (int i = 0, n = arrayValue.size(); i < n; ++i) { accept(arrayAnnotationVisitor, null, arrayValue.get(i)); } arrayAnnotationVisitor.visitEnd(); } } else { annotationVisitor.visit(name, value); } } }
Example 6
Source File: AnnotationNode.java From JByteMod-Beta with GNU General Public License v2.0 | 6 votes |
/** * Makes the given visitor visit a given annotation value. * * @param av * an annotation visitor. Maybe <tt>null</tt>. * @param name * the value name. * @param value * the actual value. */ static void accept(final AnnotationVisitor av, final String name, final Object value) { if (av != null) { if (value instanceof String[]) { String[] typeconst = (String[]) value; av.visitEnum(name, typeconst[0], typeconst[1]); } else if (value instanceof AnnotationNode) { AnnotationNode an = (AnnotationNode) value; an.accept(av.visitAnnotation(name, an.desc)); } else if (value instanceof List) { AnnotationVisitor v = av.visitArray(name); if (v != null) { List<?> array = (List<?>) value; for (int j = 0; j < array.size(); ++j) { accept(v, null, array.get(j)); } v.visitEnd(); } } else { av.visit(name, value); } } }
Example 7
Source File: AnnotationNode.java From JReFrameworker with MIT License | 6 votes |
/** * Makes the given visitor visit a given annotation value. * * @param annotationVisitor an annotation visitor. Maybe {@literal null}. * @param name the value name. * @param value the actual value. */ static void accept( final AnnotationVisitor annotationVisitor, final String name, final Object value) { if (annotationVisitor != null) { if (value instanceof String[]) { String[] typeValue = (String[]) value; annotationVisitor.visitEnum(name, typeValue[0], typeValue[1]); } else if (value instanceof AnnotationNode) { AnnotationNode annotationValue = (AnnotationNode) value; annotationValue.accept(annotationVisitor.visitAnnotation(name, annotationValue.desc)); } else if (value instanceof List) { AnnotationVisitor arrayAnnotationVisitor = annotationVisitor.visitArray(name); if (arrayAnnotationVisitor != null) { List<?> arrayValue = (List<?>) value; for (int i = 0, n = arrayValue.size(); i < n; ++i) { accept(arrayAnnotationVisitor, null, arrayValue.get(i)); } arrayAnnotationVisitor.visitEnd(); } } else { annotationVisitor.visit(name, value); } } }
Example 8
Source File: AbstractAnnotationDescriptionTest.java From byte-buddy with Apache License 2.0 | 5 votes |
@Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { super.visit(version, access, name, signature, superName, interfaces); AnnotationVisitor annotationVisitor = visitAnnotation(Type.getDescriptor(BrokenAnnotation.class), true); annotationVisitor.visit("incompatibleValue", INTEGER); AnnotationVisitor incompatibleValueArray = annotationVisitor.visitArray("incompatibleValueArray"); incompatibleValueArray.visit(null, INTEGER); incompatibleValueArray.visitEnd(); if (incompatibleDeclaration) { annotationVisitor.visitAnnotation("incompatibleAnnotationDeclaration", Type.getDescriptor(BrokenAnnotationProperty.class)).visitEnd(); AnnotationVisitor incompatibleAnnotationDeclarationArray = annotationVisitor.visitArray("incompatibleAnnotationDeclarationArray"); incompatibleAnnotationDeclarationArray.visitAnnotation(null, Type.getDescriptor(BrokenAnnotationProperty.class)); incompatibleAnnotationDeclarationArray.visitEnd(); annotationVisitor.visitEnum("incompatibleEnumerationDeclaration", Type.getDescriptor(BrokenEnumerationProperty.class), FOO.toUpperCase()); AnnotationVisitor incompatibleEnumerationDeclarationArray = annotationVisitor.visitArray("incompatibleAnnotationDeclarationArray"); incompatibleEnumerationDeclarationArray.visitEnum(null, Type.getDescriptor(BrokenEnumerationProperty.class), FOO.toUpperCase()); incompatibleEnumerationDeclarationArray.visitEnd(); } if (allowMissingValues) { annotationVisitor.visitEnum("unknownEnumerationConstant", Type.getDescriptor(SampleEnumeration.class), FOO); AnnotationVisitor unknownEnumConstantArray = annotationVisitor.visitArray("unknownEnumerationConstantArray"); unknownEnumConstantArray.visitEnum(null, Type.getDescriptor(SampleEnumeration.class), FOO); unknownEnumConstantArray.visitEnd(); annotationVisitor.visit("missingType", Type.getType("Lnet/bytebuddy/inexistant/Foo;")); AnnotationVisitor missingTypeArray = annotationVisitor.visitArray("missingTypeArray"); missingTypeArray.visit(null, Type.getType("Lnet/bytebuddy/inexistant/Foo;")); missingTypeArray.visitEnd(); } annotationVisitor.visitEnd(); }
Example 9
Source File: DynamicEntityGenerator.java From we-cmdb with Apache License 2.0 | 5 votes |
private static void writeGetterForMapperBy(ClassWriter classWriter, FieldNode field, String className, String getter) { MethodVisitor methodVisitor; AnnotationVisitor annotationVisitor0; methodVisitor = classWriter.visitMethod(ACC_PUBLIC, getter, "()Ljava/util/Set;", "()" + getTypeSiganitureForOneToMany(field.getTypeDesc()), null); if (DynamicEntityType.MultiReference.equals(field.getEntityType())) { annotationVisitor0 = methodVisitor.visitAnnotation("Ljavax/persistence/ManyToMany;", true); annotationVisitor0.visit("mappedBy", field.getMappedBy()); annotationVisitor0.visitEnd(); } else { annotationVisitor0 = methodVisitor.visitAnnotation("Ljavax/persistence/OneToMany;", true); annotationVisitor0.visit("mappedBy", field.getMappedBy()); if (DynamicEntityType.MultiSelection.equals(field.getEntityType())) { annotationVisitor0.visitEnum("fetch", "Ljavax/persistence/FetchType;", "EAGER"); AnnotationVisitor annotationVisitor1 = annotationVisitor0.visitArray("cascade"); annotationVisitor1.visitEnum(null, "Ljavax/persistence/CascadeType;", CascadeType.ALL.toString()); annotationVisitor1.visitEnd(); } annotationVisitor0.visitEnd(); } { annotationVisitor0 = methodVisitor.visitAnnotation("Lcom/fasterxml/jackson/annotation/JsonIgnore;", true); annotationVisitor0.visitEnd(); } // getter method body methodVisitor.visitVarInsn(ALOAD, 0); methodVisitor.visitFieldInsn(GETFIELD, className, field.getName(), "Ljava/util/Set;"); methodVisitor.visitInsn(ARETURN); methodVisitor.visitMaxs(1, 1); methodVisitor.visitEnd(); }
Example 10
Source File: AsmClassGenerator.java From groovy with Apache License 2.0 | 5 votes |
private void visitArrayAttributes(final AnnotationNode an, final Map<String, ListExpression> arrayAttr, final AnnotationVisitor av) { if (arrayAttr.isEmpty()) return; for (Map.Entry<String, ListExpression> entry : arrayAttr.entrySet()) { AnnotationVisitor av2 = av.visitArray(entry.getKey()); List<Expression> values = entry.getValue().getExpressions(); if (!values.isEmpty()) { int arrayElementType = determineCommonArrayType(values); for (Expression exprChild : values) { visitAnnotationArrayElement(exprChild, arrayElementType, av2); } } av2.visitEnd(); } }
Example 11
Source File: DynamicClassFactory.java From caravan with Apache License 2.0 | 5 votes |
private Class<?> createClass(ClassPair classPair) { String className = generateClassName(classPair); String classStr = className.replaceAll("\\.", "/"); String keyClassType = Type.getDescriptor(classPair.keyClass); String valueClassType = Type.getDescriptor(classPair.valueClass); ClassWriter cw = new ClassWriter(0); cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, className, null, "java/lang/Object", new String[]{interfaceName}); AnnotationVisitor anno = cw.visitAnnotation(Type.getDescriptor(JsonPropertyOrder.class), true); AnnotationVisitor aa = anno.visitArray("value"); aa.visit("", "key"); aa.visit("", "value"); aa.visitEnd(); anno.visitEnd(); FieldVisitor keyField = cw.visitField(ACC_PRIVATE, "key", keyClassType, null, null); keyField.visitEnd(); FieldVisitor valueField = cw.visitField(ACC_PRIVATE, "value", valueClassType, null, null); valueField.visitEnd(); MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitMaxs(2, 1); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(Object.class), "<init>", "()V", false); // call the constructor of super class mv.visitInsn(RETURN); mv.visitEnd(); addGetterSetter(classPair, className, classStr, keyClassType, valueClassType, cw); addKVPairMethods(classPair, className, classStr, keyClassType, valueClassType, cw); cw.visitEnd(); return defineClass(className, cw.toByteArray()); }
Example 12
Source File: BytecodeOutputter.java From Concurnas with MIT License | 5 votes |
public static void addNullablefieldAnnotation(AnnotationVisitor av0, boolean[] nullstatus) { AnnotationVisitor av1 = av0.visitArray("nullable"); for(boolean item : nullstatus) { av1.visit(null, item?Boolean.TRUE:Boolean.FALSE); } av1.visitEnd(); }
Example 13
Source File: AnnotationUtils.java From gizmo with Apache License 2.0 | 5 votes |
static void visitAnnotationValue(AnnotationVisitor visitor, String key, Object value) { if (value.getClass().isArray()) { AnnotationVisitor arrayVisitor = visitor.visitArray(key); for (Object arrayValue : (Object[]) value) { // Default key is 'value'. It can be changed by using AnnotationValue type. visitAnnotationValue(arrayVisitor, "value", arrayValue); } arrayVisitor.visitEnd(); } else if (value instanceof AnnotationValue) { AnnotationValue annotationValue = (AnnotationValue) value; visitor.visit(annotationValue.name(), annotationValue.value()); } else { visitor.visit(key, value); } }
Example 14
Source File: AnnotatedClassTest.java From JAADAS with GNU General Public License v3.0 | 4 votes |
@Override protected void generate(TraceClassVisitor cw) { MethodVisitor mv; AnnotationVisitor av0; cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/AnnotatedClass", null, "java/lang/Object", null); cw.visitSource("AnnotatedClass.java", null); { av0 = cw.visitAnnotation("Lsoot/asm/backend/targets/MyTestAnnotation;", true); av0.visit("iVal", new Integer(1)); av0.visit("fVal", new Float("1.0")); av0.visit("lVal", new Long(1L)); av0.visit("dVal", new Double("1.0")); av0.visit("zVal", Boolean.TRUE); av0.visit("bVal", new Byte((byte)1)); av0.visit("sVal", new Short((short)1)); av0.visit("strVal", "1"); av0.visit("rVal", Type.getType("Lsoot/asm/backend/targets/AnnotatedClass;")); av0.visit("iAVal", new int[] {1,2,3,4}); { AnnotationVisitor av1 = av0.visitArray("sAVal"); av1.visit(null, "A"); av1.visit(null, "B"); av1.visit(null, "C"); av1.visitEnd(); } av0.visitEnd(); } { 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(0, 0); mv.visitEnd(); } cw.visitEnd(); }
Example 15
Source File: AnnotatedMethodTest.java From JAADAS with GNU General Public License v3.0 | 4 votes |
@Override protected void generate(TraceClassVisitor cw) { MethodVisitor mv; AnnotationVisitor av0; cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/AnnotatedMethod", null, "java/lang/Object", null); cw.visitSource("AnnotatedMethod.java", 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(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "doSth", "()V", null, null); { av0 = mv.visitAnnotation("Lsoot/asm/backend/targets/MyTestAnnotation;", true); av0.visit("iVal", new Integer(124)); av0.visit("fVal", new Float("5132.0")); av0.visit("lVal", new Long(5123L)); av0.visit("dVal", new Double("745.0")); av0.visit("zVal", Boolean.TRUE); av0.visit("bVal", new Byte((byte)1)); av0.visit("sVal", new Short((short)123)); av0.visit("strVal", "435243"); av0.visit("rVal", Type.getType("Lsoot/asm/backend/targets/AnnotatedClass;")); av0.visit("iAVal", new int[] {123,234,345,456}); { AnnotationVisitor av1 = av0.visitArray("sAVal"); av1.visit(null, "A"); av1.visit(null, "B"); av1.visit(null, "C"); av1.visitEnd(); } av0.visitEnd(); } mv.visitCode(); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); }
Example 16
Source File: AnnotatedParameterTest.java From JAADAS with GNU General Public License v3.0 | 4 votes |
@Override protected void generate(TraceClassVisitor cw) { MethodVisitor mv; AnnotationVisitor av0; cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/AnnotatedParameter", null, "java/lang/Object", null); cw.visitSource("AnnotatedParameter.java", 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(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "doSth", "(Ljava/lang/String;)V", null, null); { av0 = mv.visitParameterAnnotation(0, "Lsoot/asm/backend/targets/MyTestAnnotation;", true); av0.visit("iVal", new Integer(1)); av0.visit("fVal", new Float("1.0")); av0.visit("lVal", new Long(1L)); av0.visit("dVal", new Double("1.0")); av0.visit("zVal", Boolean.TRUE); av0.visit("bVal", new Byte((byte)1)); av0.visit("sVal", new Short((short)1)); av0.visit("strVal", "1"); av0.visit("rVal", Type.getType("Lsoot/asm/backend/targets/AnnotatedClass;")); av0.visit("iAVal", new int[] {1,2,3,4}); { AnnotationVisitor av1 = av0.visitArray("sAVal"); av1.visit(null, "A"); av1.visit(null, "B"); av1.visit(null, "C"); av1.visitEnd(); } av0.visitEnd(); } mv.visitCode(); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); }
Example 17
Source File: AnnotatedAnnotatedClassTest.java From JAADAS with GNU General Public License v3.0 | 4 votes |
@Override protected void generate(TraceClassVisitor cw) { MethodVisitor mv; AnnotationVisitor av0; cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/AnnotatedAnnotatedClass", null, "java/lang/Object", null); cw.visitSource("AnnotatedAnnotatedClass.java", null); { av0 = cw.visitAnnotation("Lsoot/asm/backend/targets/MyAnnotatedAnnotation;", false); { AnnotationVisitor av1 = av0.visitAnnotation("value", "Lsoot/asm/backend/targets/MyTestAnnotation;"); av1.visit("iVal", new Integer(1)); av1.visit("fVal", new Float("1.0")); av1.visit("lVal", new Long(1L)); av1.visit("dVal", new Double("1.0")); av1.visit("zVal", Boolean.TRUE); av1.visit("bVal", new Byte((byte)1)); av1.visit("sVal", new Short((short)1)); av1.visit("strVal", "1"); av1.visit("rVal", Type.getType("Lsoot/asm/backend/targets/AnnotatedClass;")); av1.visit("iAVal", new int[] {1,2,3,4}); { AnnotationVisitor av2 = av1.visitArray("sAVal"); av2.visit(null, "A"); av2.visit(null, "B"); av2.visit(null, "C"); av2.visitEnd(); } av1.visitEnd(); } av0.visitEnd(); } { 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(0, 0); mv.visitEnd(); } cw.visitEnd(); }
Example 18
Source File: AnnotatedFieldTest.java From JAADAS with GNU General Public License v3.0 | 4 votes |
@Override protected void generate(TraceClassVisitor cw) { FieldVisitor fv; MethodVisitor mv; AnnotationVisitor av0; cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/AnnotatedField", null, "java/lang/Object", null); cw.visitSource("AnnotatedField.java", null); { fv = cw.visitField(0, "a", "Ljava/lang/String;", null, null); { av0 = fv.visitAnnotation("Lsoot/asm/backend/targets/MyTestAnnotation;", true); av0.visit("iVal", new Integer(124)); av0.visit("fVal", new Float("5132.0")); av0.visit("lVal", new Long(5123L)); av0.visit("dVal", new Double("745.0")); av0.visit("zVal", Boolean.TRUE); av0.visit("bVal", new Byte((byte)1)); av0.visit("sVal", new Short((short)123)); av0.visit("strVal", "435243"); av0.visit("rVal", Type.getType("Lsoot/asm/backend/targets/AnnotatedClass;")); av0.visit("iAVal", new int[] {123,234,345,456}); { AnnotationVisitor av1 = av0.visitArray("sAVal"); av1.visit(null, "A"); av1.visit(null, "B"); av1.visit(null, "C"); av1.visitEnd(); } av0.visitEnd(); } fv.visitEnd(); } { 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(0, 0); mv.visitEnd(); } cw.visitEnd(); }
Example 19
Source File: AbstractASMBackend.java From JAADAS with GNU General Public License v3.0 | 4 votes |
/** * Emits the bytecode for the values of an annotation * @param av The AnnotationVisitor to emit the bytecode to * @param elements A collection of AnnatiotionElem that are the values of the annotation * @param addName True, if the name of the annotation has to be added, false otherwise (should be false only in recursive calls!) */ protected void generateAnnotationElems(AnnotationVisitor av, Collection<AnnotationElem> elements, boolean addName) { if (av != null) { Iterator<AnnotationElem> it = elements.iterator(); while (it.hasNext()) { AnnotationElem elem = it.next(); if (elem instanceof AnnotationEnumElem) { AnnotationEnumElem enumElem = (AnnotationEnumElem) elem; av.visitEnum(enumElem.getName(), enumElem.getTypeName(), enumElem.getConstantName()); } else if (elem instanceof AnnotationArrayElem) { AnnotationArrayElem arrayElem = (AnnotationArrayElem) elem; AnnotationVisitor arrayVisitor = av.visitArray(arrayElem .getName()); generateAnnotationElems(arrayVisitor, arrayElem.getValues(), false); } else if (elem instanceof AnnotationAnnotationElem) { AnnotationAnnotationElem aElem = (AnnotationAnnotationElem) elem; AnnotationVisitor aVisitor = av.visitAnnotation( aElem.getName(), aElem.getValue().getType()); generateAnnotationElems(aVisitor, aElem.getValue() .getElems(), true); } else { Object val = null; if (elem instanceof AnnotationIntElem) { AnnotationIntElem intElem = (AnnotationIntElem) elem; int value = intElem.getValue(); switch (intElem.getKind()) { case 'B': val = (byte) value; break; case 'Z': val = (value == 1); break; case 'I': val = value; break; case 'S': val = (short) value; break; } } else if (elem instanceof AnnotationFloatElem) { AnnotationFloatElem floatElem = (AnnotationFloatElem) elem; val = floatElem.getValue(); } else if (elem instanceof AnnotationLongElem) { AnnotationLongElem longElem = (AnnotationLongElem) elem; val = longElem.getValue(); } else if (elem instanceof AnnotationDoubleElem) { AnnotationDoubleElem doubleElem = (AnnotationDoubleElem) elem; val = doubleElem.getValue(); } else if (elem instanceof AnnotationStringElem) { AnnotationStringElem stringElem = (AnnotationStringElem) elem; val = stringElem.getValue(); } else if (elem instanceof AnnotationClassElem) { AnnotationClassElem classElem = (AnnotationClassElem) elem; val = org.objectweb.asm.Type.getType(classElem .getDesc()); } if(addName){ av.visit(elem.getName(), val); } else{ av.visit(null, val); } } } av.visitEnd(); } }