    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 *  Unless required by applicable law or agreed to in writing, software
    012 *  distributed under the License is distributed on an "AS IS" BASIS,
    013 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 *  See the License for the specific language governing permissions and
    015 *  limitations under the License.
    016 *
    017 */
    018package org.apache.bcel.generic;
    019
    020import org.apache.bcel.classfile.ConstantPool;
    021
    022/**
    023 * Super class for the GET/PUTxxx family of instructions.
    024 *
    025 * @version $Id$
    026 */
    027public abstract class FieldInstruction extends FieldOrMethod {
    028
    029    /**
    030     * Empty constructor needed for Instruction.readInstruction.
    031     * Not to be used otherwise.
    032     */
    033    FieldInstruction() {
    034    }
    035
    036
    037    /**
    038     * @param index to constant pool
    039     */
    040    protected FieldInstruction(final short opcode, final int index) {
    041        super(opcode, index);
    042    }
    043
    044
    045    /**
    046     * @return mnemonic for instruction with symbolic references resolved
    047     */
    048    @Override
    049    public String toString( final ConstantPool cp ) {
    050        return org.apache.bcel.Const.getOpcodeName(super.getOpcode()) + " "
    051                + cp.constantToString(super.getIndex(), org.apache.bcel.Const.CONSTANT_Fieldref);
    052    }
    053
    054
    055    /** @return size of field (1 or 2)
    056     */
    057    protected int getFieldSize( final ConstantPoolGen cpg ) {
    058        return Type.size(Type.getTypeSize(getSignature(cpg)));
    059    }
    060
    061
    062    /** @return return type of referenced field
    063     */
    064    @Override
    065    public Type getType( final ConstantPoolGen cpg ) {
    066        return getFieldType(cpg);
    067    }
    068
    069
    070    /** @return type of field
    071     */
    072    public Type getFieldType( final ConstantPoolGen cpg ) {
    073        return Type.getType(getSignature(cpg));
    074    }
    075
    076
    077    /** @return name of referenced field.
    078     */
    079    public String getFieldName( final ConstantPoolGen cpg ) {
    080        return getName(cpg);
    081    }
    082}