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 */
018 package org.apache.bcel.generic;
019
020 import org.apache.bcel.Constants;
021 import org.apache.bcel.ExceptionConstants;
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 1152072 2011-07-29 01:54:05Z dbrosius $
030 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
031 */
032 public class GETFIELD extends FieldInstruction implements ExceptionThrower, StackConsumer,
033 StackProducer {
034
035 private static final long serialVersionUID = -6510928743515082496L;
036
037
038 /**
039 * Empty constructor needed for the Class.newInstance() statement in
040 * Instruction.readInstruction(). Not to be used otherwise.
041 */
042 GETFIELD() {
043 }
044
045
046 public GETFIELD(int index) {
047 super(Constants.GETFIELD, index);
048 }
049
050
051 @Override
052 public int produceStack( ConstantPoolGen cpg ) {
053 return getFieldSize(cpg);
054 }
055
056
057 public Class<?>[] getExceptions() {
058 Class<?>[] cs = new Class[2 + ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length];
059 System.arraycopy(ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION, 0, cs, 0,
060 ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length);
061 cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length + 1] = ExceptionConstants.INCOMPATIBLE_CLASS_CHANGE_ERROR;
062 cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length] = ExceptionConstants.NULL_POINTER_EXCEPTION;
063 return cs;
064 }
065
066
067 /**
068 * Call corresponding visitor method(s). The order is:
069 * Call visitor methods of implemented interfaces first, then
070 * call methods according to the class hierarchy in descending order,
071 * i.e., the most specific visitXXX() call comes last.
072 *
073 * @param v Visitor object
074 */
075 @Override
076 public void accept( Visitor v ) {
077 v.visitExceptionThrower(this);
078 v.visitStackConsumer(this);
079 v.visitStackProducer(this);
080 v.visitTypedInstruction(this);
081 v.visitLoadClass(this);
082 v.visitCPInstruction(this);
083 v.visitFieldOrMethod(this);
084 v.visitFieldInstruction(this);
085 v.visitGETFIELD(this);
086 }
087 }