1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.jdo.impl.enhancer.classfile;
20
21 import java.io.*;
22
23 /***
24 * Represents the source file attribute in a class file
25 */
26 public class SourceFileAttribute extends ClassAttribute {
27
28 public static final String expectedAttrName = "SourceFile";
29
30
31 private ConstUtf8 sourceFileName;
32
33
34
35 /***
36 * Returns the source file name
37 * The file name should not include directories
38 */
39 public ConstUtf8 fileName() {
40 return sourceFileName;
41 }
42
43 /***
44 * Sets the source file name
45 */
46 public void setFileName(ConstUtf8 name) {
47 sourceFileName = name;
48 }
49
50 /***
51 * Constructor for a source file attribute
52 */
53 public SourceFileAttribute(ConstUtf8 attrName, ConstUtf8 sourceName) {
54 super(attrName);
55 sourceFileName = sourceName;
56 }
57
58 /* package local methods *//package-summary/html">class="comment"> package local methods *//package-summary.html">
59 static SourceFileAttribute read(ConstUtf8 attrName,
60 DataInputStream data, ConstantPool pool)
61 throws IOException {
62 int index = 0;
63 index = data.readUnsignedShort();
64
65 return new SourceFileAttribute(attrName,
66 (ConstUtf8) pool.constantAt(index));
67 }
68
69 void write(DataOutputStream out) throws IOException {
70 out.writeShort(attrName().getIndex());
71 out.writeInt(2);
72 out.writeShort(sourceFileName.getIndex());
73 }
74
75 void print(PrintStream out, int indent) {
76 ClassPrint.spaces(out, indent);
77 out.println("SourceFile: " + sourceFileName.asString());
78 }
79 }