Search in sources :

Example 16 with AnnotationVisitor

use of jdk.internal.org.objectweb.asm.AnnotationVisitor in project Bytecoder by mirkosertic.

the class TraceAnnotationVisitor method visitAnnotation.

@Override
public AnnotationVisitor visitAnnotation(final String name, final String desc) {
    Printer p = this.p.visitAnnotation(name, desc);
    AnnotationVisitor av = this.av == null ? null : this.av.visitAnnotation(name, desc);
    return new TraceAnnotationVisitor(av, p);
}
Also used : AnnotationVisitor(jdk.internal.org.objectweb.asm.AnnotationVisitor)

Example 17 with AnnotationVisitor

use of jdk.internal.org.objectweb.asm.AnnotationVisitor in project jdk8u_jdk by JetBrains.

the class TraceFieldVisitor method visitTypeAnnotation.

@Override
public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) {
    Printer p = this.p.visitFieldTypeAnnotation(typeRef, typePath, desc, visible);
    AnnotationVisitor av = fv == null ? null : fv.visitTypeAnnotation(typeRef, typePath, desc, visible);
    return new TraceAnnotationVisitor(av, p);
}
Also used : AnnotationVisitor(jdk.internal.org.objectweb.asm.AnnotationVisitor)

Example 18 with AnnotationVisitor

use of jdk.internal.org.objectweb.asm.AnnotationVisitor in project jdk8u_jdk by JetBrains.

the class TraceMethodVisitor method visitAnnotation.

@Override
public AnnotationVisitor visitAnnotation(final String desc, final boolean visible) {
    Printer p = this.p.visitMethodAnnotation(desc, visible);
    AnnotationVisitor av = mv == null ? null : mv.visitAnnotation(desc, visible);
    return new TraceAnnotationVisitor(av, p);
}
Also used : AnnotationVisitor(jdk.internal.org.objectweb.asm.AnnotationVisitor)

Example 19 with AnnotationVisitor

use of jdk.internal.org.objectweb.asm.AnnotationVisitor in project jdk8u_jdk by JetBrains.

the class AnnotationNode method accept.

/**
     * 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);
        }
    }
}
Also used : AnnotationVisitor(jdk.internal.org.objectweb.asm.AnnotationVisitor) List(java.util.List) ArrayList(java.util.ArrayList)

Example 20 with AnnotationVisitor

use of jdk.internal.org.objectweb.asm.AnnotationVisitor in project openj9 by eclipse.

the class Cmvc196982 method addAnnotation.

/*
	 * Transform classToTransform by adding the given annotation to all already-annotated methods, fields and constructors in the class.
	 * Return the modified class file bytes.
	 */
private byte[] addAnnotation(Class<?> classToTransform, final Class<?> annotation) throws IOException {
    ClassWriter writer = new ClassWriter(0);
    new ClassReader(Type.getInternalName(classToTransform)).accept(new ClassVisitor(ASM4, writer) {

        @Override
        public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
            return new MethodVisitor(ASM4, cv.visitMethod(access, name, desc, signature, exceptions)) {

                @Override
                public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
                    mv.visitAnnotation(Type.getDescriptor(annotation), true).visitEnd();
                    return mv.visitAnnotation(desc, visible);
                }
            };
        }

        @Override
        public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
            return new FieldVisitor(ASM4, cv.visitField(access, name, desc, signature, value)) {

                @Override
                public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
                    fv.visitAnnotation(Type.getDescriptor(annotation), true).visitEnd();
                    return fv.visitAnnotation(desc, visible);
                }
            };
        }
    }, 0);
    return writer.toByteArray();
}
Also used : AnnotationVisitor(jdk.internal.org.objectweb.asm.AnnotationVisitor) ClassReader(jdk.internal.org.objectweb.asm.ClassReader) ClassVisitor(jdk.internal.org.objectweb.asm.ClassVisitor) FieldVisitor(jdk.internal.org.objectweb.asm.FieldVisitor) ClassWriter(jdk.internal.org.objectweb.asm.ClassWriter) MethodVisitor(jdk.internal.org.objectweb.asm.MethodVisitor)

Aggregations

AnnotationVisitor (jdk.internal.org.objectweb.asm.AnnotationVisitor)31 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ClassReader (jdk.internal.org.objectweb.asm.ClassReader)1 ClassVisitor (jdk.internal.org.objectweb.asm.ClassVisitor)1 ClassWriter (jdk.internal.org.objectweb.asm.ClassWriter)1 FieldVisitor (jdk.internal.org.objectweb.asm.FieldVisitor)1 MethodVisitor (jdk.internal.org.objectweb.asm.MethodVisitor)1