KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > annotations > ValuesDump


1 package annotations;
2 import org.objectweb.asm.*;
3 public class ValuesDump implements Opcodes {
4
5 public static byte[] dump () throws Exception JavaDoc {
6
7 ClassWriter cw = new ClassWriter(false);
8 FieldVisitor fv;
9 MethodVisitor mv;
10 AnnotationVisitor av0;
11
12 cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, "annotations/Values", null, "java/lang/Object", null);
13
14 cw.visitSource("Values.java", null);
15
16 {
17 av0 = cw.visitAnnotation("Lannotations/ValuesAnnotation;", true);
18 av0.visit("byteValue", new Byte JavaDoc((byte)1));
19 av0.visit("charValue", new Character JavaDoc((char)65));
20 av0.visit("booleanValue", new Boolean JavaDoc(true));
21 av0.visit("intValue", new Integer JavaDoc(1));
22 av0.visit("shortValue", new Short JavaDoc((short)1));
23 av0.visit("longValue", new Long JavaDoc(1L));
24 av0.visit("floatValue", new Float JavaDoc("1.0"));
25 av0.visit("doubleValue", new Double JavaDoc("1.0"));
26 av0.visit("stringValue", "A");
27 av0.visitEnum("enumValue", "Lannotations/ValuesEnum;", "ONE");
28 {
29 AnnotationVisitor av1 = av0.visitAnnotation("annotationValue", "Lannotations/ValueAttrAnnotation;");
30 av1.visit("value", "annotation");
31 av1.visitEnd();
32 }
33 av0.visit("classValue", Type.getType("Lannotations/Values;"));
34 av0.visit("byteArrayValue", new byte[] {1,-1});
35 av0.visit("charArrayValue", new char[] {(char)99,(char)98,(char)65535});
36 av0.visit("booleanArrayValue", new boolean[] {true,false});
37 av0.visit("intArrayValue", new int[] {1,-1});
38 av0.visit("shortArrayValue", new short[] {(short)1,(short)-1});
39 av0.visit("longArrayValue", new long[] {1L,-1L});
40 av0.visit("floatArrayValue", new float[] {1.0f,-1.0f});
41 av0.visit("doubleArrayValue", new double[] {1.0d,-1.0d});
42 {
43 AnnotationVisitor av1 = av0.visitArray("stringArrayValue");
44 av1.visit(null, "aa");
45 av1.visit(null, "bb");
46 av1.visitEnd();
47 }
48 {
49 AnnotationVisitor av1 = av0.visitArray("enumArrayValue");
50 av1.visitEnum(null, "Lannotations/ValuesEnum;", "ONE");
51 av1.visitEnum(null, "Lannotations/ValuesEnum;", "TWO");
52 av1.visitEnd();
53 }
54 {
55 AnnotationVisitor av1 = av0.visitArray("annotationArrayValue");
56 {
57 AnnotationVisitor av2 = av1.visitAnnotation(null, "Lannotations/ValueAttrAnnotation;");
58 av2.visit("value", "annotation1");
59 av2.visitEnd();
60 }
61 {
62 AnnotationVisitor av2 = av1.visitAnnotation(null, "Lannotations/ValueAttrAnnotation;");
63 av2.visit("value", "annotation2");
64 av2.visitEnd();
65 }
66 av1.visitEnd();
67 }
68 {
69 AnnotationVisitor av1 = av0.visitArray("classArrayValue");
70 av1.visit(null, Type.getType("Lannotations/Values;"));
71 av1.visit(null, Type.getType("Lannotations/Values;"));
72 av1.visitEnd();
73 }
74 av0.visitEnd();
75 }
76 {
77 av0 = cw.visitAnnotation("Lannotations/ValueAttrAnnotation1;", true);
78 av0.visit("value", "classAnnotation1");
79 av0.visitEnd();
80 }
81 {
82 av0 = cw.visitAnnotation("Lannotations/ValueAttrAnnotation2;", true);
83 av0.visit("value", "classAnnotation2");
84 av0.visitEnd();
85 }
86 {
87 fv = cw.visitField(ACC_PUBLIC, "testfield", "Ljava/lang/String;", null, null);
88 {
89 av0 = fv.visitAnnotation("Lannotations/ValueAttrAnnotation1;", true);
90 av0.visit("value", "fieldAnnotation1");
91 av0.visitEnd();
92 }
93 {
94 av0 = fv.visitAnnotation("Lannotations/ValueAttrAnnotation2;", true);
95 av0.visit("value", "fieldAnnotation2");
96 av0.visitEnd();
97 }
98 fv.visitEnd();
99 }
100 {
101 mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
102 mv.visitVarInsn(ALOAD, 0);
103 mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
104 mv.visitVarInsn(ALOAD, 0);
105 mv.visitLdcInsn("test");
106 mv.visitFieldInsn(PUTFIELD, "annotations/Values", "testfield", "Ljava/lang/String;");
107 mv.visitInsn(RETURN);
108 mv.visitMaxs(2, 1);
109 mv.visitEnd();
110 }
111 {
112 mv = cw.visitMethod(ACC_PUBLIC, "testMethod", "(Ljava/lang/String;I)V", null, null);
113 {
114 av0 = mv.visitAnnotation("Lannotations/ValueAttrAnnotation1;", true);
115 av0.visit("value", "methodAnnotation1");
116 av0.visitEnd();
117 }
118 {
119 av0 = mv.visitAnnotation("Lannotations/ValueAttrAnnotation2;", true);
120 av0.visit("value", "methodAnnotation2");
121 av0.visitEnd();
122 }
123 {
124 av0 = mv.visitParameterAnnotation(0, "Lannotations/ValueAttrAnnotation1;", true);
125 av0.visit("value", "param1Annotation1");
126 av0.visitEnd();
127 }
128 {
129 av0 = mv.visitParameterAnnotation(0, "Lannotations/ValueAttrAnnotation2;", true);
130 av0.visit("value", "param1Annotation2");
131 av0.visitEnd();
132 }
133 {
134 av0 = mv.visitParameterAnnotation(1, "Lannotations/ValueAttrAnnotation1;", true);
135 av0.visit("value", "param2Annotation1");
136 av0.visitEnd();
137 }
138 {
139 av0 = mv.visitParameterAnnotation(1, "Lannotations/ValueAttrAnnotation2;", true);
140 av0.visit("value", "param2Annotation2");
141 av0.visitEnd();
142 }
143 mv.visitInsn(RETURN);
144 mv.visitMaxs(0, 3);
145 mv.visitEnd();
146 }
147 cw.visitEnd();
148
149 return cw.toByteArray();
150 }
151 }
152
Popular Tags