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

graphql.util.TreeTransformerUtil Maven / Gradle / Ivy

There is a newer version: 230521-nf-execution
Show newest version
package graphql.util;

import graphql.PublicApi;

@PublicApi
public class TreeTransformerUtil {

    /**
     * Can be called multiple times to change the current node of the context. The latest call wins
     *
     * @param context
     * @param changedNode
     * @param 
     *
     * @return
     */
    public static  TraversalControl changeNode(TraverserContext context, T changedNode) {
        NodeZipper zipperWithChangedNode = context.getVar(NodeZipper.class).withNewNode(changedNode);
        NodeMultiZipper multiZipper = context.getNewAccumulate();
        if (context.isChanged()) {
            context.setAccumulate(multiZipper.withReplacedZipperForNode(context.thisNode(), changedNode));
            context.changeNode(changedNode);
        } else {
            context.setAccumulate(multiZipper.withNewZipper(zipperWithChangedNode));
            context.changeNode(changedNode);
        }
        return TraversalControl.CONTINUE;
    }

    public static  TraversalControl deleteNode(TraverserContext context) {
        NodeZipper deleteNodeZipper = context.getVar(NodeZipper.class).deleteNode();
        NodeMultiZipper multiZipper = context.getNewAccumulate();
        context.setAccumulate(multiZipper.withNewZipper(deleteNodeZipper));
        context.deleteNode();
        return TraversalControl.CONTINUE;
    }

    public static  TraversalControl insertAfter(TraverserContext context, T toInsertAfter) {
        NodeZipper insertNodeZipper = context.getVar(NodeZipper.class).insertAfter(toInsertAfter);
        NodeMultiZipper multiZipper = context.getNewAccumulate();
        context.setAccumulate(multiZipper.withNewZipper(insertNodeZipper));
        return TraversalControl.CONTINUE;
    }

    public static  TraversalControl insertBefore(TraverserContext context, T toInsertBefore) {
        NodeZipper insertNodeZipper = context.getVar(NodeZipper.class).insertBefore(toInsertBefore);
        NodeMultiZipper multiZipper = context.getNewAccumulate();
        context.setAccumulate(multiZipper.withNewZipper(insertNodeZipper));
        return TraversalControl.CONTINUE;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy