graphql.validation.LanguageTraversal Maven / Gradle / Ivy
package graphql.validation;
import java.util.ArrayList;
import java.util.List;
import graphql.Internal;
import graphql.language.Node;
@Internal
public class LanguageTraversal {
private final List path;
public LanguageTraversal() {
path = new ArrayList<>();
}
public LanguageTraversal(List basePath) {
if (basePath != null) {
path = basePath;
} else {
path = new ArrayList<>();
}
}
public void traverse(Node root, DocumentVisitor documentVisitor) {
traverseImpl(root, documentVisitor, path);
}
private void traverseImpl(Node> root, DocumentVisitor documentVisitor, List path) {
documentVisitor.enter(root, path);
path.add(root);
List children = root.getChildren();
for (Node child : children) {
if (child != null) {
traverseImpl(child, documentVisitor, path);
}
}
path.remove(path.size() - 1);
documentVisitor.leave(root, path);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy