Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

MethodParametersAttribute.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 name of the i-th element of <code>parameters</code>.
  53. * @param i the position of the parameter.
  54. */
  55. public String parameterName(int i) {
  56. return getConstPool().getUtf8Info(name(i));
  57. }
  58. /**
  59. * Returns the value of <code>access_flags</code> of the i-th element of <code>parameters</code>.
  60. *
  61. * @param i the position of the parameter.
  62. * @see AccessFlag
  63. */
  64. public int accessFlags(int i) {
  65. return ByteArray.readU16bit(info, i * 4 + 3);
  66. }
  67. /**
  68. * Makes a copy.
  69. *
  70. * @param newCp the constant pool table used by the new copy.
  71. * @param classnames ignored.
  72. */
  73. @Override
  74. public AttributeInfo copy(ConstPool newCp, Map<String,String> classnames) {
  75. int s = size();
  76. ConstPool cp = getConstPool();
  77. String[] names = new String[s];
  78. int[] flags = new int[s];
  79. for (int i = 0; i < s; i++) {
  80. names[i] = cp.getUtf8Info(name(i));
  81. flags[i] = accessFlags(i);
  82. }
  83. return new MethodParametersAttribute(newCp, names, flags);
  84. }
  85. }