- marked as proposal
Remove Iterable<ASTNode> interface from ASTNode
JastAdd2 2.1.13-82-g51973c2
Having ASTNode implement Iterable<ASTNode>
can cause problems for projects that need to have custom iterators on AST nodes. For example, ExtendJ uses a SimpleSet
interface which provides its own iterators. This does not work well with ASTNode implementing Iterable<ASTNode>
.
List nodes should still implement Iterable<ASTNode>
.
Comments (6)
-
reporter -
reporter If the
ASTNode.iterator()
method is required, it can be added via a regular inter-type declaration. The following example introduces the old iterator to ASTNode:import java.util.Iterator; aspect Iterator { ASTNode implements Iterable<T>; @Override public Iterator<T> ASTNode.iterator() { return new Iterator<T>() { private int index = 0; @Override public boolean hasNext() { return index < getNumChild(); } @Override public T next() { return hasNext() ? (T) getChild(index++) : null; } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }
-
reporter - changed status to resolved
ASTNode no longer implements java.lang.Iterable
ASTNode no longer implements the java.lang.Iterable interface.
The default list node still implements java.lang.Iterable.
fixes
#247(bitbucket)→ <<cset 418a5b4d515a>>
-
reporter TODO: add a
children()
method to access an iterable children collection. -
Account Deactivated It could be useful to move implementation of List.iterator() to some method on ASTNode (e.g. childIterator()), and let List.iterator() delegate to childIterator(). Then the code needed to reintroduce the old behavior would be reduced to:
import java.util.Iterator; aspect Iterator { ASTNode implements Iterable<T>; @Override public Iterator<T> ASTNode.iterator() { return childIterator(); } }
It would probably also make implementing the children() method metioned above easier.
-
reporter Add AST child iterator methods on ASTNode
Added methods for easier iteration of AST children:
- ASTNode.astChildIterator(), returning an Iterator<T>.
- ASTNode.astChildren(), returning an Iterable<T>.
The astChildren() method can be used in an enhanced for statement.
Refactored List.iterator() to use ASTNode.astChildIterator().
see
#247(bitbucket)→ <<cset a44c68da9269>>
- Log in to comment