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