1919 * For {@index MISSING} nodes, a lookahead iterator created on the previous non-extra leaf node may be appropriate.
2020 */
2121@ NullMarked
22- public final class LookaheadIterator implements AutoCloseable , Enumeration <LookaheadIterator .Symbol > {
22+ public final class LookaheadIterator implements AutoCloseable , Iterator <LookaheadIterator .Symbol > {
2323 private final Arena arena ;
2424 private final MemorySegment self ;
2525 private final short state ;
@@ -80,8 +80,9 @@ public boolean reset(@Unsigned short state, Language language) {
8080 return ts_lookahead_iterator_reset (self , language .segment (), state );
8181 }
8282
83+ /** Check if the lookahead iterator has more symbols. */
8384 @ Override
84- public boolean hasMoreElements () {
85+ public boolean hasNext () {
8586 if (iterFirst ) {
8687 iterFirst = false ;
8788 hasNext = ts_lookahead_iterator_next (self );
@@ -96,8 +97,8 @@ public boolean hasMoreElements() {
9697 * @throws NoSuchElementException If there are no more symbols.
9798 */
9899 @ Override
99- public Symbol nextElement () throws NoSuchElementException {
100- if (!hasMoreElements ()) throw new NoSuchElementException ();
100+ public Symbol next () throws NoSuchElementException {
101+ if (!hasNext ()) throw new NoSuchElementException ();
101102 hasNext = ts_lookahead_iterator_next (self );
102103 return new Symbol (getCurrentSymbol (), getCurrentSymbolName ());
103104 }
@@ -127,6 +128,12 @@ public void close() throws RuntimeException {
127128 arena .close ();
128129 }
129130
131+ /** @hidden */
132+ @ Override
133+ public void remove () {
134+ Iterator .super .remove ();
135+ }
136+
130137 /** A class that pairs a symbol ID with its name. */
131138 public record Symbol (@ Unsigned short id , String name ) {}
132139
0 commit comments