1/***
2 * ASM: a very small and fast Java bytecode manipulation framework
3 * Copyright (c) 2000-2007 INRIA, France Telecom
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the copyright holders nor the names of its
15 *    contributors may be used to endorse or promote products derived from
16 *    this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGE.
29 */
30package org.mockito.asm;
31
32/**
33 * A visitor to visit a Java class. The methods of this interface must be called
34 * in the following order: <tt>visit</tt> [ <tt>visitSource</tt> ] [
35 * <tt>visitOuterClass</tt> ] ( <tt>visitAnnotation</tt> |
36 * <tt>visitAttribute</tt> )* (<tt>visitInnerClass</tt> |
37 * <tt>visitField</tt> | <tt>visitMethod</tt> )* <tt>visitEnd</tt>.
38 *
39 * @author Eric Bruneton
40 */
41public interface ClassVisitor {
42
43    /**
44     * Visits the header of the class.
45     *
46     * @param version the class version.
47     * @param access the class's access flags (see {@link Opcodes}). This
48     *        parameter also indicates if the class is deprecated.
49     * @param name the internal name of the class (see
50     *        {@link Type#getInternalName() getInternalName}).
51     * @param signature the signature of this class. May be <tt>null</tt> if
52     *        the class is not a generic one, and does not extend or implement
53     *        generic classes or interfaces.
54     * @param superName the internal of name of the super class (see
55     *        {@link Type#getInternalName() getInternalName}). For interfaces,
56     *        the super class is {@link Object}. May be <tt>null</tt>, but
57     *        only for the {@link Object} class.
58     * @param interfaces the internal names of the class's interfaces (see
59     *        {@link Type#getInternalName() getInternalName}). May be
60     *        <tt>null</tt>.
61     */
62    void visit(
63        int version,
64        int access,
65        String name,
66        String signature,
67        String superName,
68        String[] interfaces);
69
70    /**
71     * Visits the source of the class.
72     *
73     * @param source the name of the source file from which the class was
74     *        compiled. May be <tt>null</tt>.
75     * @param debug additional debug information to compute the correspondance
76     *        between source and compiled elements of the class. May be
77     *        <tt>null</tt>.
78     */
79    void visitSource(String source, String debug);
80
81    /**
82     * Visits the enclosing class of the class. This method must be called only
83     * if the class has an enclosing class.
84     *
85     * @param owner internal name of the enclosing class of the class.
86     * @param name the name of the method that contains the class, or
87     *        <tt>null</tt> if the class is not enclosed in a method of its
88     *        enclosing class.
89     * @param desc the descriptor of the method that contains the class, or
90     *        <tt>null</tt> if the class is not enclosed in a method of its
91     *        enclosing class.
92     */
93    void visitOuterClass(String owner, String name, String desc);
94
95    /**
96     * Visits an annotation of the class.
97     *
98     * @param desc the class descriptor of the annotation class.
99     * @param visible <tt>true</tt> if the annotation is visible at runtime.
100     * @return a visitor to visit the annotation values, or <tt>null</tt> if
101     *         this visitor is not interested in visiting this annotation.
102     */
103    AnnotationVisitor visitAnnotation(String desc, boolean visible);
104
105    /**
106     * Visits a non standard attribute of the class.
107     *
108     * @param attr an attribute.
109     */
110    void visitAttribute(Attribute attr);
111
112    /**
113     * Visits information about an inner class. This inner class is not
114     * necessarily a member of the class being visited.
115     *
116     * @param name the internal name of an inner class (see
117     *        {@link Type#getInternalName() getInternalName}).
118     * @param outerName the internal name of the class to which the inner class
119     *        belongs (see {@link Type#getInternalName() getInternalName}). May
120     *        be <tt>null</tt> for not member classes.
121     * @param innerName the (simple) name of the inner class inside its
122     *        enclosing class. May be <tt>null</tt> for anonymous inner
123     *        classes.
124     * @param access the access flags of the inner class as originally declared
125     *        in the enclosing class.
126     */
127    void visitInnerClass(
128        String name,
129        String outerName,
130        String innerName,
131        int access);
132
133    /**
134     * Visits a field of the class.
135     *
136     * @param access the field's access flags (see {@link Opcodes}). This
137     *        parameter also indicates if the field is synthetic and/or
138     *        deprecated.
139     * @param name the field's name.
140     * @param desc the field's descriptor (see {@link Type Type}).
141     * @param signature the field's signature. May be <tt>null</tt> if the
142     *        field's type does not use generic types.
143     * @param value the field's initial value. This parameter, which may be
144     *        <tt>null</tt> if the field does not have an initial value, must
145     *        be an {@link Integer}, a {@link Float}, a {@link Long}, a
146     *        {@link Double} or a {@link String} (for <tt>int</tt>,
147     *        <tt>float</tt>, <tt>long</tt> or <tt>String</tt> fields
148     *        respectively). <i>This parameter is only used for static fields</i>.
149     *        Its value is ignored for non static fields, which must be
150     *        initialized through bytecode instructions in constructors or
151     *        methods.
152     * @return a visitor to visit field annotations and attributes, or
153     *         <tt>null</tt> if this class visitor is not interested in
154     *         visiting these annotations and attributes.
155     */
156    FieldVisitor visitField(
157        int access,
158        String name,
159        String desc,
160        String signature,
161        Object value);
162
163    /**
164     * Visits a method of the class. This method <i>must</i> return a new
165     * {@link MethodVisitor} instance (or <tt>null</tt>) each time it is
166     * called, i.e., it should not return a previously returned visitor.
167     *
168     * @param access the method's access flags (see {@link Opcodes}). This
169     *        parameter also indicates if the method is synthetic and/or
170     *        deprecated.
171     * @param name the method's name.
172     * @param desc the method's descriptor (see {@link Type Type}).
173     * @param signature the method's signature. May be <tt>null</tt> if the
174     *        method parameters, return type and exceptions do not use generic
175     *        types.
176     * @param exceptions the internal names of the method's exception classes
177     *        (see {@link Type#getInternalName() getInternalName}). May be
178     *        <tt>null</tt>.
179     * @return an object to visit the byte code of the method, or <tt>null</tt>
180     *         if this class visitor is not interested in visiting the code of
181     *         this method.
182     */
183    MethodVisitor visitMethod(
184        int access,
185        String name,
186        String desc,
187        String signature,
188        String[] exceptions);
189
190    /**
191     * Visits the end of the class. This method, which is the last one to be
192     * called, is used to inform the visitor that all the fields and methods of
193     * the class have been visited.
194     */
195    void visitEnd();
196}
197