View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   *
17   */
18  package org.apache.bcel.generic;
19  
20  import java.io.DataOutputStream;
21  import java.io.IOException;
22  
23  import org.apache.bcel.Const;
24  import org.apache.bcel.ExceptionConst;
25  
26  /**
27   * INVOKESPECIAL - Invoke instance method; special handling for superclass, private
28   * and instance initialization method invocations
29   *
30   * <PRE>Stack: ..., objectref, [arg1, [arg2 ...]] -&gt; ...</PRE>
31   *
32   * @version $Id: INVOKESPECIAL.html 1021978 2017-12-09 17:38:21Z ggregory $
33   * @see
34   * <a href="http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-6.html#jvms-6.5.invokespecial">
35   * The invokespecial instruction in The Java Virtual Machine Specification</a>
36   */
37  public class INVOKESPECIAL extends InvokeInstruction {
38  
39      /**
40       * Empty constructor needed for Instruction.readInstruction.
41       * Not to be used otherwise.
42       */
43      INVOKESPECIAL() {
44      }
45  
46  
47      public INVOKESPECIAL(final int index) {
48          super(Const.INVOKESPECIAL, index);
49      }
50  
51  
52      /**
53       * Dump instruction as byte code to stream out.
54       * @param out Output stream
55       */
56      @Override
57      public void dump( final DataOutputStream out ) throws IOException {
58          out.writeByte(super.getOpcode());
59          out.writeShort(super.getIndex());
60      }
61  
62      @Override
63      public Class<?>[] getExceptions() {
64          return ExceptionConst.createExceptions(ExceptionConst.EXCS.EXCS_FIELD_AND_METHOD_RESOLUTION,
65              ExceptionConst.NULL_POINTER_EXCEPTION,
66              ExceptionConst.INCOMPATIBLE_CLASS_CHANGE_ERROR,
67              ExceptionConst.ABSTRACT_METHOD_ERROR,
68              ExceptionConst.UNSATISFIED_LINK_ERROR);
69      }
70  
71  
72      /**
73       * Call corresponding visitor method(s). The order is:
74       * Call visitor methods of implemented interfaces first, then
75       * call methods according to the class hierarchy in descending order,
76       * i.e., the most specific visitXXX() call comes last.
77       *
78       * @param v Visitor object
79       */
80      @Override
81      public void accept( final Visitor v ) {
82          v.visitExceptionThrower(this);
83          v.visitTypedInstruction(this);
84          v.visitStackConsumer(this);
85          v.visitStackProducer(this);
86          v.visitLoadClass(this);
87          v.visitCPInstruction(this);
88          v.visitFieldOrMethod(this);
89          v.visitInvokeInstruction(this);
90          v.visitINVOKESPECIAL(this);
91      }
92  }