1 /*
   2  * reserved comment block
   3  * DO NOT REMOVE OR ALTER!
   4  */
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *      http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 package com.sun.org.apache.bcel.internal.generic;
  23 
  24 import com.sun.org.apache.bcel.internal.classfile.ConstantPool;
  25 
  26 /**
  27  * Super class for the GET/PUTxxx family of instructions.
  28  *
  29  * @version $Id$
  30  */
  31 public abstract class FieldInstruction extends FieldOrMethod {
  32 
  33     /**
  34      * Empty constructor needed for Instruction.readInstruction.
  35      * Not to be used otherwise.
  36      */
  37     FieldInstruction() {
  38     }
  39 
  40 
  41     /**
  42      * @param index to constant pool
  43      */
  44     protected FieldInstruction(final short opcode, final int index) {
  45         super(opcode, index);
  46     }
  47 
  48 
  49     /**
  50      * @return mnemonic for instruction with symbolic references resolved
  51      */
  52     @Override
  53     public String toString( final ConstantPool cp ) {
  54         return com.sun.org.apache.bcel.internal.Const.getOpcodeName(super.getOpcode()) + " "
  55                 + cp.constantToString(super.getIndex(), com.sun.org.apache.bcel.internal.Const.CONSTANT_Fieldref);
  56     }
  57 
  58 
  59     /** @return size of field (1 or 2)
  60      */
  61     protected int getFieldSize( final ConstantPoolGen cpg ) {
  62         return Type.size(Type.getTypeSize(getSignature(cpg)));
  63     }
  64 
  65 
  66     /** @return return type of referenced field
  67      */
  68     @Override
  69     public Type getType( final ConstantPoolGen cpg ) {
  70         return getFieldType(cpg);
  71     }
  72 
  73 
  74     /** @return type of field
  75      */
  76     public Type getFieldType( final ConstantPoolGen cpg ) {
  77         return Type.getType(getSignature(cpg));
  78     }
  79 
  80 
  81     /** @return name of referenced field.
  82      */
  83     public String getFieldName( final ConstantPoolGen cpg ) {
  84         return getName(cpg);
  85     }
  86 }