< prev index next >

src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/GOTO.java

Print this page

        

@@ -19,69 +19,83 @@
  * limitations under the License.
  */
 
 package com.sun.org.apache.bcel.internal.generic;
 
-import java.io.*;
+import java.io.DataOutputStream;
+import java.io.IOException;
 
 /**
  * GOTO - Branch always (to relative offset, not absolute address)
  *
- * @author  <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
+ * @version $Id: GOTO.java 1749603 2016-06-21 20:50:19Z ggregory $
  */
 public class GOTO extends GotoInstruction implements VariableLengthInstruction {
+
   /**
    * Empty constructor needed for the Class.newInstance() statement in
    * Instruction.readInstruction(). Not to be used otherwise.
    */
-  GOTO() {}
+    GOTO() {
+    }
+
 
-  public GOTO(InstructionHandle target) {
-    super(com.sun.org.apache.bcel.internal.Constants.GOTO, target);
+    public GOTO(final InstructionHandle target) {
+        super(com.sun.org.apache.bcel.internal.Const.GOTO, target);
   }
 
+
   /**
    * Dump instruction as byte code to stream out.
    * @param out Output stream
    */
-  public void dump(DataOutputStream out) throws IOException {
-    index = getTargetOffset();
-    if(opcode == com.sun.org.apache.bcel.internal.Constants.GOTO)
+    @Override
+    public void dump( final DataOutputStream out ) throws IOException {
+        super.setIndex(getTargetOffset());
+        final short _opcode = getOpcode();
+        if (_opcode == com.sun.org.apache.bcel.internal.Const.GOTO) {
       super.dump(out);
-    else { // GOTO_W
-      index = getTargetOffset();
-      out.writeByte(opcode);
-      out.writeInt(index);
+        } else { // GOTO_W
+            super.setIndex(getTargetOffset());
+            out.writeByte(_opcode);
+            out.writeInt(super.getIndex());
     }
   }
 
-  /** Called in pass 2 of InstructionList.setPositions() in order to update
-   * the branch target, that may shift due to variable length instructions.
-   */
-  protected int updatePosition(int offset, int max_offset) {
-    int i = getTargetOffset(); // Depending on old position value
-
-    position += offset; // Position may be shifted by preceding expansions
 
-    if(Math.abs(i) >= (32767 - max_offset)) { // to large for short (estimate)
-      opcode = com.sun.org.apache.bcel.internal.Constants.GOTO_W;
-      length = 5;
-      return 2; // 5 - 3
+    /**
+     * Called in pass 2 of InstructionList.setPositions() in order to update
+     * the branch target, that may shift due to variable length instructions.
+     *
+     * @param offset additional offset caused by preceding (variable length) instructions
+     * @param max_offset the maximum offset that may be caused by these instructions
+     * @return additional offset caused by possible change of this instruction's length
+     */
+    @Override
+    protected int updatePosition( final int offset, final int max_offset ) {
+        final int i = getTargetOffset(); // Depending on old position value
+        setPosition(getPosition() + offset); // Position may be shifted by preceding expansions
+        if (Math.abs(i) >= (Short.MAX_VALUE - max_offset)) { // to large for short (estimate)
+            super.setOpcode(com.sun.org.apache.bcel.internal.Const.GOTO_W);
+            final short old_length = (short) super.getLength();
+            super.setLength(5);
+            return super.getLength() - old_length;
     }
-
     return 0;
   }
 
+
   /**
    * Call corresponding visitor method(s). The order is:
    * Call visitor methods of implemented interfaces first, then
    * call methods according to the class hierarchy in descending order,
    * i.e., the most specific visitXXX() call comes last.
    *
    * @param v Visitor object
    */
-  public void accept(Visitor v) {
+    @Override
+    public void accept( final Visitor v ) {
     v.visitVariableLengthInstruction(this);
     v.visitUnconditionalBranch(this);
     v.visitBranchInstruction(this);
     v.visitGotoInstruction(this);
     v.visitGOTO(this);
< prev index next >