GETFIELD xref

View Javadoc

    1   /*
    2    * Copyright  2000-2004 The Apache Software Foundation
    3    *
    4    *  Licensed under the Apache License, Version 2.0 (the "License");
    5    *  you may not use this file except in compliance with the License.
    6    *  You may obtain a copy of the License at
    7    *
    8    *      http://www.apache.org/licenses/LICENSE-2.0
    9    *
    10   *  Unless required by applicable law or agreed to in writing, software
    11   *  distributed under the License is distributed on an "AS IS" BASIS,
    12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   *  See the License for the specific language governing permissions and
    14   *  limitations under the License.
    15   *
    16   */
    17  package org.apache.bcel.generic;
    18
    19  import org.apache.bcel.Constants;
    20  import org.apache.bcel.ExceptionConstants;
    21
    22  /***
    23   * GETFIELD - Fetch field from object
    24   * <PRE>Stack: ..., objectref -&gt; ..., value</PRE>
    25   * OR
    26   * <PRE>Stack: ..., objectref -&gt; ..., value.word1, value.word2</PRE>
    27   *
    28   * @version $Id: GETFIELD.java 386056 2006-03-15 11:31:56Z tcurdt $
    29   * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
    30   */
    31  public class GETFIELD extends FieldInstruction implements ExceptionThrower, StackConsumer,
    32          StackProducer {
    33
    34      /***
    35       * Empty constructor needed for the Class.newInstance() statement in
    36       * Instruction.readInstruction(). Not to be used otherwise.
    37       */
    38      GETFIELD() {
    39      }
    40
    41
    42      public GETFIELD(int index) {
    43          super(Constants.GETFIELD, index);
    44      }
    45
    46
    47      public int produceStack( ConstantPoolGen cpg ) {
    48          return getFieldSize(cpg);
    49      }
    50
    51
    52      public Class[] getExceptions() {
    53          Class[] cs = new Class[2 + ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length];
    54          System.arraycopy(ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION, 0, cs, 0,
    55                  ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length);
    56          cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length + 1] = ExceptionConstants.INCOMPATIBLE_CLASS_CHANGE_ERROR;
    57          cs[ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION.length] = ExceptionConstants.NULL_POINTER_EXCEPTION;
    58          return cs;
    59      }
    60
    61
    62      /***
    63       * Call corresponding visitor method(s). The order is:
    64       * Call visitor methods of implemented interfaces first, then
    65       * call methods according to the class hierarchy in descending order,
    66       * i.e., the most specific visitXXX() call comes last.
    67       *
    68       * @param v Visitor object
    69       */
    70      public void accept( Visitor v ) {
    71          v.visitExceptionThrower(this);
    72          v.visitStackConsumer(this);
    73          v.visitStackProducer(this);
    74          v.visitTypedInstruction(this);
    75          v.visitLoadClass(this);
    76          v.visitCPInstruction(this);
    77          v.visitFieldOrMethod(this);
    78          v.visitFieldInstruction(this);
    79          v.visitGETFIELD(this);
    80      }
    81  }