KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > asm > MethodVisitor


1 /***
2  * ASM: a very small and fast Java bytecode manipulation framework
3  * Copyright (c) 2000-2005 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  */

30 package org.objectweb.asm;
31
32 /**
33  * A visitor to visit a Java method. The methods of this interface must be
34  * called in the following order: [ <tt>visitAnnotationDefault</tt> ] (
35  * <tt>visitAnnotation</tt> | <tt>visitParameterAnnotation</tt> |
36  * <tt>visitAttribute</tt> )* [ <tt>visitCode</tt> ( <tt>visit</tt><i>X</i>Insn</tt> |
37  * <tt>visitLabel</tt> | <tt>visitTryCatchBlock</tt> | <tt>visitLocalVariable</tt> |
38  * <tt>visitLineNumber</tt>)* <tt>visitMaxs</tt> ] <tt>visitEnd</tt>. In
39  * addition, the <tt>visit</tt><i>X</i>Insn</tt> and <tt>visitLabel</tt>
40  * methods must be called in the sequential order of the bytecode instructions
41  * of the visited code, and the <tt>visitTryCatchBlock</tt>, <tt>visitLocalVariable</tt>
42  * and <tt>visitLineNumber</tt> methods must be called after the labels passed
43  * as arguments have been visited.
44  *
45  * @author Eric Bruneton
46  */

