1/*
2 * reserved comment block
3 * DO NOT REMOVE OR ALTER!
4 */
5/*
6 * Licensed to the Apache Software Foundation (ASF) under one or more
7 * contributor license agreements.  See the NOTICE file distributed with
8 * this work for additional information regarding copyright ownership.
9 * The ASF licenses this file to You under the Apache License, Version 2.0
10 * (the "License"); you may not use this file except in compliance with
11 * the License.  You may obtain a copy of the License at
12 *
13 *      http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21package com.sun.org.apache.bcel.internal.generic;
22
23import com.sun.org.apache.bcel.internal.Const;
24import com.sun.org.apache.bcel.internal.ExceptionConst;
25
26/**
27 * GETFIELD - Fetch field from object
28 * <PRE>Stack: ..., objectref -&gt; ..., value</PRE> OR
29 * <PRE>Stack: ..., objectref -&gt; ..., value.word1, value.word2</PRE>
30 *
31 * @version $Id: GETFIELD.java 1747278 2016-06-07 17:28:43Z britter $
32 */
33public class GETFIELD extends FieldInstruction implements ExceptionThrower, StackConsumer,
34        StackProducer {
35
36    /**
37     * Empty constructor needed for the Class.newInstance() statement in
38     * Instruction.readInstruction(). Not to be used otherwise.
39     */
40    GETFIELD() {
41    }
42
43    public GETFIELD(final int index) {
44        super(Const.GETFIELD, index);
45    }
46
47    @Override
48    public int produceStack(final ConstantPoolGen cpg) {
49        return getFieldSize(cpg);
50    }
51
52    @Override
53    public Class<?>[] getExceptions() {
54        return ExceptionConst.createExceptions(ExceptionConst.EXCS.EXCS_FIELD_AND_METHOD_RESOLUTION,
55                ExceptionConst.NULL_POINTER_EXCEPTION,
56                ExceptionConst.INCOMPATIBLE_CLASS_CHANGE_ERROR);
57    }
58
59    /**
60     * Call corresponding visitor method(s). The order is: Call visitor methods
61     * of implemented interfaces first, then call methods according to the class
62     * hierarchy in descending order, i.e., the most specific visitXXX() call
63     * comes last.
64     *
65     * @param v Visitor object
66     */
67    @Override
68    public void accept(final Visitor v) {
69        v.visitExceptionThrower(this);
70        v.visitStackConsumer(this);
71        v.visitStackProducer(this);
72        v.visitTypedInstruction(this);
73        v.visitLoadClass(this);
74        v.visitCPInstruction(this);
75        v.visitFieldOrMethod(this);
76        v.visitFieldInstruction(this);
77        v.visitGETFIELD(this);
78    }
79}
80