View Javadoc

1   package serp.bytecode.lowlevel;
2   
3   import java.io.*;
4   
5   import serp.bytecode.visitor.*;
6   
7   /***
8    * A constant pool entry describing a class.
9    * Class entries are used to refer to the current class, the superclass,
10   * implemented interfaces, etc. Each class entry contains the constant pool
11   * index of the {@link UTF8Entry} that stores the class name, which is
12   * represented in internal form.
13   *
14   * @author Abe White
15   */
16  public class ClassEntry extends Entry implements ConstantEntry {
17      private int _nameIndex = 0;
18  
19      /***
20       * Default constructor.
21       */
22      public ClassEntry() {
23      }
24  
25      /***
26       * Constructor.
27       *
28       * @param nameIndex the constant pool index of the {@link UTF8Entry}
29       * containing the class name
30       */
31      public ClassEntry(int nameIndex) {
32          _nameIndex = nameIndex;
33      }
34  
35      /***
36       * Return the constant pool index of the {@link UTF8Entry}
37       * containing the class name. Defaults to 0.
38       */
39      public int getNameIndex() {
40          return _nameIndex;
41      }
42  
43      /***
44       * Set the constant pool index of the {@link UTF8Entry}
45       * containing the class name.
46       */
47      public void setNameIndex(int nameIndex) {
48          Object key = beforeModify();
49          _nameIndex = nameIndex;
50          afterModify(key);
51      }
52  
53      /***
54       * Return the referenced {@link UTF8Entry}. This method can only
55       * be run for entries that have been added to a constant pool.
56       */
57      public UTF8Entry getNameEntry() {
58          return (UTF8Entry) getPool().getEntry(_nameIndex);
59      }
60  
61      public int getType() {
62          return Entry.CLASS;
63      }
64  
65      public Object getConstant() {
66          return getNameEntry().getValue();
67      }
68  
69      public void setConstant(Object value) {
70          getNameEntry().setConstant(value);
71      }
72  
73      public void acceptVisit(BCVisitor visit) {
74          visit.enterClassEntry(this);
75          visit.exitClassEntry(this);
76      }
77  
78      void readData(DataInput in) throws IOException {
79          _nameIndex = in.readUnsignedShort();
80      }
81  
82      void writeData(DataOutput out) throws IOException {
83          out.writeShort(_nameIndex);
84      }
85  }