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.

SourceFileAttribute.java 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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.io.IOException;
  18. import java.util.Map;
  19. /**
  20. * <code>SourceFile_attribute</code>.
  21. */
  22. public class SourceFileAttribute extends AttributeInfo {
  23. /**
  24. * The name of this attribute <code>"SourceFile"</code>.
  25. */
  26. public static final String tag = "SourceFile";
  27. SourceFileAttribute(ConstPool cp, int n, DataInputStream in)
  28. throws IOException
  29. {
  30. super(cp, n, in);
  31. }
  32. /**
  33. * Constructs a SourceFile attribute.
  34. *
  35. * @param cp a constant pool table.
  36. * @param filename the name of the source file.
  37. */
  38. public SourceFileAttribute(ConstPool cp, String filename) {
  39. super(cp, tag);
  40. int index = cp.addUtf8Info(filename);
  41. byte[] bvalue = new byte[2];
  42. bvalue[0] = (byte)(index >>> 8);
  43. bvalue[1] = (byte)index;
  44. set(bvalue);
  45. }
  46. /**
  47. * Returns the file name indicated by <code>sourcefile_index</code>.
  48. */
  49. public String getFileName() {
  50. return getConstPool().getUtf8Info(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. return new SourceFileAttribute(newCp, getFileName());
  62. }
  63. }