• 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;
29 
30 /**
31  * A visitor to visit a record component. The methods of this class must be called in the following
32  * order: ( {@code visitAnnotation} | {@code visitTypeAnnotation} | {@code visitAttribute} )* {@code
33  * visitEnd}.
34  *
35  * @author Remi Forax
36  * @author Eric Bruneton
37  */
38 public abstract class RecordComponentVisitor {
39   /**
40    * The ASM API version implemented by this visitor. The value of this field must be one of {@link
41    * Opcodes#ASM8} or {@link Opcodes#ASM9}.
42    */
43   protected final int api;
44 
45   /**
46    * The record visitor to which this visitor must delegate method calls. May be {@literal null}.
47    */
48   protected RecordComponentVisitor delegate;
49 
50   /**
51    * Constructs a new {@link RecordComponentVisitor}.
52    *
53    * @param api the ASM API version implemented by this visitor. Must be one of {@link Opcodes#ASM8}
54    *     or {@link Opcodes#ASM9}.
55    */
RecordComponentVisitor(final int api)56   protected RecordComponentVisitor(final int api) {
57     this(api, null);
58   }
59 
60   /**
61    * Constructs a new {@link RecordComponentVisitor}.
62    *
63    * @param api the ASM API version implemented by this visitor. Must be {@link Opcodes#ASM8}.
64    * @param recordComponentVisitor the record component visitor to which this visitor must delegate
65    *     method calls. May be null.
66    */
RecordComponentVisitor( final int api, final RecordComponentVisitor recordComponentVisitor)67   protected RecordComponentVisitor(
68       final int api, final RecordComponentVisitor recordComponentVisitor) {
69     if (api != Opcodes.ASM9
70         && api != Opcodes.ASM8
71         && api != Opcodes.ASM7
72         && api != Opcodes.ASM6
73         && api != Opcodes.ASM5
74         && api != Opcodes.ASM4
75         && api != Opcodes.ASM10_EXPERIMENTAL) {
76       throw new IllegalArgumentException("Unsupported api " + api);
77     }
78     if (api == Opcodes.ASM10_EXPERIMENTAL) {
79       Constants.checkAsmExperimental(this);
80     }
81     this.api = api;
82     this.delegate = recordComponentVisitor;
83   }
84 
85   /**
86    * The record visitor to which this visitor must delegate method calls. May be {@literal null}.
87    *
88    * @return the record visitor to which this visitor must delegate method calls, or {@literal
89    *     null}.
90    */
getDelegate()91   public RecordComponentVisitor getDelegate() {
92     return delegate;
93   }
94 
95   /**
96    * Visits an annotation of the record component.
97    *
98    * @param descriptor the class descriptor of the annotation class.
99    * @param visible {@literal true} if the annotation is visible at runtime.
100    * @return a visitor to visit the annotation values, or {@literal null} if this visitor is not
101    *     interested in visiting this annotation.
102    */
visitAnnotation(final String descriptor, final boolean visible)103   public AnnotationVisitor visitAnnotation(final String descriptor, final boolean visible) {
104     if (delegate != null) {
105       return delegate.visitAnnotation(descriptor, visible);
106     }
107     return null;
108   }
109 
110   /**
111    * Visits an annotation on a type in the record component signature.
112    *
113    * @param typeRef a reference to the annotated type. The sort of this type reference must be
114    *     {@link TypeReference#CLASS_TYPE_PARAMETER}, {@link
115    *     TypeReference#CLASS_TYPE_PARAMETER_BOUND} or {@link TypeReference#CLASS_EXTENDS}. See
116    *     {@link TypeReference}.
117    * @param typePath the path to the annotated type argument, wildcard bound, array element type, or
118    *     static inner type within 'typeRef'. May be {@literal null} if the annotation targets
119    *     'typeRef' as a whole.
120    * @param descriptor the class descriptor of the annotation class.
121    * @param visible {@literal true} if the annotation is visible at runtime.
122    * @return a visitor to visit the annotation values, or {@literal null} if this visitor is not
123    *     interested in visiting this annotation.
124    */
visitTypeAnnotation( final int typeRef, final TypePath typePath, final String descriptor, final boolean visible)125   public AnnotationVisitor visitTypeAnnotation(
126       final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {
127     if (delegate != null) {
128       return delegate.visitTypeAnnotation(typeRef, typePath, descriptor, visible);
129     }
130     return null;
131   }
132 
133   /**
134    * Visits a non standard attribute of the record component.
135    *
136    * @param attribute an attribute.
137    */
visitAttribute(final Attribute attribute)138   public void visitAttribute(final Attribute attribute) {
139     if (delegate != null) {
140       delegate.visitAttribute(attribute);
141     }
142   }
143 
144   /**
145    * Visits the end of the record component. This method, which is the last one to be called, is
146    * used to inform the visitor that everything have been visited.
147    */
visitEnd()148   public void visitEnd() {
149     if (delegate != null) {
150       delegate.visitEnd();
151     }
152   }
153 }
154