1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.bcel.generic;
18
19 import org.apache.bcel.classfile.ConstantPool;
20
21 /***
22 * Super class for the GET/PUTxxx family of instructions.
23 *
24 * @version $Id: FieldInstruction.java 386056 2006-03-15 11:31:56Z tcurdt $
25 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
26 */
27 public abstract class FieldInstruction extends FieldOrMethod implements TypedInstruction {
28
29 /***
30 * Empty constructor needed for the Class.newInstance() statement in
31 * Instruction.readInstruction(). Not to be used otherwise.
32 */
33 FieldInstruction() {
34 }
35
36
37 /***
38 * @param index to constant pool
39 */
40 protected FieldInstruction(short opcode, int index) {
41 super(opcode, index);
42 }
43
44
45 /***
46 * @return mnemonic for instruction with symbolic references resolved
47 */
48 public String toString( ConstantPool cp ) {
49 return org.apache.bcel.Constants.OPCODE_NAMES[opcode] + " "
50 + cp.constantToString(index, org.apache.bcel.Constants.CONSTANT_Fieldref);
51 }
52
53
54 /*** @return size of field (1 or 2)
55 */
56 protected int getFieldSize( ConstantPoolGen cpg ) {
57 return getType(cpg).getSize();
58 }
59
60
61 /*** @return return type of referenced field
62 */
63 public Type getType( ConstantPoolGen cpg ) {
64 return getFieldType(cpg);
65 }
66
67
68 /*** @return type of field
69 */
70 public Type getFieldType( ConstantPoolGen cpg ) {
71 return Type.getType(getSignature(cpg));
72 }
73
74
75 /*** @return name of referenced field.
76 */
77 public String getFieldName( ConstantPoolGen cpg ) {
78 return getName(cpg);
79 }
80 }