Package org.ow2.asm

Examples of org.ow2.asm.FieldVisitor


        generate(dir, "pkg/Outer$Inner.class", dumpInner());
    }

    public byte[] dump() {
        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
        FieldVisitor fv;
        MethodVisitor mv;

        cw.visit(V1_4,
                ACC_PUBLIC + ACC_SUPER + ACC_DEPRECATED,
                "pkg/Outer",
                null,
                "java/lang/Object",
                null);

        cw.visitInnerClass("pkg/Outer$Inner", "pkg/Outer", "C", 0);
        cw.visitInnerClass("pkg/Outer$1", null, null, 0);

        fv = cw.visitField(ACC_PRIVATE + ACC_DEPRECATED, "i", "I", null, null);
        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");
View Full Code Here


        return cw.toByteArray();
    }

    public static byte[] dump1() {
        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
        FieldVisitor fv;
        MethodVisitor mv;

        cw.visit(V1_4, ACC_SUPER, "pkg/Outer$1", null, "pkg/Outer", null);

        cw.visitOuterClass("pkg/Outer", "m", "()V");
        cw.visitInnerClass("pkg/Outer$1", null, null, 0);

        fv = cw.visitField(ACC_FINAL + ACC_SYNTHETIC,
                "this$0",
                "Lpkg/Outer;",
                null,
                null);
        fv.visitEnd();

        mv = cw.visitMethod(0, "<init>", "(Lpkg/Outer;)V", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ALOAD, 1);
View Full Code Here

        return cw.toByteArray();
    }

    public static byte[] dumpInner() {
        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
        FieldVisitor fv;
        MethodVisitor mv;

        cw.visit(V1_4,
                ACC_SUPER,
                "pkg/Outer$Inner",
                null,
                "java/lang/Object",
                null);

        cw.visitInnerClass("pkg/Outer$Inner", "pkg/Outer", "C", 0);

        fv = cw.visitField(ACC_FINAL + ACC_SYNTHETIC,
                "this$0",
                "Lpkg/Outer;",
                null,
                null);
        fv.visitEnd();

        mv = cw.visitMethod(0, "<init>", "(Lpkg/Outer;)V", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ALOAD, 1);
View Full Code Here

        return cw.toByteArray();
    }

    public byte[] dumpAnnotated() {
        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
        FieldVisitor fv;
        MethodVisitor mv;
        AnnotationVisitor av0, av1;

        cw.visit(V1_5,
                ACC_PUBLIC + ACC_SUPER,
                "pkg/Annotated",
                null,
                "java/lang/Object",
                null);

        // visible class annotation
        cw.visitAnnotation(DEPRECATED, true).visitEnd();

        // invisible class annotation, with values of all types
        av0 = cw.visitAnnotation("Lpkg/Annotation;", false);
        av0.visit("byteValue", new Byte((byte) 0));
        av0.visit("charValue", new Character((char) 48));
        av0.visit("booleanValue", Boolean.FALSE);
        av0.visit("intValue", new Integer(0));
        av0.visit("shortValue", new Short((short) 0));
        av0.visit("longValue", new Long(0L));
        av0.visit("floatValue", new Float("0.0"));
        av0.visit("doubleValue", new Double("0.0"));
        av0.visit("stringValue", "0");
        av0.visitEnum("enumValue", "Lpkg/Enum;", "V0");
        av0.visitAnnotation("annotationValue", DOC).visitEnd();
        av0.visit("classValue", Type.getType("Lpkg/Annotation;"));
        av0.visit("byteArrayValue", new byte[] { 1, 0 });
        av0.visit("charArrayValue", new char[] { '1', '0' });
        av0.visit("booleanArrayValue", new boolean[] { true, false });
        av0.visit("intArrayValue", new int[] { 1, 0 });
        av0.visit("shortArrayValue", new short[] { (short) 1, (short) 0 });
        av0.visit("longArrayValue", new long[] { 1L, 0L });
        av0.visit("floatArrayValue", new float[] { 1.0f, 0.0f });
        av0.visit("doubleArrayValue", new double[] { 1.0d, 0.0d });
        av1 = av0.visitArray("stringArrayValue");
        av1.visit(null, "1");
        av1.visit(null, "0");
        av1.visitEnd();
        av0.visitArray("classArrayValue").visitEnd();
        av1 = av0.visitArray("enumArrayValue");
        av1.visitEnum(null, "Lpkg/Enum;", "V1");
        av1.visitEnum(null, "Lpkg/Enum;", "V2");
        av1.visitEnd();
        av0.visitArray("annotationArrayValue").visitEnd();
        av0.visitEnd();

        fv = cw.visitField(ACC_PUBLIC, "f", "I", null, null);
        // visible field annotation
        fv.visitAnnotation(DEPRECATED, true).visitEnd();
        // invisible field annotation
        av0 = fv.visitAnnotation("Lpkg/Annotation;", false);
        av0.visitEnum("enumValue", "Lpkg/Enum;", "V0");
        av0.visitEnd();
        fv.visitEnd();

        mv = cw.visitMethod(ACC_PUBLIC, "<init>", "(IIIIIIIIII)V", null, null);
        // visible method annotation
        mv.visitAnnotation(DEPRECATED, true).visitEnd();
        // invisible method annotation
View Full Code Here

        } catch (Exception e) {
        }
    }

    public void testIllegalFieldMemberVisitAfterEnd() {
        FieldVisitor fv = new CheckFieldAdapter(new EmptyVisitor());
        fv.visitEnd();
        try {
            fv.visitAttribute(new Comment());
            fail();
        } catch (Exception e) {
        }
    }
