1 30 package org.objectweb.asm.optimizer; 31 32 import org.objectweb.asm.AnnotationVisitor; 33 import org.objectweb.asm.Type; 34 35 41 public class AnnotationConstantsCollector implements AnnotationVisitor { 42 43 private AnnotationVisitor av; 44 45 private ConstantPool cp; 46 47 public AnnotationConstantsCollector( 48 final AnnotationVisitor av, 49 final ConstantPool cp) 50 { 51 this.av = av; 52 this.cp = cp; 53 } 54 55 public void visit(final String name, final Object value) { 56 if (name != null) { 57 cp.newUTF8(name); 58 } 59 if (value instanceof Byte ) { 60 cp.newInteger(((Byte ) value).byteValue()); 61 } else if (value instanceof Boolean ) { 62 cp.newInteger(((Boolean ) value).booleanValue() ? 1 : 0); 63 } else if (value instanceof Character ) { 64 cp.newInteger(((Character ) value).charValue()); 65 } else if (value instanceof Short ) { 66 cp.newInteger(((Short ) value).shortValue()); 67 } else if (value instanceof Type) { 68 cp.newUTF8(((Type) value).getDescriptor()); 69 } else if (value instanceof byte[]) { 70 byte[] v = (byte[]) value; 71 for (int i = 0; i < v.length; i++) { 72 cp.newInteger(v[i]); 73 } 74 } else if (value instanceof boolean[]) { 75 boolean[] v = (boolean[]) value; 76 for (int i = 0; i < v.length; i++) { 77 cp.newInteger(v[i] ? 1 : 0); 78 } 79 } else if (value instanceof short[]) { 80 short[] v = (short[]) value; 81 for (int i = 0; i < v.length; i++) { 82 cp.newInteger(v[i]); 83 } 84 } else if (value instanceof char[]) { 85 char[] v = (char[]) value; 86 for (int i = 0; i < v.length; i++) { 87 cp.newInteger(v[i]); 88 } 89 } else if (value instanceof int[]) { 90 int[] v = (int[]) value; 91 for (int i = 0; i < v.length; i++) { 92 cp.newInteger(v[i]); 93 } 94 } else if (value instanceof long[]) { 95 long[] v = (long[]) value; 96 for (int i = 0; i < v.length; i++) { 97 cp.newLong(v[i]); 98 } 99 } else if (value instanceof float[]) { 100 float[] v = (float[]) value; 101 for (int i = 0; i < v.length; i++) { 102 cp.newFloat(v[i]); 103 } 104 } else if (value instanceof double[]) { 105 double[] v = (double[]) value; 106 for (int i = 0; i < v.length; i++) { 107 cp.newDouble(v[i]); 108 } 109 } else { 110 cp.newConst(value); 111 } 112 av.visit(name, value); 113 } 114 115 public void visitEnum( 116 final String name, 117 final String desc, 118 final String value) 119 { 120 if (name != null) { 121 cp.newUTF8(name); 122 } 123 cp.newUTF8(desc); 124 cp.newUTF8(value); 125 av.visitEnum(name, desc, value); 126 } 127 128 public AnnotationVisitor visitAnnotation( 129 final String name, 130 final String desc) 131 { 132 if (name != null) { 133 cp.newUTF8(name); 134 } 135 cp.newUTF8(desc); 136 return new AnnotationConstantsCollector(av.visitAnnotation(name, desc), 137 cp); 138 } 139 140 public AnnotationVisitor visitArray(final String name) { 141 if (name != null) { 142 cp.newUTF8(name); 143 } 144 return new AnnotationConstantsCollector(av.visitArray(name), cp); 145 } 146 147 public void visitEnd() { 148 av.visitEnd(); 149 } 150 } 151 | Popular Tags |