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  */
  21 
  22 package com.sun.org.apache.bcel.internal.generic;
  23 
  24 import java.io.DataOutputStream;
  25 import java.io.IOException;
  26 
  27 import com.sun.org.apache.bcel.internal.util.ByteSequence;
  28 
  29 /**
  30  * GOTO_W - Branch always (to relative offset, not absolute address)
  31  *
  32  */
  33 public class GOTO_W extends GotoInstruction {
  34 
  35     /**
  36      * Empty constructor needed for Instruction.readInstruction.
  37      * Not to be used otherwise.
  38      */
  39     GOTO_W() {
  40     }
  41 
  42 
  43     public GOTO_W(final InstructionHandle target) {
  44         super(com.sun.org.apache.bcel.internal.Const.GOTO_W, target);
  45         super.setLength(5);
  46     }
  47 
  48 
  49     /**
  50      * Dump instruction as byte code to stream out.
  51      * @param out Output stream
  52      */
  53     @Override
  54     public void dump( final DataOutputStream out ) throws IOException {
  55         super.setIndex(getTargetOffset());
  56         out.writeByte(super.getOpcode());
  57         out.writeInt(super.getIndex());
  58     }
  59 
  60 
  61     /**
  62      * Read needed data (e.g. index) from file.
  63      */
  64     @Override
  65     protected void initFromFile( final ByteSequence bytes, final boolean wide ) throws IOException {
  66         super.setIndex(bytes.readInt());
  67         super.setLength(5);
  68     }
  69 
  70 
  71     /**
  72      * Call corresponding visitor method(s). The order is:
  73      * Call visitor methods of implemented interfaces first, then
  74      * call methods according to the class hierarchy in descending order,
  75      * i.e., the most specific visitXXX() call comes last.
  76      *
  77      * @param v Visitor object
  78      */
  79     @Override
  80     public void accept( final Visitor v ) {
  81         v.visitUnconditionalBranch(this);
  82         v.visitBranchInstruction(this);
  83         v.visitGotoInstruction(this);
  84         v.visitGOTO_W(this);
  85     }
  86 }