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.

NestMembersAttribute.java 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Javassist, a Java-bytecode translator toolkit.
  3. * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved.
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. Alternatively, the contents of this file may be used under
  8. * the terms of the GNU Lesser General Public License Version 2.1 or later,
  9. * or the Apache License Version 2.0.
  10. *
  11. * Software distributed under the License is distributed on an "AS IS" basis,
  12. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13. * for the specific language governing rights and limitations under the
  14. * License.
  15. */
  16. package javassist.bytecode;
  17. import java.io.DataInputStream;
  18. import java.io.IOException;
  19. import java.util.Map;
  20. /**
  21. * <code>NestMembers_attribute</code>.
  22. * It was introduced by JEP-181. See JVMS 4.7.29 for the specification.
  23. *
  24. * @since 3.24
  25. */
  26. public class NestMembersAttribute extends AttributeInfo {
  27. /**
  28. * The name of this attribute <code>"NestMembers"</code>.
  29. */
  30. public static final String tag = "NestMembers";
  31. NestMembersAttribute(ConstPool cp, int n, DataInputStream in) throws IOException {
  32. super(cp, n, in);
  33. }
  34. private NestMembersAttribute(ConstPool cp, byte[] info) {
  35. super(cp, tag, info);
  36. }
  37. /**
  38. * Makes a copy. Class names are replaced according to the
  39. * given <code>Map</code> object.
  40. *
  41. * @param newCp the constant pool table used by the new copy.
  42. * @param classnames pairs of replaced and substituted
  43. * class names.
  44. */
  45. @Override
  46. public AttributeInfo copy(ConstPool newCp, Map<String, String> classnames) {
  47. byte[] src = get();
  48. byte[] dest = new byte[src.length];
  49. ConstPool cp = getConstPool();
  50. int n = ByteArray.readU16bit(src, 0);
  51. ByteArray.write16bit(n, dest, 0);
  52. for (int i = 0, j = 2; i < n; ++i, j += 2) {
  53. int index = ByteArray.readU16bit(src, j);
  54. int newIndex = cp.copy(index, newCp, classnames);
  55. ByteArray.write16bit(newIndex, dest, j);
  56. }
  57. return new NestMembersAttribute(newCp, dest);
  58. }
  59. /**
  60. * Returns <code>number_of_classes</code>.
  61. * @return the number of the classes recorded in this attribute.
  62. */
  63. public int numberOfClasses() {
  64. return ByteArray.readU16bit(info, 0);
  65. }
  66. /** Returns <code>classes[index]</code>.
  67. *
  68. * @param index the index into <code>classes</code>.
  69. * @return the value at the given index in the <code>classes</code> array.
  70. * It is an index into the constant pool.
  71. * The constant pool entry at the returned index is a
  72. * <code>CONSTANT_Class_info</code> structure.
  73. */
  74. public int memberClass(int index) {
  75. return ByteArray.readU16bit(info, index * 2 + 2);
  76. }
  77. }