001// ASM: a very small and fast Java bytecode manipulation framework
002// Copyright (c) 2000-2011 INRIA, France Telecom
003// All rights reserved.
004//
005// Redistribution and use in source and binary forms, with or without
006// modification, are permitted provided that the following conditions
007// are met:
008// 1. Redistributions of source code must retain the above copyright
009//    notice, this list of conditions and the following disclaimer.
010// 2. Redistributions in binary form must reproduce the above copyright
011//    notice, this list of conditions and the following disclaimer in the
012//    documentation and/or other materials provided with the distribution.
013// 3. Neither the name of the copyright holders nor the names of its
014//    contributors may be used to endorse or promote products derived from
015//    this software without specific prior written permission.
016//
017// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
018// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
020// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
021// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
022// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
023// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
024// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
025// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
026// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
027// THE POSSIBILITY OF SUCH DAMAGE.
028package io.ebean.enhance.asm.signature;
029
030import io.ebean.enhance.asm.Opcodes;
031
032/**
033 * A visitor to visit a generic signature. The methods of this interface must be called in one of
034 * the three following orders (the last one is the only valid order for a {@link SignatureVisitor}
035 * that is returned by a method of this interface):
036 *
037 * <ul>
038 *   <li><i>ClassSignature</i> = ( {@code visitFormalTypeParameter} {@code visitClassBound}? {@code
039 *       visitInterfaceBound}* )* ({@code visitSuperclass} {@code visitInterface}* )
040 *   <li><i>MethodSignature</i> = ( {@code visitFormalTypeParameter} {@code visitClassBound}? {@code
041 *       visitInterfaceBound}* )* ({@code visitParameterType}* {@code visitReturnType} {@code
042 *       visitExceptionType}* )
043 *   <li><i>TypeSignature</i> = {@code visitBaseType} | {@code visitTypeVariable} | {@code
044 *       visitArrayType} | ( {@code visitClassType} {@code visitTypeArgument}* ( {@code
045 *       visitInnerClassType} {@code visitTypeArgument}* )* {@code visitEnd} ) )
046 * </ul>
047 *
048 * @author Thomas Hallgren
049 * @author Eric Bruneton
050 */
051public abstract class SignatureVisitor {
052
053  /** Wildcard for an "extends" type argument. */
054  public static final char EXTENDS = '+';
055
056  /** Wildcard for a "super" type argument. */
057  public static final char SUPER = '-';
058
059  /** Wildcard for a normal type argument. */
060  public static final char INSTANCEOF = '=';
061
062  /**
063   * The ASM API version implemented by this visitor. The value of this field must be one of {@link
064   * Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6} or {@link Opcodes#ASM7}.
065   */
066  protected final int api;
067
068  /**
069   * Constructs a new {@link SignatureVisitor}.
070   *
071   * @param api the ASM API version implemented by this visitor. Must be one of {@link
072   *     Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6} or {@link Opcodes#ASM7}.
073   */
074  public SignatureVisitor(final int api) {
075    if (api != Opcodes.ASM7 && api != Opcodes.ASM6 && api != Opcodes.ASM5 && api != Opcodes.ASM4) {
076      throw new IllegalArgumentException("Unsupported api " + api);
077    }
078    this.api = api;
079  }
080
081  /**
082   * Visits a formal type parameter.
083   *
084   * @param name the name of the formal parameter.
085   */
086  public void visitFormalTypeParameter(final String name) {}
087
088  /**
089   * Visits the class bound of the last visited formal type parameter.
090   *
091   * @return a non null visitor to visit the signature of the class bound.
092   */
093  public SignatureVisitor visitClassBound() {
094    return this;
095  }
096
097  /**
098   * Visits an interface bound of the last visited formal type parameter.
099   *
100   * @return a non null visitor to visit the signature of the interface bound.
101   */
102  public SignatureVisitor visitInterfaceBound() {
103    return this;
104  }
105
106  /**
107   * Visits the type of the super class.
108   *
109   * @return a non null visitor to visit the signature of the super class type.
110   */
111  public SignatureVisitor visitSuperclass() {
112    return this;
113  }
114
115  /**
116   * Visits the type of an interface implemented by the class.
117   *
118   * @return a non null visitor to visit the signature of the interface type.
119   */
120  public SignatureVisitor visitInterface() {
121    return this;
122  }
123
124  /**
125   * Visits the type of a method parameter.
126   *
127   * @return a non null visitor to visit the signature of the parameter type.
128   */
129  public SignatureVisitor visitParameterType() {
130    return this;
131  }
132
133  /**
134   * Visits the return type of the method.
135   *
136   * @return a non null visitor to visit the signature of the return type.
137   */
138  public SignatureVisitor visitReturnType() {
139    return this;
140  }
141
142  /**
143   * Visits the type of a method exception.
144   *
145   * @return a non null visitor to visit the signature of the exception type.
146   */
147  public SignatureVisitor visitExceptionType() {
148    return this;
149  }
150
151  /**
152   * Visits a signature corresponding to a primitive type.
153   *
154   * @param descriptor the descriptor of the primitive type, or 'V' for {@code void} .
155   */
156  public void visitBaseType(final char descriptor) {}
157
158  /**
159   * Visits a signature corresponding to a type variable.
160   *
161   * @param name the name of the type variable.
162   */
163  public void visitTypeVariable(final String name) {}
164
165  /**
166   * Visits a signature corresponding to an array type.
167   *
168   * @return a non null visitor to visit the signature of the array element type.
169   */
170  public SignatureVisitor visitArrayType() {
171    return this;
172  }
173
174  /**
175   * Starts the visit of a signature corresponding to a class or interface type.
176   *
177   * @param name the internal name of the class or interface.
178   */
179  public void visitClassType(final String name) {}
180
181  /**
182   * Visits an inner class.
183   *
184   * @param name the local name of the inner class in its enclosing class.
185   */
186  public void visitInnerClassType(final String name) {}
187
188  /** Visits an unbounded type argument of the last visited class or inner class type. */
189  public void visitTypeArgument() {}
190
191  /**
192   * Visits a type argument of the last visited class or inner class type.
193   *
194   * @param wildcard '+', '-' or '='.
195   * @return a non null visitor to visit the signature of the type argument.
196   */
197  public SignatureVisitor visitTypeArgument(final char wildcard) {
198    return this;
199  }
200
201  /** Ends the visit of a signature corresponding to a class or interface type. */
202  public void visitEnd() {}
203}