View Javadoc

1   package serp.bytecode.lowlevel;
2   
3   import java.io.*;
4   
5   /***
6    * Base class for field, method, and interface method constant pool
7    * entries. All complex entries reference the {@link ClassEntry} of the
8    * class that owns the entity and a {@link NameAndTypeEntry} describing
9    * the entity.
10   *
11   * @author Abe White
12   */
13  public abstract class ComplexEntry extends Entry {
14      private int _classIndex = 0;
15      private int _nameAndTypeIndex = 0;
16  
17      /***
18       * Default constructor.
19       */
20      public ComplexEntry() {
21      }
22  
23      /***
24       * Constructor.
25       *
26       * @param classIndex the constant pool index of the
27       * {@link ClassEntry} describing the owner of this entity
28       * @param nameAndTypeIndex the constant pool index of the
29       * {@link NameAndTypeEntry} describing this entity
30       */
31      public ComplexEntry(int classIndex, int nameAndTypeIndex) {
32          _classIndex = classIndex;
33          _nameAndTypeIndex = nameAndTypeIndex;
34      }
35  
36      /***
37       * Return the constant pool index of the {@link ClassEntry} describing
38       * the owning class of this entity. Defaults to 0.
39       */
40      public int getClassIndex() {
41          return _classIndex;
42      }
43  
44      /***
45       * Set the constant pool index of the {@link ClassEntry} describing
46       * the owning class of this entity.
47       */
48      public void setClassIndex(int classIndex) {
49          Object key = beforeModify();
50          _classIndex = classIndex;
51          afterModify(key);
52      }
53  
54      /***
55       * Return the referenced {@link ClassEntry}. This method can only
56       * be run for entries that have been added to a constant pool.
57       */
58      public ClassEntry getClassEntry() {
59          return (ClassEntry) getPool().getEntry(_classIndex);
60      }
61  
62      /***
63       * Return the constant pool index of the {@link NameAndTypeEntry}
64       * describing this entity.
65       */
66      public int getNameAndTypeIndex() {
67          return _nameAndTypeIndex;
68      }
69  
70      /***
71       * Set the constant pool index of the {@link NameAndTypeEntry}
72       * describing this entity.
73       */
74      public void setNameAndTypeIndex(int nameAndTypeIndex) {
75          Object key = beforeModify();
76          _nameAndTypeIndex = nameAndTypeIndex;
77          afterModify(key);
78      }
79  
80      /***
81       * Return the referenced {@link NameAndTypeEntry}. This method can only
82       * be run for entries that have been added to a constant pool.
83       */
84      public NameAndTypeEntry getNameAndTypeEntry() {
85          return (NameAndTypeEntry) getPool().getEntry(_nameAndTypeIndex);
86      }
87  
88      void readData(DataInput in) throws IOException {
89          _classIndex = in.readUnsignedShort();
90          _nameAndTypeIndex = in.readUnsignedShort();
91      }
92  
93      void writeData(DataOutput out) throws IOException {
94          out.writeShort(_classIndex);
95          out.writeShort(_nameAndTypeIndex);
96      }
97  }