Added proper support for changing the AST as its being visited, both removal and addition. The rule is now: children traversal traverses through the tree mostly as it was when it started.

This commit is contained in:
Reinier Zwitserloot committed 2009-06-24 01:22:08 +02:00
1 parent c834e09af4
commit 99a38d4d08
4 files changed
+12 -5

No files matched your search

+7 -2
View File
@@ -134,7 +134,7 @@ public abstract class AST<N> {
}
public Collection<? extends Node> down() {
return children;
return new ArrayList<Node>(children);
}
public boolean isHandled() {
@@ -154,13 +154,18 @@ public abstract class AST<N> {
return fileName;
}
public Node add(N newChild, Kind kind) {
@SuppressWarnings("unchecked") public Node add(N newChild, Kind kind) {
Node n = buildTree(newChild, kind);
if ( n == null ) return null;
n.parent = this;
((List)children).add(n);
return n;
}
public void removeChild(Node child) {
children.remove(child);
}
public Node recursiveSetHandled() {
this.handled = true;
for ( Node child : children ) child.recursiveSetHandled();
+1 -1
View File
@@ -256,7 +256,7 @@ public class EclipseAST extends AST<ASTNode> {
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override public Collection<Node> down() {
return (Collection<Node>) children;
return (Collection<Node>) super.down();
}
/** {@inheritDoc} */
+2
View File
@@ -135,7 +135,9 @@ class PKG {
for ( int i = 0 ; i < parent.methods.length ; i++ ) {
if ( parent.methods[i] instanceof ConstructorDeclaration &&
(parent.methods[i].bits & ASTNode.IsDefaultConstructor) != 0 ) {
EclipseAST.Node tossMe = type.getNodeFor(parent.methods[i]);
parent.methods[i] = method;
if ( tossMe != null ) tossMe.up().removeChild(tossMe);
injectionComplete = true;
break;
}
+2 -2
View File
@@ -69,7 +69,7 @@ public class JavacAST extends AST<JCTree> {
}
private void traverseChildren(JavacASTVisitor visitor, Node node) {
for ( Node child : node.down() ) {
for ( Node child : new ArrayList<Node>(node.down()) ) {
child.traverse(visitor);
}
}
@@ -357,7 +357,7 @@ public class JavacAST extends AST<JCTree> {
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override public Collection<Node> down() {
return (Collection<Node>) children;
return (Collection<Node>) super.down();
}
public void addError(String message) {