2 * ASM: a very small and fast Java bytecode manipulation framework
3 * Copyright (c) 2000-2005 INRIA, France Telecom
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the copyright holders nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGE.
30 package org.objectweb.asm.util;
32 import org.objectweb.asm.AnnotationVisitor;
33 import org.objectweb.asm.Attribute;
34 import org.objectweb.asm.util.attrs.Traceable;
37 * An abstract trace visitor.
39 * @author Eric Bruneton
41 public abstract class TraceAbstractVisitor extends AbstractVisitor {
44 * Constant used in {@link #appendDescriptor appendDescriptor} for internal
45 * type names in bytecode notation.
47 public final static int INTERNAL_NAME = 0;
50 * Constant used in {@link #appendDescriptor appendDescriptor} for field
51 * descriptors, formatted in bytecode notation
53 public final static int FIELD_DESCRIPTOR = 1;
56 * Constant used in {@link #appendDescriptor appendDescriptor} for field
57 * signatures, formatted in bytecode notation
59 public final static int FIELD_SIGNATURE = 2;
62 * Constant used in {@link #appendDescriptor appendDescriptor} for method
63 * descriptors, formatted in bytecode notation
65 public final static int METHOD_DESCRIPTOR = 3;
68 * Constant used in {@link #appendDescriptor appendDescriptor} for method
69 * signatures, formatted in bytecode notation
71 public final static int METHOD_SIGNATURE = 4;
74 * Constant used in {@link #appendDescriptor appendDescriptor} for class
75 * signatures, formatted in bytecode notation
77 public final static int CLASS_SIGNATURE = 5;
80 * Constant used in {@link #appendDescriptor appendDescriptor} for field or
81 * method return value signatures, formatted in default Java notation
84 public final static int TYPE_DECLARATION = 6;
87 * Constant used in {@link #appendDescriptor appendDescriptor} for class
88 * signatures, formatted in default Java notation (non-bytecode)
90 public final static int CLASS_DECLARATION = 7;
93 * Constant used in {@link #appendDescriptor appendDescriptor} for method
94 * parameter signatures, formatted in default Java notation (non-bytecode)
96 public final static int PARAMETERS_DECLARATION = 8;
99 * Tab for class members.
101 protected String tab = " ";
104 * Prints a disassembled view of the given annotation.
106 * @param desc the class descriptor of the annotation class.
107 * @param visible <tt>true</tt> if the annotation is visible at runtime.
108 * @return a visitor to visit the annotation values.
110 public AnnotationVisitor visitAnnotation(
112 final boolean visible)
115 buf.append(tab).append('@');
116 appendDescriptor(FIELD_DESCRIPTOR, desc);
118 text.add(buf.toString());
119 TraceAnnotationVisitor tav = createTraceAnnotationVisitor();
120 text.add(tav.getText());
121 text.add(visible ? ")\n" : ") // invisible\n");
126 * Prints a disassembled view of the given attribute.
128 * @param attr an attribute.
130 public void visitAttribute(final Attribute attr) {
132 buf.append(tab).append("ATTRIBUTE ");
133 appendDescriptor(-1, attr.type);
135 if (attr instanceof Traceable) {
136 ((Traceable) attr).trace(buf, null);
138 buf.append(" : ").append(attr.toString()).append("\n");
141 text.add(buf.toString());
147 public void visitEnd() {
151 // ------------------------------------------------------------------------
153 // ------------------------------------------------------------------------
155 protected TraceAnnotationVisitor createTraceAnnotationVisitor() {
156 return new TraceAnnotationVisitor();
160 * Appends an internal name, a type descriptor or a type signature to
163 * @param type indicates if desc is an internal name, a field descriptor, a
164 * method descriptor, a class signature, ...
165 * @param desc an internal name, type descriptor, or type signature. May be
168 protected void appendDescriptor(final int type, final String desc) {
169 if (type == CLASS_SIGNATURE || type == FIELD_SIGNATURE
170 || type == METHOD_SIGNATURE)
173 buf.append("// signature ").append(desc).append('\n');