View Full Code Here

        } catch (Exception e) {
        }
    }

    public void testIllegalFieldAttribute() {
        FieldVisitor fv = new CheckFieldAdapter(new EmptyVisitor());
        try {
            fv.visitAttribute(null);
            fail();
        } catch (Exception e) {
        }
    }
View Full Code Here

                "java/lang/Object",
                new String[] { "java/io/Serializable" });

        cw.visitSource("Debug.java", "source-debug");

        FieldVisitor fv = cw.visitField(ACC_FINAL + ACC_STATIC,
                "serialVersionUID",
                "J",
                null,
                new Long(1L));
        fv.visitEnd();

        MethodVisitor mv = cw.visitMethod(ACC_PUBLIC,
                "<init>",
                "()V",
                null,
View Full Code Here

        final String name,
        final String desc,
        final String signature,
        final Object value)
    {
        FieldVisitor fv = super.visitField(access, name, desc, signature, value);
        fv.visitAttribute(new CommentAttribute("this is a field comment"));
        return fv;
    }
View Full Code Here

    }

    public byte[] dump() {
        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
        MethodVisitor mv;
        FieldVisitor fv;

        cw.visit(V1_6,
                ACC_PUBLIC + ACC_SUPER,
                "pkg/FrameTable",
                null,
                "java/lang/Object",
                null);

        fv = cw.visitField(M, "long", "Ljava/lang/Long;", null, null);
        fv.visitEnd();

        fv = cw.visitField(M, "double", "Ljava/lang/Double;", null, null);
        fv.visitEnd();

        fv = cw.visitField(M, "number", "Ljava/lang/Number;", null, null);
        fv.visitEnd();

        fv = cw.visitField(M, "serializable", I1, null, null);
        fv.visitEnd();

        fv = cw.visitField(M, "comparable", I2, null, null);
        fv.visitEnd();

        fv = cw.visitField(M, "longArray", "[Ljava/lang/Long;", null, null);
        fv.visitEnd();

        fv = cw.visitField(M, "intArray", "[I", null, null);
        fv.visitEnd();

        fv = cw.visitField(M, "floatArray", "[F", null, null);
        fv.visitEnd();

        fv = cw.visitField(M, "objectArray", "[Ljava/lang/Object;", null, null);
        fv.visitEnd();

        mv = cw.visitMethod(ACC_PUBLIC,
                "<init>",
                "(Ljava/lang/Object;)V",
                null,
View Full Code Here

        generate(dir, "pkg/Attribute.class", dump());
    }

    public byte[] dump() {
        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
        FieldVisitor fv;
        MethodVisitor mv;

        cw.visit(V1_3,
                ACC_PUBLIC + ACC_SYNTHETIC,
                "pkg/Attribute",
                null,
                "java/lang/Object",
                null);

        cw.visitAttribute(new Comment());

        fv = cw.visitField(ACC_PUBLIC, "f", "I", null, null);
        fv.visitAttribute(new Comment());
        fv.visitEnd();

        mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
        mv.visitAttribute(new Comment());
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
View Full Code Here

TOP

Related Classes of org.ow2.asm.FieldVisitor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.