2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
26 package org.apidesign.javap;
28 public final class StackMapIterator {
29 private static final StackMapTableData INITIAL_FRAME =
30 new StackMapTableData(-1) {
32 int getStackItemsCount() {
37 public String toString() {
42 private final StackMapTableData[] stackMapTable;
44 private int nextFrameIndex;
45 private int lastFrameByteCodeOffset;
47 private int byteCodeOffset;
49 StackMapIterator(final StackMapTableData[] stackMapTable) {
50 this.stackMapTable = (stackMapTable != null)
52 : new StackMapTableData[0];
53 this.lastFrameByteCodeOffset = -1;
57 public String getFrameAsString() {
58 return getCurrentFrame().toString();
61 public int getFrameIndex() {
62 return nextFrameIndex;
65 public int getFrameStackItemsCount() {
66 return getCurrentFrame().getStackItemsCount();
69 public void advanceBy(final int numByteCodes) {
70 if (numByteCodes < 0) {
71 throw new IllegalStateException("Forward only iterator");
74 byteCodeOffset += numByteCodes;
75 while ((nextFrameIndex < stackMapTable.length)
76 && ((byteCodeOffset - lastFrameByteCodeOffset)
77 >= (stackMapTable[nextFrameIndex].offsetDelta
79 lastFrameByteCodeOffset +=
80 stackMapTable[nextFrameIndex].offsetDelta + 1;
85 public void advanceTo(final int nextByteCodeOffset) {
86 advanceBy(nextByteCodeOffset - byteCodeOffset);
89 private StackMapTableData getCurrentFrame() {
90 return (nextFrameIndex == 0)
92 : stackMapTable[nextFrameIndex - 1];