KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jas > FieldCP


1 /**
2  * FieldCP's are used to refer to a field in a particular
3  * class.
4  *
5  * @author $Author: fqian $
6  * @version $Revision: 1.1 $
7  */

8
9 package jas;
10
11 import java.io.*;
12
13
14 public class FieldCP extends CP implements RuntimeConstants
15 {
16   ClassCP clazz;
17   NameTypeCP nt;
18
19   /**
20    * FieldCP's are created by specifying the class to which the
21    * field belongs, the name of the symbol, and its signature.
22    * For instance, to refer to the field <tt>out</tt> in
23    * <tt>System.out</tt> use
24    * <tt> new FieldCP("java/lang/System", "out", "Ljava/io/PrintStream;")</tt>
25    *
26    * @param clazz Name of class
27    * @param name Name of symbol
28    * @param sig Signature for symbol
29    */

30
31   public FieldCP(String JavaDoc clazz, String JavaDoc name, String JavaDoc sig)
32   {
33     uniq = (clazz + "&%$#&" + name + "*()#$" + sig).intern();
34     this.clazz = new ClassCP(clazz);
35     this.nt = new NameTypeCP(name, sig);
36   }
37
38   void resolve(ClassEnv e)
39   {
40     e.addCPItem(clazz);
41     e.addCPItem(nt);
42   }
43
44   void write(ClassEnv e, DataOutputStream out)
45     throws IOException, jasError
46   {
47     out.writeByte(CONSTANT_FIELD);
48     out.writeShort(e.getCPIndex(clazz));
49     out.writeShort(e.getCPIndex(nt));
50   }
51 }
52
Popular Tags