KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jas > SourceAttr


1 /**
2  * This attribute is used to embed Source file information into
3  * a class file.
4  * @author $Author: fqian $
5  * @version $Revision: 1.1 $
6  */

7
8 package jas;
9
10 import java.io.*;
11
12 public class SourceAttr
13 {
14   static CP attr = new AsciiCP("SourceFile");
15
16   CP name;
17
18   /**
19    * Create a source file attribute.
20    * @param name Name of the source file
21    * @see ClassEnv#setSource
22    */

23
24   public SourceAttr(String JavaDoc name)
25   { this.name = new AsciiCP(name); }
26
27   /**
28    * Create a source file attribute, with more control over attribute name
29    * @param cp CP to be associated as the name of the source file
30    * @see ClassEnv#setSource
31    */

32   public SourceAttr(CP name)
33   { this.name = name; }
34
35   void resolve(ClassEnv e)
36   { e.addCPItem(attr); e.addCPItem(name); }
37
38   void write(ClassEnv e, DataOutputStream out)
39     throws IOException, jasError
40   {
41     out.writeShort(e.getCPIndex(attr));
42     out.writeInt(2);
43     out.writeShort(e.getCPIndex(name));
44   }
45 }
46
47
Popular Tags