1.1 --- a/src/share/classes/com/sun/tools/classfile/Code_attribute.java Wed Mar 25 10:29:28 2009 +0000 1.2 +++ b/src/share/classes/com/sun/tools/classfile/Code_attribute.java Mon Mar 30 15:08:09 2009 -0700 1.3 @@ -26,6 +26,8 @@ 1.4 package com.sun.tools.classfile; 1.5 1.6 import java.io.IOException; 1.7 +import java.util.Iterator; 1.8 +import java.util.NoSuchElementException; 1.9 1.10 /** 1.11 * See JVMS3, section 4.8.3. 1.12 @@ -100,6 +102,39 @@ 1.13 return visitor.visitCode(this, data); 1.14 } 1.15 1.16 + public Iterable<Instruction> getInstructions() { 1.17 + return new Iterable<Instruction>() { 1.18 + public Iterator<Instruction> iterator() { 1.19 + return new Iterator<Instruction>() { 1.20 + 1.21 + public boolean hasNext() { 1.22 + return (next != null); 1.23 + } 1.24 + 1.25 + public Instruction next() { 1.26 + if (next == null) 1.27 + throw new NoSuchElementException(); 1.28 + 1.29 + current = next; 1.30 + pc += current.length(); 1.31 + next = (pc < code.length ? new Instruction(code, pc) : null); 1.32 + return current; 1.33 + } 1.34 + 1.35 + public void remove() { 1.36 + throw new UnsupportedOperationException("Not supported."); 1.37 + } 1.38 + 1.39 + Instruction current = null; 1.40 + int pc = 0; 1.41 + Instruction next = new Instruction(code, pc); 1.42 + 1.43 + }; 1.44 + } 1.45 + 1.46 + }; 1.47 + } 1.48 + 1.49 public final int max_stack; 1.50 public final int max_locals; 1.51 public final int code_length;