    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one
    003 * or more contributor license agreements.  See the NOTICE file
    004 * distributed with this work for additional information
    005 * regarding copyright ownership.  The ASF licenses this file
    006 * to you under the Apache License, Version 2.0 (the
    007 * "License"); you may not use this file except in compliance
    008 * with the License.  You may obtain a copy of the License at
    009 *
    010 *   https://www.apache.org/licenses/LICENSE-2.0
    011 *
    012 * Unless required by applicable law or agreed to in writing,
    013 * software distributed under the License is distributed on an
    014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    015 * KIND, either express or implied.  See the License for the
    016 * specific language governing permissions and limitations
    017 * under the License.
    018 */
    019package org.apache.bcel.generic;
    020
    021import java.io.DataOutputStream;
    022import java.io.IOException;
    023
    024import org.apache.bcel.Const;
    025import org.apache.bcel.ExceptionConst;
    026
    027/**
    028 * INVOKESPECIAL - Invoke instance method; special handling for superclass, private and instance initialization method
    029 * invocations
    030 *
    031 * <PRE>
    032 * Stack: ..., objectref, [arg1, [arg2 ...]] -&gt; ...
    033 * </PRE>
    034 *
    035 * @see <a href="https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-6.html#jvms-6.5.invokespecial"> The
    036 *      invokespecial instruction in The Java Virtual Machine Specification</a>
    037 */
    038public class INVOKESPECIAL extends InvokeInstruction {
    039
    040    /**
    041     * Empty constructor needed for Instruction.readInstruction. Not to be used otherwise.
    042     */
    043    INVOKESPECIAL() {
    044    }
    045
    046    public INVOKESPECIAL(final int index) {
    047        super(Const.INVOKESPECIAL, index);
    048    }
    049
    050    /**
    051     * Call corresponding visitor method(s). The order is: Call visitor methods of implemented interfaces first, then call
    052     * methods according to the class hierarchy in descending order, that is, the most specific visitXXX() call comes last.
    053     *
    054     * @param v Visitor object.
    055     */
    056    @Override
    057    public void accept(final Visitor v) {
    058        v.visitExceptionThrower(this);
    059        v.visitTypedInstruction(this);
    060        v.visitStackConsumer(this);
    061        v.visitStackProducer(this);
    062        v.visitLoadClass(this);
    063        v.visitCPInstruction(this);
    064        v.visitFieldOrMethod(this);
    065        v.visitInvokeInstruction(this);
    066        v.visitINVOKESPECIAL(this);
    067    }
    068
    069    /**
    070     * Dumps instruction as byte code to stream out.
    071     *
    072     * @param out Output stream.
    073     */
    074    @Override
    075    public void dump(final DataOutputStream out) throws IOException {
    076        out.writeByte(super.getOpcode());
    077        out.writeShort(super.getIndex());
    078    }
    079
    080    @Override
    081    public Class<?>[] getExceptions() {
    082        return ExceptionConst.createExceptions(ExceptionConst.EXCS.EXCS_FIELD_AND_METHOD_RESOLUTION, ExceptionConst.NULL_POINTER_EXCEPTION,
    083            ExceptionConst.INCOMPATIBLE_CLASS_CHANGE_ERROR, ExceptionConst.ABSTRACT_METHOD_ERROR, ExceptionConst.UNSATISFIED_LINK_ERROR);
    084    }
    085}