1 | public class FieldRefCPInfo extends ConstantPoolEntry {↵ | | 1 | public class MethodRefCPInfo extends ConstantPoolEntry {↵
|
2 | /** Name of the field's class */↵ | | 2 | /** the name of the class defining this method */↵
|
3 | private String fieldClassName;↵ | | 3 | private String methodClassName;↵
|
4 | /** name of the field in that class */↵ | | 4 | /** the name of the method */↵
|
5 | private String fieldName;↵ | | 5 | private String methodName;↵
|
6 | /** The type of the field */↵ | | 6 | /** the method's type descriptor */↵
|
7 | private String fieldType;↵ | | 7 | private String methodType;↵
|
8 | /** Index into the constant pool for the class */↵ | | 8 | /** The index into the constant pool which defines the class of this method. */↵
|
9 | private int classIndex;↵ | | 9 | private int classIndex;↵
|
10 | /** I↵ | | 10 | /**↵
|
11 | ndex into the constant pool for the name and type entry↵ | | 11 | * the index into the constant pool which defined the name and type↵
|
| | | 12 | * signature of the method↵
|
12 | */↵ | | 13 | */↵
|
13 | private int nameAndTypeIndex;↵ | | 14 | private int nameAndTypeIndex;↵
|
|
14 | /** Constructor. */↵ | | 15 | /** Constructor. */↵
|
15 | public FieldRefCPInfo() {↵ | | 16 | public MethodRefCPInfo() {↵
|
16 | super(CONSTANT_FIELDREF, 1);↵ | | 17 | super(CONSTANT_METHODREF, 1);↵
|
17 | }↵ | | 18 | }↵
|
|
18 | /**↵ | | 19 | /**↵
|
19 | * read a constant pool entry from a class stream.↵ | | 20 | * read a constant pool entry from a class stream.↵
|
20 | *↵ | | 21 | *↵
|
21 | * @param cpStream the DataInputStream which contains the constant pool↵ | | 22 | * @param cpStream the DataInputStream which contains the constant pool↵
|
22 | * entry to be read.↵ | | 23 | * entry to be read.↵
|
23 | * @exception IOException if there is a problem reading the entry from↵ | | 24 | * @exception IOException if there is a problem reading the entry from↵
|
24 | * the stream.↵ | | 25 | * the stream.↵
|
25 | */↵ | | 26 | */↵
|
26 | public void read(DataInputStream cpStream) throws IOException {↵ | | 27 | public void read(DataInputStream cpStream) throws IOException {↵
|
27 | classIndex = cpStream.readUnsignedShort();↵ | | 28 | classIndex = cpStream.readUnsignedShort();↵
|
28 | nameAndTypeIndex = cpStream.readUnsignedShort();↵ | | 29 | nameAndTypeIndex = cpStream.readUnsignedShort();↵
|
29 | }↵ | | 30 | }↵
|
|
| | | 31 | /**↵
|
| | | 32 | * Print a readable version of the constant pool entry.↵
|
| | | 33 | *↵
|
| | | 34 | * @return the string representation of this constant pool entry.↵
|
| | | 35 | */↵
|
| | | 36 | public String toString() {↵
|
| | | 37 | String value;↵
|
|
| | | 38 | if (isResolved()) {↵
|
| | | 39 | value = "Method : Class = " + methodClassName + ", name = "↵
|
| | | 40 | + methodName + ", type = " + methodType;↵
|
| | | 41 | } else {↵
|
| | | 42 | value = "Method : Class index = " + classIndex↵
|
| | | 43 | + ", name and type index = " + nameAndTypeIndex;↵
|
| | | 44 | }↵
|
|
| | | 45 | return value;↵
|
| | | 46 | }↵
|
|
30 | /**↵ | | 47 | /**↵
|
31 | * Resolve this constant pool entry with respect to its dependents in↵ | | 48 | * Resolve this constant pool entry with respect to its dependents in↵
|
32 | * the constant pool.↵ | | 49 | * the constant pool.↵
|
33 | *↵ | | 50 | *↵
|
34 | * @param constantPool the constant pool of which this entry is a member↵ | | 51 | * @param constantPool the constant pool of which this entry is a member↵
|
35 | * and against which this entry is to be resolved.↵ | | 52 | * and against which this entry is to be resolved.↵
|
36 | */↵ | | 53 | */↵
|
37 | public void resolve(ConstantPool constantPool) {↵ | | 54 | public void resolve(ConstantPool constantPool) {↵
|
38 | ClassCPInfo fieldClass↵ | | 55 | ClassCPInfo methodClass↵
|
39 | = (ClassCPInfo) constantPool.getEntry(classIndex);↵ | | 56 | = (ClassCPInfo) constantPool.getEntry(classIndex);↵
|
|
40 | fieldClass.resolve(constantPool);↵ | | 57 | methodClass.resolve(constantPool);↵
|
|
41 | fieldClassName = fieldClass.getClassName();↵ | | 58 | methodClassName = methodClass.getClassName();↵
|
|
42 | NameAndTypeCPInfo nt↵ | | 59 | NameAndTypeCPInfo nt↵
|
43 | = (NameAndTypeCPInfo) constantPool.getEntry(nameAndTypeIndex);↵ | | 60 | = (NameAndTypeCPInfo) constantPool.getEntry(nameAndTypeIndex);↵
|
|
44 | nt.resolve(constantPool);↵ | | 61 | nt.resolve(constantPool);↵
|
|
45 | fieldName = nt.getName();↵ | | 62 | methodName = nt.getName();↵
|
46 | fieldType = nt.getType();↵ | | 63 | methodType = nt.getType();↵
|
|
47 | super.resolve(constantPool);↵ | | 64 | super.resolve(constantPool);↵
|
48 | }↵ | | 65 | }↵
|
|
49 | /**↵ | | |
|
50 | * Print a readable version of the constant pool entry.↵ | | |
|
51 | *↵ | | |
|
52 | * @return the string representation of this constant pool entry.↵ | | |
|
53 | */↵ | | |
|
54 | public String toString() {↵ | | |
|
55 | String value;↵ | | |
|
|
56 | if (isResolved()) {↵ | | |
|
57 | value = "Field : Class = " + fieldClassName + ", name = "↵ | | |
|
58 | + fieldName + ", type = " + fieldType;↵ | | |
|
59 | } else {↵ | | |
|
60 | value = "Field : Class index = " + classIndex↵ | | |
|
61 | + ", name and type index = " + nameAndTypeIndex;↵ | | |
|
62 | }↵ | | |
|
|
63 | return value;↵ | | |
|
64 | }↵ | | |
|
|
65 | /**↵ | | 66 | /**↵
|
66 | * Gets the name of the class defining the field↵ | | 67 | * Get the name of the class defining the method↵
|
67 | *↵ | | 68 | *↵
|
68 | * @return the name of the class defining the field↵ | | 69 | * @return the name of the class defining this method↵
|
69 | */↵ | | 70 | */↵
|
70 | public String getFieldClassName() {↵ | | 71 | public String getMethodClassName() {↵
|
71 | return fieldClassName;↵ | | 72 | return methodClassName;↵
|
72 | }↵ | | 73 | }↵
|
|
73 | /**↵ | | 74 | /**↵
|
74 | * Get the name of the field↵ | | 75 | * Get the name of the method.↵
|
75 | *↵ | | 76 | *↵
|
76 | * @return the field's name↵ | | 77 | * @return the name of the method.↵
|
77 | */↵ | | 78 | */↵
|
78 | public String getFieldName() {↵ | | 79 | public String getMethodName() {↵
|
79 | return fieldName;↵ | | 80 | return methodName;↵
|
80 | }↵ | | 81 | }↵
|
|
81 | /**↵ | | 82 | /**↵
|
82 | * Get the type of the field↵ | | 83 | * Get the type signature of the method.↵
|
83 | *↵ | | 84 | *↵
|
84 | * @return the field's type in string format↵ | | 85 | * @return the type signature of the method.↵
|
85 | */↵ | | 86 | */↵
|
86 | public String getFieldType() {↵ | | 87 | public String getMethodType() {↵
|
87 | return fieldType;↵ | | 88 | return methodType;↵
|
88 | | | 89 |
|