Search in sources :

Example 1 with Type.getType

use of org.objectweb.asm.Type.getType in project felix by apache.

the class AnnotationPlayback method acceptArray.

private void acceptArray(final Map<String, Object> values, final AnnotationVisitor visitor) {
    Map<String, Object> copy = new HashMap<String, Object>(values);
    for (Map.Entry<String, Object> entry : copy.entrySet()) {
        Class<?> type = entry.getValue().getClass();
        if (type.isArray()) {
            // Simple arrays have been visited using AnnotationVisitor.visit(String, Object)
            AnnotationVisitor arrayVisitor = visitor.visitArray(entry.getKey());
            if (arrayVisitor != null) {
                Object[] array = (Object[]) entry.getValue();
                Class<?> componentType = array.getClass().getComponentType();
                Type asmType = Type.getType(componentType);
                if (componentType.isEnum()) {
                    for (Object o : array) {
                        Enum eValue = (Enum) o;
                        arrayVisitor.visitEnum(null, asmType.getDescriptor(), eValue.name());
                    }
                } else if (componentType.isAnnotation()) {
                    for (Object o : array) {
                        Annotation annotation = (Annotation) o;
                        AnnotationVisitor annotationVisitor = arrayVisitor.visitAnnotation(null, asmType.getDescriptor());
                        if (annotationVisitor != null) {
                            AnnotationPlayback playback = new AnnotationPlayback(annotation);
                            playback.accept(annotationVisitor);
                        }
                    }
                } else {
                    for (Object o : array) {
                        arrayVisitor.visit(null, transform(o));
                    }
                }
                arrayVisitor.visitEnd();
            }
            values.remove(entry.getKey());
        }
    }
}
Also used : HashMap(java.util.HashMap) Annotation(java.lang.annotation.Annotation) Type.getType(org.objectweb.asm.Type.getType) Type(org.objectweb.asm.Type) AnnotationVisitor(org.objectweb.asm.AnnotationVisitor) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Annotation (java.lang.annotation.Annotation)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AnnotationVisitor (org.objectweb.asm.AnnotationVisitor)1 Type (org.objectweb.asm.Type)1 Type.getType (org.objectweb.asm.Type.getType)1