1/*
2 * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26/*
27 * This file is available under and governed by the GNU General Public
28 * License version 2 only, as published by the Free Software Foundation.
29 * However, the following notice accompanied the original version of this
30 * file:
31 *
32 * ASM: a very small and fast Java bytecode manipulation framework
33 * Copyright (c) 2000-2007 INRIA, France Telecom
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 * 1. Redistributions of source code must retain the above copyright
40 *    notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 *    notice, this list of conditions and the following disclaimer in the
43 *    documentation and/or other materials provided with the distribution.
44 * 3. Neither the name of the copyright holders nor the names of its
45 *    contributors may be used to endorse or promote products derived from
46 *    this software without specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
49 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
52 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
53 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
54 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
55 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
56 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
57 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
58 * THE POSSIBILITY OF SUCH DAMAGE.
59 */
60package com.sun.xml.internal.ws.org.objectweb.asm;
61
62/**
63 * A visitor to visit a Java method. The methods of this interface must be
64 * called in the following order: [ <tt>visitAnnotationDefault</tt> ] (
65 * <tt>visitAnnotation</tt> | <tt>visitParameterAnnotation</tt> |
66 * <tt>visitAttribute</tt> )* [ <tt>visitCode</tt> ( <tt>visitFrame</tt> |
67 * <tt>visit</tt><i>X</i>Insn</tt> | <tt>visitLabel</tt> | <tt>visitTryCatchBlock</tt> |
68 * <tt>visitLocalVariable</tt> | <tt>visitLineNumber</tt>)* <tt>visitMaxs</tt> ]
69 * <tt>visitEnd</tt>. In addition, the <tt>visit</tt><i>X</i>Insn</tt>
70 * and <tt>visitLabel</tt> methods must be called in the sequential order of
71 * the bytecode instructions of the visited code, <tt>visitTryCatchBlock</tt>
72 * must be called <i>before</i> the labels passed as arguments have been
73 * visited, and the <tt>visitLocalVariable</tt> and <tt>visitLineNumber</tt>
74 * methods must be called <i>after</i> the labels passed as arguments have been
75 * visited.
76 *
77 * @author Eric Bruneton
78 */
79public interface MethodVisitor {
80
81    // -------------------------------------------------------------------------
82    // Annotations and non standard attributes
83    // -------------------------------------------------------------------------
84
85    /**
86     * Visits the default value of this annotation interface method.
87     *
88     * @return a visitor to the visit the actual default value of this
89     *         annotation interface method, or <tt>null</tt> if this visitor
90     *         is not interested in visiting this default value. The 'name'
91     *         parameters passed to the methods of this annotation visitor are
92     *         ignored. Moreover, exacly one visit method must be called on this
93     *         annotation visitor, followed by visitEnd.
94     */
95    AnnotationVisitor visitAnnotationDefault();
96
97    /**
98     * Visits an annotation of this method.
99     *
100     * @param desc the class descriptor of the annotation class.
101     * @param visible <tt>true</tt> if the annotation is visible at runtime.
102     * @return a visitor to visit the annotation values, or <tt>null</tt> if
103     *         this visitor is not interested in visiting this annotation.
104     */
105    AnnotationVisitor visitAnnotation(String desc, boolean visible);
106
107    /**
108     * Visits an annotation of a parameter this method.
109     *
110     * @param parameter the parameter index.
111     * @param desc the class descriptor of the annotation class.
112     * @param visible <tt>true</tt> if the annotation is visible at runtime.
113     * @return a visitor to visit the annotation values, or <tt>null</tt> if
114     *         this visitor is not interested in visiting this annotation.
115     */
116    AnnotationVisitor visitParameterAnnotation(
117        int parameter,
118        String desc,
119        boolean visible);
120
121    /**
122     * Visits a non standard attribute of this method.
123     *
124     * @param attr an attribute.
125     */
126    void visitAttribute(Attribute attr);
127
128    /**
129     * Starts the visit of the method's code, if any (i.e. non abstract method).
130     */
131    void visitCode();
132
133    /**
134     * Visits the current state of the local variables and operand stack
135     * elements. This method must(*) be called <i>just before</i> any
136     * instruction <b>i</b> that follows an unconditionnal branch instruction
137     * such as GOTO or THROW, that is the target of a jump instruction, or that
138     * starts an exception handler block. The visited types must describe the
139     * values of the local variables and of the operand stack elements <i>just
140     * before</i> <b>i</b> is executed. <br> <br> (*) this is mandatory only
141     * for classes whose version is greater than or equal to
142     * {@link Opcodes#V1_6 V1_6}. <br> <br> Packed frames are basically
143     * "deltas" from the state of the previous frame (very first frame is
144     * implicitly defined by the method's parameters and access flags): <ul>
145     * <li>{@link Opcodes#F_SAME} representing frame with exactly the same
146     * locals as the previous frame and with the empty stack.</li> <li>{@link Opcodes#F_SAME1}
147     * representing frame with exactly the same locals as the previous frame and
148     * with single value on the stack (<code>nStack</code> is 1 and
149     * <code>stack[0]</code> contains value for the type of the stack item).</li>
150     * <li>{@link Opcodes#F_APPEND} representing frame with current locals are
151     * the same as the locals in the previous frame, except that additional
152     * locals are defined (<code>nLocal</code> is 1, 2 or 3 and
153     * <code>local</code> elements contains values representing added types).</li>
154     * <li>{@link Opcodes#F_CHOP} representing frame with current locals are
155     * the same as the locals in the previous frame, except that the last 1-3
156     * locals are absent and with the empty stack (<code>nLocals</code> is 1,
157     * 2 or 3). </li> <li>{@link Opcodes#F_FULL} representing complete frame
158     * data.</li> </li> </ul>
159     *
160     * @param type the type of this stack map frame. Must be
161     *        {@link Opcodes#F_NEW} for expanded frames, or
162     *        {@link Opcodes#F_FULL}, {@link Opcodes#F_APPEND},
163     *        {@link Opcodes#F_CHOP}, {@link Opcodes#F_SAME} or
164     *        {@link Opcodes#F_APPEND}, {@link Opcodes#F_SAME1} for compressed
165     *        frames.
166     * @param nLocal the number of local variables in the visited frame.
167     * @param local the local variable types in this frame. This array must not
168     *        be modified. Primitive types are represented by
169     *        {@link Opcodes#TOP}, {@link Opcodes#INTEGER},
170     *        {@link Opcodes#FLOAT}, {@link Opcodes#LONG},
171     *        {@link Opcodes#DOUBLE},{@link Opcodes#NULL} or
172     *        {@link Opcodes#UNINITIALIZED_THIS} (long and double are
173     *        represented by a single element). Reference types are represented
174     *        by String objects (representing internal names), and uninitialized
175     *        types by Label objects (this label designates the NEW instruction
176     *        that created this uninitialized value).
177     * @param nStack the number of operand stack elements in the visited frame.
178     * @param stack the operand stack types in this frame. This array must not
179     *        be modified. Its content has the same format as the "local" array.
180     */
181    void visitFrame(
182        int type,
183        int nLocal,
184        Object[] local,
185        int nStack,
186        Object[] stack);
187
188    // -------------------------------------------------------------------------
189    // Normal instructions
190    // -------------------------------------------------------------------------
191
192    /**
193     * Visits a zero operand instruction.
194     *
195     * @param opcode the opcode of the instruction to be visited. This opcode is
196     *        either NOP, ACONST_NULL, ICONST_M1, ICONST_0, ICONST_1, ICONST_2,
197     *        ICONST_3, ICONST_4, ICONST_5, LCONST_0, LCONST_1, FCONST_0,
198     *        FCONST_1, FCONST_2, DCONST_0, DCONST_1, IALOAD, LALOAD, FALOAD,
199     *        DALOAD, AALOAD, BALOAD, CALOAD, SALOAD, IASTORE, LASTORE, FASTORE,
200     *        DASTORE, AASTORE, BASTORE, CASTORE, SASTORE, POP, POP2, DUP,
201     *        DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, SWAP, IADD, LADD, FADD,
202     *        DADD, ISUB, LSUB, FSUB, DSUB, IMUL, LMUL, FMUL, DMUL, IDIV, LDIV,
203     *        FDIV, DDIV, IREM, LREM, FREM, DREM, INEG, LNEG, FNEG, DNEG, ISHL,
204     *        LSHL, ISHR, LSHR, IUSHR, LUSHR, IAND, LAND, IOR, LOR, IXOR, LXOR,
205     *        I2L, I2F, I2D, L2I, L2F, L2D, F2I, F2L, F2D, D2I, D2L, D2F, I2B,
206     *        I2C, I2S, LCMP, FCMPL, FCMPG, DCMPL, DCMPG, IRETURN, LRETURN,
207     *        FRETURN, DRETURN, ARETURN, RETURN, ARRAYLENGTH, ATHROW,
208     *        MONITORENTER, or MONITOREXIT.
209     */
210    void visitInsn(int opcode);
211
212    /**
213     * Visits an instruction with a single int operand.
214     *
215     * @param opcode the opcode of the instruction to be visited. This opcode is
216     *        either BIPUSH, SIPUSH or NEWARRAY.
217     * @param operand the operand of the instruction to be visited.<br> When
218     *        opcode is BIPUSH, operand value should be between Byte.MIN_VALUE
219     *        and Byte.MAX_VALUE.<br> When opcode is SIPUSH, operand value
220     *        should be between Short.MIN_VALUE and Short.MAX_VALUE.<br> When
221     *        opcode is NEWARRAY, operand value should be one of
222     *        {@link Opcodes#T_BOOLEAN}, {@link Opcodes#T_CHAR},
223     *        {@link Opcodes#T_FLOAT}, {@link Opcodes#T_DOUBLE},
224     *        {@link Opcodes#T_BYTE}, {@link Opcodes#T_SHORT},
225     *        {@link Opcodes#T_INT} or {@link Opcodes#T_LONG}.
226     */
227    void visitIntInsn(int opcode, int operand);
228
229    /**
230     * Visits a local variable instruction. A local variable instruction is an
231     * instruction that loads or stores the value of a local variable.
232     *
233     * @param opcode the opcode of the local variable instruction to be visited.
234     *        This opcode is either ILOAD, LLOAD, FLOAD, DLOAD, ALOAD, ISTORE,
235     *        LSTORE, FSTORE, DSTORE, ASTORE or RET.
236     * @param var the operand of the instruction to be visited. This operand is
237     *        the index of a local variable.
238     */
239    void visitVarInsn(int opcode, int var);
240
241    /**
242     * Visits a type instruction. A type instruction is an instruction that
243     * takes the internal name of a class as parameter.
244     *
245     * @param opcode the opcode of the type instruction to be visited. This
246     *        opcode is either NEW, ANEWARRAY, CHECKCAST or INSTANCEOF.
247     * @param type the operand of the instruction to be visited. This operand
248     *        must be the internal name of an object or array class (see {@link
249     *        Type#getInternalName() getInternalName}).
250     */
251    void visitTypeInsn(int opcode, String type);
252
253    /**
254     * Visits a field instruction. A field instruction is an instruction that
255     * loads or stores the value of a field of an object.
256     *
257     * @param opcode the opcode of the type instruction to be visited. This
258     *        opcode is either GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD.
259     * @param owner the internal name of the field's owner class (see {@link
260     *        Type#getInternalName() getInternalName}).
261     * @param name the field's name.
262     * @param desc the field's descriptor (see {@link Type Type}).
263     */
264    void visitFieldInsn(int opcode, String owner, String name, String desc);
265
266    /**
267     * Visits a method instruction. A method instruction is an instruction that
268     * invokes a method.
269     *
270     * @param opcode the opcode of the type instruction to be visited. This
271     *        opcode is either INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or
272     *        INVOKEINTERFACE.
273     * @param owner the internal name of the method's owner class (see {@link
274     *        Type#getInternalName() getInternalName}).
275     * @param name the method's name.
276     * @param desc the method's descriptor (see {@link Type Type}).
277     */
278    void visitMethodInsn(int opcode, String owner, String name, String desc);
279
280    /**
281     * Visits a jump instruction. A jump instruction is an instruction that may
282     * jump to another instruction.
283     *
284     * @param opcode the opcode of the type instruction to be visited. This
285     *        opcode is either IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ,
286     *        IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ACMPEQ,
287     *        IF_ACMPNE, GOTO, JSR, IFNULL or IFNONNULL.
288     * @param label the operand of the instruction to be visited. This operand
289     *        is a label that designates the instruction to which the jump
290     *        instruction may jump.
291     */
292    void visitJumpInsn(int opcode, Label label);
293
294    /**
295     * Visits a label. A label designates the instruction that will be visited
296     * just after it.
297     *
298     * @param label a {@link Label Label} object.
299     */
300    void visitLabel(Label label);
301
302    // -------------------------------------------------------------------------
303    // Special instructions
304    // -------------------------------------------------------------------------
305
306    /**
307     * Visits a LDC instruction.
308     *
309     * @param cst the constant to be loaded on the stack. This parameter must be
310     *        a non null {@link Integer}, a {@link Float}, a {@link Long}, a
311     *        {@link Double} a {@link String} (or a {@link Type} for
312     *        <tt>.class</tt> constants, for classes whose version is 49.0 or
313     *        more).
314     */
315    void visitLdcInsn(Object cst);
316
317    /**
318     * Visits an IINC instruction.
319     *
320     * @param var index of the local variable to be incremented.
321     * @param increment amount to increment the local variable by.
322     */
323    void visitIincInsn(int var, int increment);
324
325    /**
326     * Visits a TABLESWITCH instruction.
327     *
328     * @param min the minimum key value.
329     * @param max the maximum key value.
330     * @param dflt beginning of the default handler block.
331     * @param labels beginnings of the handler blocks. <tt>labels[i]</tt> is
332     *        the beginning of the handler block for the <tt>min + i</tt> key.
333     */
334    void visitTableSwitchInsn(int min, int max, Label dflt, Label[] labels);
335
336    /**
337     * Visits a LOOKUPSWITCH instruction.
338     *
339     * @param dflt beginning of the default handler block.
340     * @param keys the values of the keys.
341     * @param labels beginnings of the handler blocks. <tt>labels[i]</tt> is
342     *        the beginning of the handler block for the <tt>keys[i]</tt> key.
343     */
344    void visitLookupSwitchInsn(Label dflt, int[] keys, Label[] labels);
345
346    /**
347     * Visits a MULTIANEWARRAY instruction.
348     *
349     * @param desc an array type descriptor (see {@link Type Type}).
350     * @param dims number of dimensions of the array to allocate.
351     */
352    void visitMultiANewArrayInsn(String desc, int dims);
353
354    // -------------------------------------------------------------------------
355    // Exceptions table entries, debug information, max stack and max locals
356    // -------------------------------------------------------------------------
357
358    /**
359     * Visits a try catch block.
360     *
361     * @param start beginning of the exception handler's scope (inclusive).
362     * @param end end of the exception handler's scope (exclusive).
363     * @param handler beginning of the exception handler's code.
364     * @param type internal name of the type of exceptions handled by the
365     *        handler, or <tt>null</tt> to catch any exceptions (for "finally"
366     *        blocks).
367     * @throws IllegalArgumentException if one of the labels has already been
368     *         visited by this visitor (by the {@link #visitLabel visitLabel}
369     *         method).
370     */
371    void visitTryCatchBlock(Label start, Label end, Label handler, String type);
372
373    /**
374     * Visits a local variable declaration.
375     *
376     * @param name the name of a local variable.
377     * @param desc the type descriptor of this local variable.
378     * @param signature the type signature of this local variable. May be
379     *        <tt>null</tt> if the local variable type does not use generic
380     *        types.
381     * @param start the first instruction corresponding to the scope of this
382     *        local variable (inclusive).
383     * @param end the last instruction corresponding to the scope of this local
384     *        variable (exclusive).
385     * @param index the local variable's index.
386     * @throws IllegalArgumentException if one of the labels has not already
387     *         been visited by this visitor (by the
388     *         {@link #visitLabel visitLabel} method).
389     */
390    void visitLocalVariable(
391        String name,
392        String desc,
393        String signature,
394        Label start,
395        Label end,
396        int index);
397
398    /**
399     * Visits a line number declaration.
400     *
401     * @param line a line number. This number refers to the source file from
402     *        which the class was compiled.
403     * @param start the first instruction corresponding to this line number.
404     * @throws IllegalArgumentException if <tt>start</tt> has not already been
405     *         visited by this visitor (by the {@link #visitLabel visitLabel}
406     *         method).
407     */
408    void visitLineNumber(int line, Label start);
409
410    /**
411     * Visits the maximum stack size and the maximum number of local variables
412     * of the method.
413     *
414     * @param maxStack maximum stack size of the method.
415     * @param maxLocals maximum number of local variables for the method.
416     */
417    void visitMaxs(int maxStack, int maxLocals);
418
419    /**
420     * Visits the end of the method. This method, which is the last one to be
421     * called, is used to inform the visitor that all the annotations and
422     * attributes of the method have been visited.
423     */
424    void visitEnd();
425}
426