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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. public class NestMembersAttribute extends AttributeInfo {
  25. /**
  26. * The name of this attribute <code>"NestMembers"</code>.
  27. */
  28. public static final String tag = "NestMembers";
  29. NestMembersAttribute(ConstPool cp, int n, DataInputStream in) throws IOException {
  30. super(cp, n, in);
  31. }
  32. private NestMembersAttribute(ConstPool cp, byte[] info) {
  33. super(cp, tag, info);
  34. }
  35. /**
  36. * Makes a copy. Class names are replaced according to the
  37. * given <code>Map</code> object.
  38. *
  39. * @param newCp the constant pool table used by the new copy.
  40. * @param classnames pairs of replaced and substituted
  41. * class names.
  42. */
  43. @Override
  44. public AttributeInfo copy(ConstPool newCp, Map<String, String> classnames) {
  45. byte[] src = get();
  46. byte[] dest = new byte[src.length];
  47. ConstPool cp = getConstPool();
  48. int n = ByteArray.readU16bit(src, 0);
  49. ByteArray.write16bit(n, dest, 0);
  50. for (int i = 0, j = 2; i < n; ++i, j += 2) {
  51. int index = ByteArray.readU16bit(src, j);
  52. int newIndex = cp.copy(index, newCp, classnames);
  53. ByteArray.write16bit(newIndex, dest, j);
  54. }
  55. return new NestMembersAttribute(newCp, dest);
  56. }
  57. /**
  58. * Returns <code>number_of_classes</code>.
  59. * @return the number of the classes recorded in this attribute.
  60. */
  61. public int numberOfClasses() {
  62. return ByteArray.readU16bit(info, 0);
  63. }
  64. /** Returns <code>classes[index]</code>.
  65. *
  66. * @param index the index into <code>classes</code>.
  67. * @return the value at the given index in the <code>classes</code> array.
  68. * It is an index into the constant pool.
  69. * The constant pool entry at the returned index is a
  70. * <code>CONSTANT_Class_info</code> structure.
  71. */
  72. public int memberClass(int index) {
  73. return ByteArray.readU16bit(info, index * 2 + 2);
  74. }
  75. }