PageRenderTime 35ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/com/alibaba/fastjson/asm/MethodVisitor.java

https://bitbucket.org/xiejuntao/xdesktop
Java | 183 lines | 15 code | 17 blank | 151 comment | 0 complexity | fa7610e9da2be6412f745071599ab804 MD5 | raw file
  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. */
  30. package com.alibaba.fastjson.asm;
  31. /**
  32. * A visitor to visit a Java method. The methods of this interface must be called in the following order: [
  33. * <tt>visitAnnotationDefault</tt> ] ( <tt>visitAnnotation</tt> | <tt>visitParameterAnnotation</tt> |
  34. * <tt>visitAttribute</tt> )* [ <tt>visitCode</tt> ( <tt>visitFrame</tt> | <tt>visit</tt><i>X</i>Insn</tt> |
  35. * <tt>visitLabel</tt> | <tt>visitTryCatchBlock</tt> | <tt>visitLocalVariable</tt> | <tt>visitLineNumber</tt>)*
  36. * <tt>visitMaxs</tt> ] <tt>visitEnd</tt>. In addition, the <tt>visit</tt><i>X</i>Insn</tt> and <tt>visitLabel</tt>
  37. * methods must be called in the sequential order of the bytecode instructions of the visited code,
  38. * <tt>visitTryCatchBlock</tt> must be called <i>before</i> the labels passed as arguments have been visited, and the
  39. * <tt>visitLocalVariable</tt> and <tt>visitLineNumber</tt> methods must be called <i>after</i> the labels passed as
  40. * arguments have been visited.
  41. *
  42. * @author Eric Bruneton
  43. */
  44. public interface MethodVisitor {
  45. // -------------------------------------------------------------------------
  46. // Annotations and non standard attributes
  47. // -------------------------------------------------------------------------
  48. // -------------------------------------------------------------------------
  49. // Normal instructions
  50. // -------------------------------------------------------------------------
  51. /**
  52. * Visits a zero operand instruction.
  53. *
  54. * @param opcode the opcode of the instruction to be visited. This opcode is either NOP, ACONST_NULL, ICONST_M1,
  55. * ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5, LCONST_0, LCONST_1, FCONST_0, FCONST_1, FCONST_2,
  56. * DCONST_0, DCONST_1, IALOAD, LALOAD, FALOAD, DALOAD, AALOAD, BALOAD, CALOAD, SALOAD, IASTORE, LASTORE, FASTORE,
  57. * DASTORE, AASTORE, BASTORE, CASTORE, SASTORE, POP, POP2, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, SWAP, IADD,
  58. * LADD, FADD, DADD, ISUB, LSUB, FSUB, DSUB, IMUL, LMUL, FMUL, DMUL, IDIV, LDIV, FDIV, DDIV, IREM, LREM, FREM, DREM,
  59. * INEG, LNEG, FNEG, DNEG, ISHL, LSHL, ISHR, LSHR, IUSHR, LUSHR, IAND, LAND, IOR, LOR, IXOR, LXOR, I2L, I2F, I2D,
  60. * L2I, L2F, L2D, F2I, F2L, F2D, D2I, D2L, D2F, I2B, I2C, I2S, LCMP, FCMPL, FCMPG, DCMPL, DCMPG, IRETURN, LRETURN,
  61. * FRETURN, DRETURN, ARETURN, RETURN, ARRAYLENGTH, ATHROW, MONITORENTER, or MONITOREXIT.
  62. */
  63. void visitInsn(int opcode);
  64. /**
  65. * Visits an instruction with a single int operand.
  66. *
  67. * @param opcode the opcode of the instruction to be visited. This opcode is either BIPUSH, SIPUSH or NEWARRAY.
  68. * @param operand the operand of the instruction to be visited.<br>
  69. * When opcode is BIPUSH, operand value should be between Byte.MIN_VALUE and Byte.MAX_VALUE.<br>
  70. * When opcode is SIPUSH, operand value should be between Short.MIN_VALUE and Short.MAX_VALUE.<br>
  71. * When opcode is NEWARRAY, operand value should be one of {@link Opcodes#T_BOOLEAN}, {@link Opcodes#T_CHAR},
  72. * {@link Opcodes#T_FLOAT}, {@link Opcodes#T_DOUBLE}, {@link Opcodes#T_BYTE}, {@link Opcodes#T_SHORT},
  73. * {@link Opcodes#T_INT} or {@link Opcodes#T_LONG}.
  74. */
  75. void visitIntInsn(int opcode, int operand);
  76. /**
  77. * Visits a local variable instruction. A local variable instruction is an instruction that loads or stores the
  78. * value of a local variable.
  79. *
  80. * @param opcode the opcode of the local variable instruction to be visited. This opcode is either ILOAD, LLOAD,
  81. * FLOAD, DLOAD, ALOAD, ISTORE, LSTORE, FSTORE, DSTORE, ASTORE or RET.
  82. * @param var the operand of the instruction to be visited. This operand is the index of a local variable.
  83. */
  84. void visitVarInsn(int opcode, int var);
  85. /**
  86. * Visits a type instruction. A type instruction is an instruction that takes the internal name of a class as
  87. * parameter.
  88. *
  89. * @param opcode the opcode of the type instruction to be visited. This opcode is either NEW, ANEWARRAY, CHECKCAST
  90. * or INSTANCEOF.
  91. * @param type the operand of the instruction to be visited. This operand must be the internal name of an object or
  92. * array class (see {@link Type#getInternalName() getInternalName}).
  93. */
  94. void visitTypeInsn(int opcode, String type);
  95. /**
  96. * Visits a field instruction. A field instruction is an instruction that loads or stores the value of a field of an
  97. * object.
  98. *
  99. * @param opcode the opcode of the type instruction to be visited. This opcode is either GETSTATIC, PUTSTATIC,
  100. * GETFIELD or PUTFIELD.
  101. * @param owner the internal name of the field's owner class (see {@link Type#getInternalName() getInternalName}).
  102. * @param name the field's name.
  103. * @param desc the field's descriptor (see {@link Type Type}).
  104. */
  105. void visitFieldInsn(int opcode, String owner, String name, String desc);
  106. /**
  107. * Visits a method instruction. A method instruction is an instruction that invokes a method.
  108. *
  109. * @param opcode the opcode of the type instruction to be visited. This opcode is either INVOKEVIRTUAL,
  110. * INVOKESPECIAL, INVOKESTATIC, INVOKEINTERFACE or INVOKEDYNAMIC.
  111. * @param owner the internal name of the method's owner class (see {@link Type#getInternalName() getInternalName})
  112. * or {@link com.alibaba.fastjson.asm.Opcodes#INVOKEDYNAMIC_OWNER}.
  113. * @param name the method's name.
  114. * @param desc the method's descriptor (see {@link Type Type}).
  115. */
  116. void visitMethodInsn(int opcode, String owner, String name, String desc);
  117. /**
  118. * Visits a jump instruction. A jump instruction is an instruction that may jump to another instruction.
  119. *
  120. * @param opcode the opcode of the type instruction to be visited. This opcode is either IFEQ, IFNE, IFLT, IFGE,
  121. * IFGT, IFLE, IF_ICMPEQ, IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ACMPEQ, IF_ACMPNE, GOTO, JSR,
  122. * IFNULL or IFNONNULL.
  123. * @param label the operand of the instruction to be visited. This operand is a label that designates the
  124. * instruction to which the jump instruction may jump.
  125. */
  126. void visitJumpInsn(int opcode, Label label);
  127. /**
  128. * Visits a label. A label designates the instruction that will be visited just after it.
  129. *
  130. * @param label a {@link Label Label} object.
  131. */
  132. void visitLabel(Label label);
  133. // -------------------------------------------------------------------------
  134. // Special instructions
  135. // -------------------------------------------------------------------------
  136. /**
  137. * Visits a LDC instruction.
  138. *
  139. * @param cst the constant to be loaded on the stack. This parameter must be a non null {@link Integer}, a
  140. * {@link Float}, a {@link Long}, a {@link Double} a {@link String} (or a {@link Type} for <tt>.class</tt>
  141. * constants, for classes whose version is 49.0 or more).
  142. */
  143. void visitLdcInsn(Object cst);
  144. /**
  145. * Visits an IINC instruction.
  146. *
  147. * @param var index of the local variable to be incremented.
  148. * @param increment amount to increment the local variable by.
  149. */
  150. void visitIincInsn(int var, int increment);
  151. // -------------------------------------------------------------------------
  152. // Exceptions table entries, debug information, max stack and max locals
  153. // -------------------------------------------------------------------------
  154. /**
  155. * Visits the maximum stack size and the maximum number of local variables of the method.
  156. *
  157. * @param maxStack maximum stack size of the method.
  158. * @param maxLocals maximum number of local variables for the method.
  159. */
  160. void visitMaxs(int maxStack, int maxLocals);
  161. /**
  162. * Visits the end of the method. This method, which is the last one to be called, is used to inform the visitor that
  163. * all the annotations and attributes of the method have been visited.
  164. */
  165. void visitEnd();
  166. }