1 30 package org.objectweb.asm.util; 31 32 import org.objectweb.asm.AnnotationVisitor; 33 import org.objectweb.asm.Attribute; 34 import org.objectweb.asm.util.attrs.Traceable; 35 36 41 public abstract class TraceAbstractVisitor extends AbstractVisitor { 42 43 47 public final static int INTERNAL_NAME = 0; 48 49 53 public final static int FIELD_DESCRIPTOR = 1; 54 55 59 public final static int FIELD_SIGNATURE = 2; 60 61 65 public final static int METHOD_DESCRIPTOR = 3; 66 67 71 public final static int METHOD_SIGNATURE = 4; 72 73 77 public final static int CLASS_SIGNATURE = 5; 78 79 84 public final static int TYPE_DECLARATION = 6; 85 86 90 public final static int CLASS_DECLARATION = 7; 91 92 96 public final static int PARAMETERS_DECLARATION = 8; 97 98 101 protected String tab = " "; 102 103 110 public AnnotationVisitor visitAnnotation( 111 final String desc, 112 final boolean visible) 113 { 114 buf.setLength(0); 115 buf.append(tab).append('@'); 116 appendDescriptor(FIELD_DESCRIPTOR, desc); 117 buf.append('('); 118 text.add(buf.toString()); 119 TraceAnnotationVisitor tav = createTraceAnnotationVisitor(); 120 text.add(tav.getText()); 121 text.add(visible ? ")\n" : ") // invisible\n"); 122 return tav; 123 } 124 125 130 public void visitAttribute(final Attribute attr) { 131 buf.setLength(0); 132 buf.append(tab).append("ATTRIBUTE "); 133 appendDescriptor(-1, attr.type); 134 135 if (attr instanceof Traceable) { 136 ((Traceable) attr).trace(buf, null); 137 } else { 138 buf.append(" : ").append(attr.toString()).append("\n"); 139 } 140 141 text.add(buf.toString()); 142 } 143 144 147 public void visitEnd() { 148 } 150 151 155 protected TraceAnnotationVisitor createTraceAnnotationVisitor() { 156 return new TraceAnnotationVisitor(); 157 } 158 159 168 protected void appendDescriptor(final int type, final String desc) { 169 if (type == CLASS_SIGNATURE || type == FIELD_SIGNATURE 170 || type == METHOD_SIGNATURE) 171 { 172 if (desc != null) { 173 buf.append("// signature ").append(desc).append('\n'); 174 } 175 } else { 176 buf.append(desc); 177 } 178 } 179 180 } 181 | Popular Tags |