View Javadoc
1   package mockit.asm.classes;
2   
3   import edu.umd.cs.findbugs.annotations.NonNull;
4   import edu.umd.cs.findbugs.annotations.Nullable;
5   
6   import mockit.asm.BaseWriter;
7   import mockit.asm.fields.FieldVisitor;
8   import mockit.asm.jvmConstants.Access;
9   import mockit.asm.jvmConstants.Opcodes;
10  import mockit.asm.methods.MethodVisitor;
11  import mockit.asm.types.JavaType;
12  
13  /**
14   * A visitor to visit a Java class, in the following order:<br>
15   * <code>visit</code> (<code>visitAnnotation</code>)* (<code>visitInnerClass</code> | <code>visitField</code> |
16   * <code>visitMethod</code>)* <code>visitEnd</code>.
17   */
18  public class ClassVisitor extends BaseWriter {
19      protected ClassVisitor() {
20      }
21  
22      /**
23       * Visits the header of the class.
24       *
25       * @param version
26       *            the class version
27       * @param access
28       *            the class's access flags (see {@link Access})
29       * @param name
30       *            the internal name of the class
31       * @param additionalInfo
32       *            additional class information
33       */
34      public void visit(int version, int access, @NonNull String name, @NonNull ClassInfo additionalInfo) {
35      }
36  
37      /**
38       * Visits information about an inner class, which is not necessarily a member of the class being visited.
39       *
40       * @param name
41       *            the internal name of an inner class
42       * @param outerName
43       *            the internal name of the class to which the inner class belongs; <code>null</code> for not member
44       *            classes
45       * @param innerName
46       *            the (simple) name of the inner class inside its enclosing class; <code>null</code> for anonymous inner
47       *            classes
48       * @param access
49       *            the access flags of the inner class as originally declared in the enclosing class
50       */
51      public void visitInnerClass(@NonNull String name, @Nullable String outerName, @Nullable String innerName,
52              int access) {
53      }
54  
55      /**
56       * Visits a field of the class.
57       *
58       * @param access
59       *            the field's access flags (see {@link Access})
60       * @param name
61       *            the field's name
62       * @param desc
63       *            the field's descriptor (see {@link JavaType})
64       * @param signature
65       *            the field's signature; <code>null</code> when the field's type does not use generic types
66       * @param value
67       *            the field's initial value; <code>null</code> when the field does not have an initial value; otherwise,
68       *            must be an {@link Integer}, a {@link Float}, a {@link Long}, a {@link Double} or a {@link String} (for
69       *            <code>int</code>, <code>float</code>, <code>long</code> or <code>String</code> fields respectively);
70       *            <em>this parameter is only used for static fields</em>; its value is ignored for non static fields,
71       *            which must be initialized through bytecode instructions in constructors or methods
72       *
73       * @return a visitor to visit field annotations and attributes, or <code>null</code> if this class visitor is not
74       *         interested in visiting these annotations and attributes
75       */
76      @Nullable
77      public FieldVisitor visitField(int access, @NonNull String name, @NonNull String desc, @Nullable String signature,
78              @Nullable Object value) {
79          return null;
80      }
81  
82      /**
83       * Visits a method of the class. This method <i>must</i> return a new {@link MethodVisitor} instance (or
84       * <code>null</code>) each time it is called, i.e., it should not return a previously returned visitor.
85       *
86       * @param access
87       *            the method's access flags (see {@link Opcodes})
88       * @param name
89       *            the method's name
90       * @param desc
91       *            the method's descriptor (see {@link JavaType})
92       * @param signature
93       *            the method's signature, <code>null</code> if the method parameters, return type and exceptions do not
94       *            use generic types
95       * @param exceptions
96       *            the internal names of the method's exception classes
97       *
98       * @return an object to visit the byte code of the method, or <code>null</code> if this class visitor is not
99       *         interested in visiting the code of this method
100      */
101     @Nullable
102     public MethodVisitor visitMethod(int access, @NonNull String name, @NonNull String desc, @Nullable String signature,
103             @Nullable String[] exceptions) {
104         return null;
105     }
106 
107     /**
108      * Returns the bytecode of the class that was built with this class visitor.
109      */
110     public byte[] toByteArray() {
111         return null;
112     }
113 }