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.

ConstantAttribute.java 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Javassist, a Java-bytecode translator toolkit.
  3. * Copyright (C) 1999-2003 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. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. */
  15. package javassist.bytecode;
  16. import java.io.DataInputStream;
  17. import java.util.Map;
  18. import java.io.IOException;
  19. /**
  20. * <code>ConstantValue_attribute</code>.
  21. */
  22. public class ConstantAttribute extends AttributeInfo {
  23. /**
  24. * The name of this attribute <code>"ConstantValue"</code>.
  25. */
  26. public static final String tag = "ConstantValue";
  27. ConstantAttribute(ConstPool cp, int n, DataInputStream in)
  28. throws IOException
  29. {
  30. super(cp, n, in);
  31. }
  32. /**
  33. * Constructs a ConstantValue attribute.
  34. *
  35. * @param cp a constant pool table.
  36. * @param index <code>constantvalue_index</code>
  37. * of <code>ConstantValue_attribute</code>.
  38. */
  39. public ConstantAttribute(ConstPool cp, int index) {
  40. super(cp, tag);
  41. byte[] bvalue = new byte[2];
  42. bvalue[0] = (byte)(index >>> 8);
  43. bvalue[1] = (byte)index;
  44. set(bvalue);
  45. }
  46. /**
  47. * Returns <code>constantvalue_index</code>.
  48. */
  49. public int getConstantValue() {
  50. return ByteArray.readU16bit(get(), 0);
  51. }
  52. /**
  53. * Makes a copy. Class names are replaced according to the
  54. * given <code>Map</code> object.
  55. *
  56. * @param newCp the constant pool table used by the new copy.
  57. * @param classnames pairs of replaced and substituted
  58. * class names.
  59. */
  60. public AttributeInfo copy(ConstPool newCp, Map classnames) {
  61. int index = getConstPool().copy(getConstantValue(), newCp,
  62. classnames);
  63. return new ConstantAttribute(newCp, index);
  64. }
  65. }