• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // ASM: a very small and fast Java bytecode manipulation framework
2 // Copyright (c) 2000-2011 INRIA, France Telecom
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions
7 // are met:
8 // 1. Redistributions of source code must retain the above copyright
9 //    notice, this list of conditions and the following disclaimer.
10 // 2. Redistributions in binary form must reproduce the above copyright
11 //    notice, this list of conditions and the following disclaimer in the
12 //    documentation and/or other materials provided with the distribution.
13 // 3. Neither the name of the copyright holders nor the names of its
14 //    contributors may be used to endorse or promote products derived from
15 //    this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 // THE POSSIBILITY OF SUCH DAMAGE.
28 package org.objectweb.asm.util;
29 
30 import org.objectweb.asm.AnnotationVisitor;
31 import org.objectweb.asm.Attribute;
32 import org.objectweb.asm.Opcodes;
33 import org.objectweb.asm.RecordComponentVisitor;
34 import org.objectweb.asm.TypePath;
35 
36 /**
37  * A {@link RecordComponentVisitor} that prints the record components it visits with a {@link
38  * Printer}.
39  *
40  * @author Remi Forax
41  */
42 public final class TraceRecordComponentVisitor extends RecordComponentVisitor {
43 
44   /** The printer to convert the visited record component into text. */
45   public final Printer printer;
46 
47   /**
48    * Constructs a new {@link TraceRecordComponentVisitor}.
49    *
50    * @param printer the printer to convert the visited record component into text.
51    */
TraceRecordComponentVisitor(final Printer printer)52   public TraceRecordComponentVisitor(final Printer printer) {
53     this(null, printer);
54   }
55 
56   /**
57    * Constructs a new {@link TraceRecordComponentVisitor}.
58    *
59    * @param recordComponentVisitor the record component visitor to which to delegate calls. May be
60    *     {@literal null}.
61    * @param printer the printer to convert the visited record component into text.
62    */
TraceRecordComponentVisitor( final RecordComponentVisitor recordComponentVisitor, final Printer printer)63   public TraceRecordComponentVisitor(
64       final RecordComponentVisitor recordComponentVisitor, final Printer printer) {
65     super(/* latest api ='*/ Opcodes.ASM9, recordComponentVisitor);
66     this.printer = printer;
67   }
68 
69   @Override
visitAnnotation(final String descriptor, final boolean visible)70   public AnnotationVisitor visitAnnotation(final String descriptor, final boolean visible) {
71     Printer annotationPrinter = printer.visitRecordComponentAnnotation(descriptor, visible);
72     return new TraceAnnotationVisitor(
73         super.visitAnnotation(descriptor, visible), annotationPrinter);
74   }
75 
76   @Override
visitTypeAnnotation( final int typeRef, final TypePath typePath, final String descriptor, final boolean visible)77   public AnnotationVisitor visitTypeAnnotation(
78       final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {
79     Printer annotationPrinter =
80         printer.visitRecordComponentTypeAnnotation(typeRef, typePath, descriptor, visible);
81     return new TraceAnnotationVisitor(
82         super.visitTypeAnnotation(typeRef, typePath, descriptor, visible), annotationPrinter);
83   }
84 
85   @Override
visitAttribute(final Attribute attribute)86   public void visitAttribute(final Attribute attribute) {
87     printer.visitRecordComponentAttribute(attribute);
88     super.visitAttribute(attribute);
89   }
90 
91   @Override
visitEnd()92   public void visitEnd() {
93     printer.visitRecordComponentEnd();
94     super.visitEnd();
95   }
96 }
97