All Downloads are FREE. Search and download functionalities are using the official Maven repository.

graphql.validation.LanguageTraversal Maven / Gradle / Ivy

There is a newer version: 230521-nf-execution
Show newest version
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