Search in sources :

Example 6 with FieldVisitor

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

the class FieldNode method accept.

/**
     * Makes the given class visitor visit this field.
     *
     * @param cv
     *            a class visitor.
     */
public void accept(final ClassVisitor cv) {
    FieldVisitor fv = cv.visitField(access, name, desc, signature, value);
    if (fv == null) {
        return;
    }
    int i, n;
    n = visibleAnnotations == null ? 0 : visibleAnnotations.size();
    for (i = 0; i < n; ++i) {
        AnnotationNode an = visibleAnnotations.get(i);
        an.accept(fv.visitAnnotation(an.desc, true));
    }
    n = invisibleAnnotations == null ? 0 : invisibleAnnotations.size();
    for (i = 0; i < n; ++i) {
        AnnotationNode an = invisibleAnnotations.get(i);
        an.accept(fv.visitAnnotation(an.desc, false));
    }
    n = visibleTypeAnnotations == null ? 0 : visibleTypeAnnotations.size();
    for (i = 0; i < n; ++i) {
        TypeAnnotationNode an = visibleTypeAnnotations.get(i);
        an.accept(fv.visitTypeAnnotation(an.typeRef, an.typePath, an.desc, true));
    }
    n = invisibleTypeAnnotations == null ? 0 : invisibleTypeAnnotations.size();
    for (i = 0; i < n; ++i) {
        TypeAnnotationNode an = invisibleTypeAnnotations.get(i);
        an.accept(fv.visitTypeAnnotation(an.typeRef, an.typePath, an.desc, false));
    }
    n = attrs == null ? 0 : attrs.size();
    for (i = 0; i < n; ++i) {
        fv.visitAttribute(attrs.get(i));
    }
    fv.visitEnd();
}
Also used : FieldVisitor(jdk.internal.org.objectweb.asm.FieldVisitor)

Example 7 with FieldVisitor

use of jdk.internal.org.objectweb.asm.FieldVisitor 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)

Example 8 with FieldVisitor

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

the class TraceClassVisitor method visitField.

@Override
public FieldVisitor visitField(final int access, final String name, final String desc, final String signature, final Object value) {
    Printer p = this.p.visitField(access, name, desc, signature, value);
    FieldVisitor fv = cv == null ? null : cv.visitField(access, name, desc, signature, value);
    return new TraceFieldVisitor(fv, p);
}
Also used : FieldVisitor(jdk.internal.org.objectweb.asm.FieldVisitor)

Aggregations

FieldVisitor (jdk.internal.org.objectweb.asm.FieldVisitor)8 ClassWriter (jdk.internal.org.objectweb.asm.ClassWriter)2 MethodVisitor (jdk.internal.org.objectweb.asm.MethodVisitor)2 ConstantDescriptor (com.ibm.j9ddr.StructureReader.ConstantDescriptor)1 FieldDescriptor (com.ibm.j9ddr.StructureReader.FieldDescriptor)1 AnnotationVisitor (jdk.internal.org.objectweb.asm.AnnotationVisitor)1 ClassReader (jdk.internal.org.objectweb.asm.ClassReader)1 ClassVisitor (jdk.internal.org.objectweb.asm.ClassVisitor)1