    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 */
    026public abstract class FieldInstruction extends FieldOrMethod {
    027
    028    /**
    029     * Empty constructor needed for Instruction.readInstruction. Not to be used otherwise.
    030     */
    031    FieldInstruction() {
    032    }
    033
    034    /**
    035     * @param index to constant pool
    036     */
    037    protected FieldInstruction(final short opcode, final int index) {
    038        super(opcode, index);
    039    }
    040
    041    /**
    042     * @return name of referenced field.
    043     */
    044    public String getFieldName(final ConstantPoolGen cpg) {
    045        return getName(cpg);
    046    }
    047
    048    /**
    049     * @return size of field (1 or 2)
    050     */
    051    protected int getFieldSize(final ConstantPoolGen cpg) {
    052        return Type.size(Type.getTypeSize(getSignature(cpg)));
    053    }
    054
    055    /**
    056     * @return type of field
    057     */
    058    public Type getFieldType(final ConstantPoolGen cpg) {
    059        return Type.getType(getSignature(cpg));
    060    }
    061
    062    /**
    063     * @return return type of referenced field
    064     */
    065    @Override
    066    public Type getType(final ConstantPoolGen cpg) {
    067        return getFieldType(cpg);
    068    }
    069
    070    /**
    071     * @return mnemonic for instruction with symbolic references resolved
    072     */
    073    @Override
    074    public String toString(final ConstantPool cp) {
    075        return org.apache.bcel.Const.getOpcodeName(super.getOpcode()) + " " + cp.constantToString(super.getIndex(), org.apache.bcel.Const.CONSTANT_Fieldref);
    076    }
    077}