47 public interface MethodVisitor {
48
49     // -------------------------------------------------------------------------
50
// Annotations and non standard attributes
51
// -------------------------------------------------------------------------
52

53     /**
54      * Visits the default value of this annotation interface method.
55      *
56      * @return a non null visitor to the visit the actual default value of this
57      * annotation interface method. The 'name' parameters passed to the
58      * methods of this annotation visitor are ignored. Moreover, exacly
59      * one visit method must be called on this annotation visitor,
60      * followed by visitEnd.
61      */

62     AnnotationVisitor visitAnnotationDefault();
63
64     /**
65      * Visits an annotation of this method.
66      *
67      * @param desc the class descriptor of the annotation class.
68      * @param visible <tt>true</tt> if the annotation is visible at runtime.
69      * @return a non null visitor to visit the annotation values.
70      */

71     AnnotationVisitor visitAnnotation(String JavaDoc desc, boolean visible);
72
73     /**
74      * Visits an annotation of a parameter this method.
75      *
76      * @param parameter the parameter index.
77      * @param desc the class descriptor of the annotation class.
78      * @param visible <tt>true</tt> if the annotation is visible at runtime.
79      * @return a non null visitor to visit the annotation values.
80      */

81     AnnotationVisitor visitParameterAnnotation(
82         int parameter,
83         String JavaDoc desc,
84         boolean visible);
85
86     /**
87      * Visits a non standard attribute of this method.
88      *
89      * @param attr an attribute.
90      */

91     void visitAttribute(Attribute attr);
92
93     /**
94      * Starts the visit of the method's code, if any (i.e. non abstract method).
95      */

96     void visitCode();
97
98     // -------------------------------------------------------------------------
99
// Normal instructions
100
// -------------------------------------------------------------------------
101

102     /**
103      * Visits a zero operand instruction.
104      *
105      * @param opcode the opcode of the instruction to be visited. This opcode is
106      * either NOP, ACONST_NULL, ICONST_M1, ICONST_0, ICONST_1, ICONST_2,
107      * ICONST_3, ICONST_4, ICONST_5, LCONST_0, LCONST_1, FCONST_0,
108      * FCONST_1, FCONST_2, DCONST_0, DCONST_1, IALOAD, LALOAD, FALOAD,
109      * DALOAD, AALOAD, BALOAD, CALOAD, SALOAD, IASTORE, LASTORE, FASTORE,
110      * DASTORE, AASTORE, BASTORE, CASTORE, SASTORE, POP, POP2, DUP,
111      * DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, SWAP, IADD, LADD, FADD,
112      * DADD, ISUB, LSUB, FSUB, DSUB, IMUL, LMUL, FMUL, DMUL, IDIV, LDIV,
113      * FDIV, DDIV, IREM, LREM, FREM, DREM, INEG, LNEG, FNEG, DNEG, ISHL,
114      * LSHL, ISHR, LSHR, IUSHR, LUSHR, IAND, LAND, IOR, LOR, IXOR, LXOR,
115      * I2L, I2F, I2D, L2I, L2F, L2D, F2I, F2L, F2D, D2I, D2L, D2F, I2B,
116      * I2C, I2S, LCMP, FCMPL, FCMPG, DCMPL, DCMPG, IRETURN, LRETURN,
117      * FRETURN, DRETURN, ARETURN, RETURN, ARRAYLENGTH, ATHROW,
118      * MONITORENTER, or MONITOREXIT.
119      */

120     void visitInsn(int opcode);
121
122     /**
123      * Visits an instruction with a single int operand.
124      *
125      * @param opcode the opcode of the instruction to be visited. This opcode is
126      * either BIPUSH, SIPUSH or NEWARRAY.
127      * @param operand the operand of the instruction to be visited.
128      */

129     void visitIntInsn(int opcode, int operand);
130
131     /**
132      * Visits a local variable instruction. A local variable instruction is an
133      * instruction that loads or stores the value of a local variable.
134      *
135      * @param opcode the opcode of the local variable instruction to be visited.
136      * This opcode is either ILOAD, LLOAD, FLOAD, DLOAD, ALOAD, ISTORE,
137      * LSTORE, FSTORE, DSTORE, ASTORE or RET.
138      * @param var the operand of the instruction to be visited. This operand is
139      * the index of a local variable.
140      */

141     void visitVarInsn(int opcode, int var);
142
143     /**
144      * Visits a type instruction. A type instruction is an instruction that
145      * takes a type descriptor as parameter.
146      *
147      * @param opcode the opcode of the type instruction to be visited. This
148      * opcode is either NEW, ANEWARRAY, CHECKCAST or INSTANCEOF.
149      * @param desc the operand of the instruction to be visited. This operand is
150      * must be a fully qualified class name in internal form, or the type
151      * descriptor of an array type (see {@link Type Type}).
152      */

153     void visitTypeInsn(int opcode, String JavaDoc desc);
154
155     /**
156      * Visits a field instruction. A field instruction is an instruction that
157      * loads or stores the value of a field of an object.
158      *
159      * @param opcode the opcode of the type instruction to be visited. This
160      * opcode is either GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD.
161      * @param owner the internal name of the field's owner class (see {@link
162      * Type#getInternalName() getInternalName}).
163      * @param name the field's name.
164      * @param desc the field's descriptor (see {@link Type Type}).
165      */

166     void visitFieldInsn(int opcode, String JavaDoc owner, String JavaDoc name, String JavaDoc desc);
167
168     /**
169      * Visits a method instruction. A method instruction is an instruction that
170      * invokes a method.
171      *
172      * @param opcode the opcode of the type instruction to be visited. This
173      * opcode is either INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or
174      * INVOKEINTERFACE.
175      * @param owner the internal name of the method's owner class (see {@link
176      * Type#getInternalName() getInternalName}).
177      * @param name the method's name.
178      * @param desc the method's descriptor (see {@link Type Type}).
179      */

180     void visitMethodInsn(int opcode, String JavaDoc owner, String JavaDoc name, String JavaDoc desc);
181
182     /**
183      * Visits a jump instruction. A jump instruction is an instruction that may
184      * jump to another instruction.
185      *
186      * @param opcode the opcode of the type instruction to be visited. This
187      * opcode is either IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ,
188      * IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ACMPEQ,
189      * IF_ACMPNE, GOTO, JSR, IFNULL or IFNONNULL.
190      * @param label the operand of the instruction to be visited. This operand
191      * is a label that designates the instruction to which the jump
192      * instruction may jump.
193      */

194     void visitJumpInsn(int opcode, Label label);
195
196     /**
197      * Visits a label. A label designates the instruction that will be visited
198      * just after it.
199      *
200      * @param label a {@link Label Label} object.
201      */

202     void visitLabel(Label label);
203
204     // -------------------------------------------------------------------------
205
// Special instructions
206
// -------------------------------------------------------------------------
207

208     /**
209      * Visits a LDC instruction.
210      *
211      * @param cst the constant to be loaded on the stack. This parameter must be
212      * a non null {@link Integer}, a {@link Float}, a {@link Long}, a
213      * {@link Double} a {@link String} (or a {@link Type} for
214      * <tt>.class</tt> constants, for classes whose version is 49.0 or
215      * more).
216      */

217     void visitLdcInsn(Object JavaDoc cst);
218
219     /**
220      * Visits an IINC instruction.
221      *
222      * @param var index of the local variable to be incremented.
223      * @param increment amount to increment the local variable by.
224      */

225     void visitIincInsn(int var, int increment);
226
227     /**
228      * Visits a TABLESWITCH instruction.
229      *
230      * @param min the minimum key value.
231      * @param max the maximum key value.
232      * @param dflt beginning of the default handler block.
233      * @param labels beginnings of the handler blocks. <tt>labels[i]</tt> is
234      * the beginning of the handler block for the <tt>min + i</tt> key.
235      */

236     void visitTableSwitchInsn(int min, int max, Label dflt, Label labels[]);
237
238     /**
239      * Visits a LOOKUPSWITCH instruction.
240      *
241      * @param dflt beginning of the default handler block.
242      * @param keys the values of the keys.
243      * @param labels beginnings of the handler blocks. <tt>labels[i]</tt> is
244      * the beginning of the handler block for the <tt>keys[i]</tt> key.
245      */

246     void visitLookupSwitchInsn(Label dflt, int keys[], Label labels[]);
247
248     /**
249      * Visits a MULTIANEWARRAY instruction.
250      *
251      * @param desc an array type descriptor (see {@link Type Type}).
252      * @param dims number of dimensions of the array to allocate.
253      */

254     void visitMultiANewArrayInsn(String JavaDoc desc, int dims);
255
256     // -------------------------------------------------------------------------
257
// Exceptions table entries, debug information, max stack size and max
258
// locals
259
// -------------------------------------------------------------------------
260

261     /**
262      * Visits a try catch block.
263      *
264      * @param start beginning of the exception handler's scope (inclusive).
265      * @param end end of the exception handler's scope (exclusive).
266      * @param handler beginning of the exception handler's code.
267      * @param type internal name of the type of exceptions handled by the
268      * handler, or <tt>null</tt> to catch any exceptions (for "finally"
269      * blocks).
270      * @throws IllegalArgumentException if one of the labels has not already
271      * been visited by this visitor (by the
272      * {@link #visitLabel visitLabel} method).
273      */

274     void visitTryCatchBlock(Label start, Label end, Label handler, String JavaDoc type);
275
276     /**
277      * Visits a local variable declaration.
278      *
279      * @param name the name of a local variable.
280      * @param desc the type descriptor of this local variable.
281      * @param signature the type signature of this local variable. May be
282      * <tt>null</tt> if the local variable type does not use generic
283      * types.
284      * @param start the first instruction corresponding to the scope of this
285      * local variable (inclusive).
286      * @param end the last instruction corresponding to the scope of this local
287      * variable (exclusive).
288      * @param index the local variable's index.
289      * @throws IllegalArgumentException if one of the labels has not already
290      * been visited by this visitor (by the
291      * {@link #visitLabel visitLabel} method).
292      */

293     void visitLocalVariable(
294         String JavaDoc name,
295         String JavaDoc desc,
296         String JavaDoc signature,
297         Label start,
298         Label end,
299         int index);
300
301     /**
302      * Visits a line number declaration.
303      *
304      * @param line a line number. This number refers to the source file from
305      * which the class was compiled.
306      * @param start the first instruction corresponding to this line number.
307      * @throws IllegalArgumentException if <tt>start</tt> has not already been
308      * visited by this visitor (by the {@link #visitLabel visitLabel}
309      * method).
310      */

311     void visitLineNumber(int line, Label start);
312
313     /**
314      * Visits the maximum stack size and the maximum number of local variables
315      * of the method.
316      *
317      * @param maxStack maximum stack size of the method.
318      * @param maxLocals maximum number of local variables for the method.
319      */

320     void visitMaxs(int maxStack, int maxLocals);
321
322     /**
323      * Visits the end of the method. This method, which is the last one to be
324      * called, is used to inform the visitor that all the annotations and
325      * attributes of the method have been visited.
326      */

327     void visitEnd();
328 }
329
Popular Tags