• 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.signature;
29 
30 import org.objectweb.asm.Opcodes;
31 
32 /**
33  * A visitor to visit a generic signature. The methods of this interface must be called in one of
34  * the three following orders (the last one is the only valid order for a {@link SignatureVisitor}
35  * that is returned by a method of this interface):
36  *
37  * <ul>
38  *   <li><i>ClassSignature</i> = ( {@code visitFormalTypeParameter} {@code visitClassBound}? {@code
39  *       visitInterfaceBound}* )* ({@code visitSuperclass} {@code visitInterface}* )
40  *   <li><i>MethodSignature</i> = ( {@code visitFormalTypeParameter} {@code visitClassBound}? {@code
41  *       visitInterfaceBound}* )* ({@code visitParameterType}* {@code visitReturnType} {@code
42  *       visitExceptionType}* )
43  *   <li><i>TypeSignature</i> = {@code visitBaseType} | {@code visitTypeVariable} | {@code
44  *       visitArrayType} | ( {@code visitClassType} {@code visitTypeArgument}* ( {@code
45  *       visitInnerClassType} {@code visitTypeArgument}* )* {@code visitEnd} ) )
46  * </ul>
47  *
48  * @author Thomas Hallgren
49  * @author Eric Bruneton
50  */
51 public abstract class SignatureVisitor {
52 
53   /** Wildcard for an "extends" type argument. */
54   public static final char EXTENDS = '+';
55 
56   /** Wildcard for a "super" type argument. */
57   public static final char SUPER = '-';
58 
59   /** Wildcard for a normal type argument. */
60   public static final char INSTANCEOF = '=';
61 
62   /**
63    * The ASM API version implemented by this visitor. The value of this field must be one of the
64    * {@code ASM}<i>x</i> values in {@link Opcodes}.
65    */
66   protected final int api;
67 
68   /**
69    * Constructs a new {@link SignatureVisitor}.
70    *
71    * @param api the ASM API version implemented by this visitor. Must be one of the {@code
72    *     ASM}<i>x</i> values in {@link Opcodes}.
73    */
SignatureVisitor(final int api)74   protected SignatureVisitor(final int api) {
75     if (api != Opcodes.ASM9
76         && api != Opcodes.ASM8
77         && api != Opcodes.ASM7
78         && api != Opcodes.ASM6
79         && api != Opcodes.ASM5
80         && api != Opcodes.ASM4
81         && api != Opcodes.ASM10_EXPERIMENTAL) {
82       throw new IllegalArgumentException("Unsupported api " + api);
83     }
84     this.api = api;
85   }
86 
87   /**
88    * Visits a formal type parameter.
89    *
90    * @param name the name of the formal parameter.
91    */
visitFormalTypeParameter(final String name)92   public void visitFormalTypeParameter(final String name) {}
93 
94   /**
95    * Visits the class bound of the last visited formal type parameter.
96    *
97    * @return a non null visitor to visit the signature of the class bound.
98    */
visitClassBound()99   public SignatureVisitor visitClassBound() {
100     return this;
101   }
102 
103   /**
104    * Visits an interface bound of the last visited formal type parameter.
105    *
106    * @return a non null visitor to visit the signature of the interface bound.
107    */
visitInterfaceBound()108   public SignatureVisitor visitInterfaceBound() {
109     return this;
110   }
111 
112   /**
113    * Visits the type of the super class.
114    *
115    * @return a non null visitor to visit the signature of the super class type.
116    */
visitSuperclass()117   public SignatureVisitor visitSuperclass() {
118     return this;
119   }
120 
121   /**
122    * Visits the type of an interface implemented by the class.
123    *
124    * @return a non null visitor to visit the signature of the interface type.
125    */
visitInterface()126   public SignatureVisitor visitInterface() {
127     return this;
128   }
129 
130   /**
131    * Visits the type of a method parameter.
132    *
133    * @return a non null visitor to visit the signature of the parameter type.
134    */
visitParameterType()135   public SignatureVisitor visitParameterType() {
136     return this;
137   }
138 
139   /**
140    * Visits the return type of the method.
141    *
142    * @return a non null visitor to visit the signature of the return type.
143    */
visitReturnType()144   public SignatureVisitor visitReturnType() {
145     return this;
146   }
147 
148   /**
149    * Visits the type of a method exception.
150    *
151    * @return a non null visitor to visit the signature of the exception type.
152    */
visitExceptionType()153   public SignatureVisitor visitExceptionType() {
154     return this;
155   }
156 
157   /**
158    * Visits a signature corresponding to a primitive type.
159    *
160    * @param descriptor the descriptor of the primitive type, or 'V' for {@code void} .
161    */
visitBaseType(final char descriptor)162   public void visitBaseType(final char descriptor) {}
163 
164   /**
165    * Visits a signature corresponding to a type variable.
166    *
167    * @param name the name of the type variable.
168    */
visitTypeVariable(final String name)169   public void visitTypeVariable(final String name) {}
170 
171   /**
172    * Visits a signature corresponding to an array type.
173    *
174    * @return a non null visitor to visit the signature of the array element type.
175    */
visitArrayType()176   public SignatureVisitor visitArrayType() {
177     return this;
178   }
179 
180   /**
181    * Starts the visit of a signature corresponding to a class or interface type.
182    *
183    * @param name the internal name of the class or interface (see {@link
184    *     org.objectweb.asm.Type#getInternalName()}).
185    */
visitClassType(final String name)186   public void visitClassType(final String name) {}
187 
188   /**
189    * Visits an inner class.
190    *
191    * @param name the local name of the inner class in its enclosing class.
192    */
visitInnerClassType(final String name)193   public void visitInnerClassType(final String name) {}
194 
195   /** Visits an unbounded type argument of the last visited class or inner class type. */
visitTypeArgument()196   public void visitTypeArgument() {}
197 
198   /**
199    * Visits a type argument of the last visited class or inner class type.
200    *
201    * @param wildcard '+', '-' or '='.
202    * @return a non null visitor to visit the signature of the type argument.
203    */
visitTypeArgument(final char wildcard)204   public SignatureVisitor visitTypeArgument(final char wildcard) {
205     return this;
206   }
207 
208   /** Ends the visit of a signature corresponding to a class or interface type. */
visitEnd()209   public void visitEnd() {}
210 }
211