< prev index next >

src/java.base/share/classes/jdk/internal/org/objectweb/asm/util/TraceClassVisitor.java

Print this page
rev 47452 : imported patch jdk-new-asmv6.patch


  48  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  49  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  50  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  51  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  52  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  53  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  54  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  55  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  56  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  57  * THE POSSIBILITY OF SUCH DAMAGE.
  58  */
  59 package jdk.internal.org.objectweb.asm.util;
  60 
  61 import java.io.PrintWriter;
  62 
  63 import jdk.internal.org.objectweb.asm.AnnotationVisitor;
  64 import jdk.internal.org.objectweb.asm.Attribute;
  65 import jdk.internal.org.objectweb.asm.ClassVisitor;
  66 import jdk.internal.org.objectweb.asm.FieldVisitor;
  67 import jdk.internal.org.objectweb.asm.MethodVisitor;

  68 import jdk.internal.org.objectweb.asm.Opcodes;
  69 import jdk.internal.org.objectweb.asm.TypePath;
  70 
  71 /**
  72  * A {@link ClassVisitor} that prints the classes it visits with a
  73  * {@link Printer}. This class visitor can be used in the middle of a class
  74  * visitor chain to trace the class that is visited at a given point in this
  75  * chain. This may be useful for debugging purposes.
  76  * <p>
  77  * The trace printed when visiting the <tt>Hello</tt> class is the following:
  78  * <p>
  79  * <blockquote>
  80  *
  81  * <pre>
  82  * // class version 49.0 (49) // access flags 0x21 public class Hello {
  83  *
  84  * // compiled from: Hello.java
  85  *
  86  * // access flags 0x1 public &lt;init&gt; ()V ALOAD 0 INVOKESPECIAL
  87  * java/lang/Object &lt;init&gt; ()V RETURN MAXSTACK = 1 MAXLOCALS = 1


 143      */
 144     public TraceClassVisitor(final ClassVisitor cv, final PrintWriter pw) {
 145         this(cv, new Textifier(), pw);
 146     }
 147 
 148     /**
 149      * Constructs a new {@link TraceClassVisitor}.
 150      *
 151      * @param cv
 152      *            the {@link ClassVisitor} to which this visitor delegates
 153      *            calls. May be <tt>null</tt>.
 154      * @param p
 155      *            the object that actually converts visit events into text.
 156      * @param pw
 157      *            the print writer to be used to print the class. May be null if
 158      *            you simply want to use the result via
 159      *            {@link Printer#getText()}, instead of printing it.
 160      */
 161     public TraceClassVisitor(final ClassVisitor cv, final Printer p,
 162             final PrintWriter pw) {
 163         super(Opcodes.ASM5, cv);
 164         this.pw = pw;
 165         this.p = p;
 166     }
 167 
 168     @Override
 169     public void visit(final int version, final int access, final String name,
 170             final String signature, final String superName,
 171             final String[] interfaces) {
 172         p.visit(version, access, name, signature, superName, interfaces);
 173         super.visit(version, access, name, signature, superName, interfaces);
 174     }
 175 
 176     @Override
 177     public void visitSource(final String file, final String debug) {
 178         p.visitSource(file, debug);
 179         super.visitSource(file, debug);
 180     }
 181 








 182     @Override
 183     public void visitOuterClass(final String owner, final String name,
 184             final String desc) {
 185         p.visitOuterClass(owner, name, desc);
 186         super.visitOuterClass(owner, name, desc);
 187     }
 188 
 189     @Override
 190     public AnnotationVisitor visitAnnotation(final String desc,
 191             final boolean visible) {
 192         Printer p = this.p.visitClassAnnotation(desc, visible);
 193         AnnotationVisitor av = cv == null ? null : cv.visitAnnotation(desc,
 194                 visible);
 195         return new TraceAnnotationVisitor(av, p);
 196     }
 197 
 198     @Override
 199     public AnnotationVisitor visitTypeAnnotation(int typeRef,
 200             TypePath typePath, String desc, boolean visible) {
 201         Printer p = this.p.visitClassTypeAnnotation(typeRef, typePath, desc,




  48  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  49  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  50  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  51  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  52  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  53  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  54  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  55  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  56  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  57  * THE POSSIBILITY OF SUCH DAMAGE.
  58  */
  59 package jdk.internal.org.objectweb.asm.util;
  60 
  61 import java.io.PrintWriter;
  62 
  63 import jdk.internal.org.objectweb.asm.AnnotationVisitor;
  64 import jdk.internal.org.objectweb.asm.Attribute;
  65 import jdk.internal.org.objectweb.asm.ClassVisitor;
  66 import jdk.internal.org.objectweb.asm.FieldVisitor;
  67 import jdk.internal.org.objectweb.asm.MethodVisitor;
  68 import jdk.internal.org.objectweb.asm.ModuleVisitor;
  69 import jdk.internal.org.objectweb.asm.Opcodes;
  70 import jdk.internal.org.objectweb.asm.TypePath;
  71 
  72 /**
  73  * A {@link ClassVisitor} that prints the classes it visits with a
  74  * {@link Printer}. This class visitor can be used in the middle of a class
  75  * visitor chain to trace the class that is visited at a given point in this
  76  * chain. This may be useful for debugging purposes.
  77  * <p>
  78  * The trace printed when visiting the <tt>Hello</tt> class is the following:
  79  * <p>
  80  * <blockquote>
  81  *
  82  * <pre>
  83  * // class version 49.0 (49) // access flags 0x21 public class Hello {
  84  *
  85  * // compiled from: Hello.java
  86  *
  87  * // access flags 0x1 public &lt;init&gt; ()V ALOAD 0 INVOKESPECIAL
  88  * java/lang/Object &lt;init&gt; ()V RETURN MAXSTACK = 1 MAXLOCALS = 1


 144      */
 145     public TraceClassVisitor(final ClassVisitor cv, final PrintWriter pw) {
 146         this(cv, new Textifier(), pw);
 147     }
 148 
 149     /**
 150      * Constructs a new {@link TraceClassVisitor}.
 151      *
 152      * @param cv
 153      *            the {@link ClassVisitor} to which this visitor delegates
 154      *            calls. May be <tt>null</tt>.
 155      * @param p
 156      *            the object that actually converts visit events into text.
 157      * @param pw
 158      *            the print writer to be used to print the class. May be null if
 159      *            you simply want to use the result via
 160      *            {@link Printer#getText()}, instead of printing it.
 161      */
 162     public TraceClassVisitor(final ClassVisitor cv, final Printer p,
 163             final PrintWriter pw) {
 164         super(Opcodes.ASM6, cv);
 165         this.pw = pw;
 166         this.p = p;
 167     }
 168 
 169     @Override
 170     public void visit(final int version, final int access, final String name,
 171             final String signature, final String superName,
 172             final String[] interfaces) {
 173         p.visit(version, access, name, signature, superName, interfaces);
 174         super.visit(version, access, name, signature, superName, interfaces);
 175     }
 176 
 177     @Override
 178     public void visitSource(final String file, final String debug) {
 179         p.visitSource(file, debug);
 180         super.visitSource(file, debug);
 181     }
 182 
 183     @Override
 184     public ModuleVisitor visitModule(String name, int flags,
 185             String version) {
 186         Printer p = this.p.visitModule(name, flags, version);
 187         ModuleVisitor mv = super.visitModule(name, flags, version);
 188         return new TraceModuleVisitor(mv, p);
 189     }
 190 
 191     @Override
 192     public void visitOuterClass(final String owner, final String name,
 193             final String desc) {
 194         p.visitOuterClass(owner, name, desc);
 195         super.visitOuterClass(owner, name, desc);
 196     }
 197 
 198     @Override
 199     public AnnotationVisitor visitAnnotation(final String desc,
 200             final boolean visible) {
 201         Printer p = this.p.visitClassAnnotation(desc, visible);
 202         AnnotationVisitor av = cv == null ? null : cv.visitAnnotation(desc,
 203                 visible);
 204         return new TraceAnnotationVisitor(av, p);
 205     }
 206 
 207     @Override
 208     public AnnotationVisitor visitTypeAnnotation(int typeRef,
 209             TypePath typePath, String desc, boolean visible) {
 210         Printer p = this.p.visitClassTypeAnnotation(typeRef, typePath, desc,


< prev index next >