You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MethodParametersAttribute.java 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package javassist.bytecode;
  2. import java.io.DataInputStream;
  3. import java.io.IOException;
  4. import java.util.Map;
  5. /**
  6. * <code>MethodParameters_attribute</code>.
  7. */
  8. public class MethodParametersAttribute extends AttributeInfo {
  9. /**
  10. * The name of this attribute <code>"MethodParameters"</code>.
  11. */
  12. public static final String tag = "MethodParameters";
  13. MethodParametersAttribute(ConstPool cp, int n, DataInputStream in)
  14. throws IOException
  15. {
  16. super(cp, n, in);
  17. }
  18. /**
  19. * Constructs an attribute.
  20. *
  21. * @param cp a constant pool table.
  22. * @param names an array of parameter names.
  23. * The i-th element is the name of the i-th parameter.
  24. * @param flags an array of parameter access flags.
  25. */
  26. public MethodParametersAttribute(ConstPool cp, String[] names, int[] flags) {
  27. super(cp, tag);
  28. byte[] data = new byte[names.length * 4 + 1];
  29. data[0] = (byte)names.length;
  30. for (int i = 0; i < names.length; i++) {
  31. ByteArray.write16bit(cp.addUtf8Info(names[i]), data, i * 4 + 1);
  32. ByteArray.write16bit(flags[i], data, i * 4 + 3);
  33. }
  34. set(data);
  35. }
  36. /**
  37. * Returns <code>parameters_count</code>, which is the number of
  38. * parameters.
  39. */
  40. public int size() {
  41. return info[0] & 0xff;
  42. }
  43. /**
  44. * Returns the value of <code>name_index</code> of the i-th element of <code>parameters</code>.
  45. *
  46. * @param i the position of the parameter.
  47. */
  48. public int name(int i) {
  49. return ByteArray.readU16bit(info, i * 4 + 1);
  50. }
  51. /**
  52. * Returns the value of <code>access_flags</code> of the i-th element of <code>parameters</code>.
  53. *
  54. * @param i the position of the parameter.
  55. * @see AccessFlag
  56. */
  57. public int accessFlags(int i) {
  58. return ByteArray.readU16bit(info, i * 4 + 3);
  59. }
  60. /**
  61. * Makes a copy.
  62. *
  63. * @param newCp the constant pool table used by the new copy.
  64. * @param classnames ignored.
  65. */
  66. @Override
  67. public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames) {
  68. int s = size();
  69. ConstPool cp = getConstPool();
  70. String[] names = new String[s];
  71. int[] flags = new int[s];
  72. for (int i = 0; i < s; i++) {
  73. names[i] = cp.getUtf8Info(name(i));
  74. flags[i] = accessFlags(i);
  75. }
  76. return new MethodParametersAttribute(newCp, names, flags);
  77. }
  78. }