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