KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jas > ConstAttr


1 /**
2  * This is typically used to represent a constant value for
3  * a field entry (as in static final int foo = 20).
4  *
5  * @author $Author: fqian $
6  * @version $Revision: 1.1 $
7  */

8
9 package jas;
10
11 import java.io.*;
12
13 public class ConstAttr
14 {
15   static CP attr = new AsciiCP("ConstantValue");
16   CP val;
17
18   /**
19    * Create a new constant attribute whose constant value
20    * is picked up from constant pool with the given entry.
21    * @param val Constant pool item whose value is associated
22    * with the constant value attribute
23    */

24
25   public ConstAttr(CP val)
26   { this.val = val; }
27
28   void resolve(ClassEnv e)
29   {
30     e.addCPItem(val);
31     e.addCPItem(attr);
32   }
33
34   void write(ClassEnv e, DataOutputStream out)
35     throws IOException, jasError
36   {
37     out.writeShort(e.getCPIndex(attr));
38     out.writeInt(2);
39     out.writeShort(e.getCPIndex(val));
40   }
41 }
42
43   
44
Popular Tags