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