View Javadoc

1   /*
2    * Copyright  2000-2004 The Apache Software Foundation
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License"); 
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License. 
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  }