1 package org.objectweb.asm.util; 2 3 import org.objectweb.asm.AnnotationVisitor; 4 import org.objectweb.asm.TypeAnnotationVisitor; 5 6 import com.sun.tools.javac.code.TypeAnnotationPosition.TypePathEntry; 7 8 /** 9 * An {@link TypeAnnotationVisitor} that prints the ASM code that generates 10 * the extended annotations it visits. 11 * 12 * @author jaimeq 13 */ 14 public class ASMifierTypeAnnotationVisitor extends AbstractVisitor 15 implements TypeAnnotationVisitor 16 { 17 18 /** 19 * Identifier of the extended annotation visitor variable in the 20 * produced code. 21 */ 22 protected final int id; 23 24 /** 25 * Constructs a new {@link ASMifierTypeAnnotationVisitor}. 26 * 27 * @param id identifier of the extended annotation visitor variable in the 28 * produced code. 29 */ 30 public ASMifierTypeAnnotationVisitor(final int id) { 31 this.id = id; 32 } 33 34 // ------------------------------------------------------------------------ 35 // Implementation of the TypeAnnotationVisitor interface 36 // ------------------------------------------------------------------------ 37 38 public void visit(final String name, final Object value) { 39 buf.setLength(0); 40 buf.append("xav").append(id).append(".visit("); 41 ASMifierAbstractVisitor.appendConstant(buf, name); 42 buf.append(", "); 43 ASMifierAbstractVisitor.appendConstant(buf, value); 44 buf.append(");\n"); 45 text.add(buf.toString()); 46 } 47 48 public void visitEnum( 49 final String name, 50 final String desc, 51 final String value) 52 { 53 buf.setLength(0); 54 buf.append("xav").append(id).append(".visitEnum("); 55 ASMifierAbstractVisitor.appendConstant(buf, name); 56 buf.append(", "); 57 ASMifierAbstractVisitor.appendConstant(buf, desc); 58 buf.append(", "); 59 ASMifierAbstractVisitor.appendConstant(buf, value); 60 buf.append(");\n"); 61 text.add(buf.toString()); 62 } 63 64 public AnnotationVisitor visitAnnotation( 65 final String name, 66 final String desc) 67 { 68 buf.setLength(0); 69 buf.append("{\n"); 70 buf.append("AnnotationVisitor av").append(id + 1).append(" = av"); 71 buf.append(id).append(".visitAnnotation("); 72 ASMifierAbstractVisitor.appendConstant(buf, name); 73 buf.append(", "); 74 ASMifierAbstractVisitor.appendConstant(buf, desc); 75 buf.append(");\n"); 76 text.add(buf.toString()); 77 ASMifierAnnotationVisitor av = new ASMifierAnnotationVisitor(id + 1); 78 text.add(av.getText()); 79 text.add("}\n"); 80 return av; 81 } 82 83 public AnnotationVisitor visitArray(final String name) { 84 buf.setLength(0); 85 buf.append("{\n"); 86 buf.append("AnnotationVisitor av").append(id + 1).append(" = av"); 87 buf.append(id).append(".visitArray("); 88 ASMifierAbstractVisitor.appendConstant(buf, name); 89 buf.append(");\n"); 90 text.add(buf.toString()); 91 ASMifierAnnotationVisitor av = new ASMifierAnnotationVisitor(id + 1); 92 text.add(av.getText()); 93 text.add("}\n"); 94 return av; 95 } 96 97 public void visitEnd() { 98 buf.setLength(0); 99 buf.append("xav").append(id).append(".visitEnd();\n"); 100 text.add(buf.toString()); 101 } 102 103 public void appendConstant(final StringBuffer buf, int i) { 104 ASMifierAbstractVisitor.appendConstant(buf, Integer.valueOf(i)); 105 } 106 107 public void visitXTargetType(int target_type) { 108 buf.setLength(0); 109 buf.append("xav").append(id).append(".visitXTargetType("); 110 appendConstant(buf, target_type); 111 buf.append(");\n"); 112 text.add(buf.toString()); 113 } 114 115 public void visitXOffset(int offset) { 116 buf.setLength(0); 117 buf.append("xav").append(id).append(".visitXOffset("); 118 appendConstant(buf, offset); 119 buf.append(");\n"); 120 text.add(buf.toString()); 121 } 122 123 public void visitXLocationLength(int location_length) { 124 buf.setLength(0); 125 buf.append("xav").append(id).append(".visitXLocationLength("); 126 appendConstant(buf, location_length); 127 buf.append(");\n"); 128 text.add(buf.toString()); 129 } 130 131 public void visitXLocation(TypePathEntry location) { 132 buf.setLength(0); 133 buf.append("xav").append(id).append(".visitXLocation("); 134 buf.append(location.toString()); 135 buf.append(");\n"); 136 text.add(buf.toString()); 137 } 138 139 public void visitXNumEntries(int num_entries) { 140 buf.setLength(0); 141 buf.append("xav").append(id).append(".visitXNumEntries("); 142 appendConstant(buf, num_entries); 143 buf.append(");\n"); 144 text.add(buf.toString()); 145 } 146 147 public void visitXStartPc(int start_pc) { 148 buf.setLength(0); 149 buf.append("xav").append(id).append(".visitXStartPc("); 150 appendConstant(buf, start_pc); 151 buf.append(");\n"); 152 text.add(buf.toString()); 153 } 154 155 public void visitXLength(int length) { 156 buf.setLength(0); 157 buf.append("xav").append(id).append(".visitXLength("); 158 appendConstant(buf, length); 159 buf.append(");\n"); 160 text.add(buf.toString()); 161 } 162 163 public void visitXIndex(int index) { 164 buf.setLength(0); 165 buf.append("xav").append(id).append(".visitXIndex("); 166 appendConstant(buf, index); 167 buf.append(");\n"); 168 text.add(buf.toString()); 169 } 170 171 public void visitXParamIndex(int param_index) { 172 buf.setLength(0); 173 buf.append("xav").append(id).append(".visitXParamIndex("); 174 appendConstant(buf, param_index); 175 buf.append(");\n"); 176 text.add(buf.toString()); 177 } 178 179 public void visitXBoundIndex(int bound_index) { 180 buf.setLength(0); 181 buf.append("xav").append(id).append(".visitXBoundIndex("); 182 appendConstant(buf, bound_index); 183 buf.append(");\n"); 184 text.add(buf.toString()); 185 } 186 187 public void visitXTypeIndex(int type_index) { 188 buf.setLength(0); 189 buf.append("xav").append(id).append(".visitXTypeIndex("); 190 appendConstant(buf, type_index); 191 buf.append(");\n"); 192 text.add(buf.toString()); 193 } 194 195 public void visitXExceptionIndex(int exception_index) { 196 buf.setLength(0); 197 buf.append("xav").append(id).append(".visitXExceptionIndex("); 198 appendConstant(buf, exception_index); 199 buf.append(");\n"); 200 text.add(buf.toString()); 201 } 202 203 public void visitXNameAndArgsSize() { 204 } 205 } 206