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.Const; 021import org.apache.bcel.ExceptionConst; 022 023/** 024 * GETFIELD - Fetch field from object 025 * <PRE>Stack: ..., objectref -> ..., value</PRE> 026 * OR 027 * <PRE>Stack: ..., objectref -> ..., value.word1, value.word2</PRE> 028 * 029 * @version $Id: GETFIELD.java 1812166 2017-10-13 23:48:11Z ggregory $ 030 */ 031public class GETFIELD extends FieldInstruction implements ExceptionThrower, StackConsumer, 032 StackProducer { 033 034 /** 035 * Empty constructor needed for Instruction.readInstruction. 036 * Not to be used otherwise. 037 */ 038 GETFIELD() { 039 } 040 041 042 public GETFIELD(final int index) { 043 super(Const.GETFIELD, index); 044 } 045 046 047 @Override 048 public int produceStack( final ConstantPoolGen cpg ) { 049 return getFieldSize(cpg); 050 } 051 052 053 @Override 054 public Class<?>[] getExceptions() { 055 return ExceptionConst.createExceptions(ExceptionConst.EXCS.EXCS_FIELD_AND_METHOD_RESOLUTION, 056 ExceptionConst.NULL_POINTER_EXCEPTION, 057 ExceptionConst.INCOMPATIBLE_CLASS_CHANGE_ERROR); 058 } 059 060 061 /** 062 * Call corresponding visitor method(s). The order is: 063 * Call visitor methods of implemented interfaces first, then 064 * call methods according to the class hierarchy in descending order, 065 * i.e., the most specific visitXXX() call comes last. 066 * 067 * @param v Visitor object 068 */ 069 @Override 070 public void accept( final Visitor v ) { 071 v.visitExceptionThrower(this); 072 v.visitStackConsumer(this); 073 v.visitStackProducer(this); 074 v.visitTypedInstruction(this); 075 v.visitLoadClass(this); 076 v.visitCPInstruction(this); 077 v.visitFieldOrMethod(this); 078 v.visitFieldInstruction(this); 079 v.visitGETFIELD(this); 080 } 081}