1 4 package gnu.bytecode; 5 6 10 11 public class VarEnumerator implements java.util.Enumeration 12 { 13 Scope topScope; 14 Scope currentScope; 15 Variable next; 16 17 public VarEnumerator (Scope scope) 18 { 19 topScope = scope; 20 reset (); 21 } 22 23 public final void reset () 24 { 25 currentScope = topScope; 26 if (topScope != null) 27 { 28 next = currentScope.firstVar (); 29 if (next == null) 30 fixup (); 31 } 32 } 33 34 private void fixup () 35 { 36 while (next == null) 37 { 38 if (currentScope.firstChild != null) 39 currentScope = currentScope.firstChild; 40 else 41 { 42 while (currentScope.nextSibling == null) 43 { 44 if (currentScope == topScope) 45 return; 46 currentScope = currentScope.parent; 47 } 48 currentScope = currentScope.nextSibling; 49 } 50 next = currentScope.firstVar (); 51 } 52 } 53 54 55 public final Variable nextVar () 56 { 57 Variable result = next; 58 if (result != null) 59 { 60 next = result.nextVar (); 61 if (next == null) 62 fixup (); 63 } 64 return result; 65 } 66 67 public final boolean hasMoreElements () 68 { 69 return next != null; 70 } 71 72 public Object nextElement () 73 { 74 Variable result = nextVar (); 75 if (result == null) 76 throw new java.util.NoSuchElementException ("VarEnumerator"); 77 return result; 78 } 79 80 81 82 } 83 | Popular Tags |