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  */
  30 public abstract class FieldInstruction extends FieldOrMethod {
  31 
  32     /**
  33      * Empty constructor needed for Instruction.readInstruction.
  34      * Not to be used otherwise.
  35      */
  36     FieldInstruction() {
  37     }
  38 
  39 
  40     /**
  41      * @param index to constant pool
  42      */
  43     protected FieldInstruction(final short opcode, final int index) {
  44         super(opcode, index);
  45     }
  46 
  47 
  48     /**
  49      * @return mnemonic for instruction with symbolic references resolved
  50      */
  51     @Override
  52     public String toString( final ConstantPool cp ) {
  53         return com.sun.org.apache.bcel.internal.Const.getOpcodeName(super.getOpcode()) + " "
  54                 + cp.constantToString(super.getIndex(), com.sun.org.apache.bcel.internal.Const.CONSTANT_Fieldref);
  55     }
  56 
  57 
  58     /** @return size of field (1 or 2)
  59      */
  60     protected int getFieldSize( final ConstantPoolGen cpg ) {
  61         return Type.size(Type.getTypeSize(getSignature(cpg)));
  62     }
  63 
  64 
  65     /** @return return type of referenced field
  66      */
  67     @Override
  68     public Type getType( final ConstantPoolGen cpg ) {
  69         return getFieldType(cpg);
  70     }
  71 
  72 
  73     /** @return type of field
  74      */
  75     public Type getFieldType( final ConstantPoolGen cpg ) {
  76         return Type.getType(getSignature(cpg));
  77     }
  78 
  79 
  80     /** @return name of referenced field.
  81      */
  82     public String getFieldName( final ConstantPoolGen cpg ) {
  83         return getName(cpg);
  84     }
  85 }