Interface NodeTraversal.Callback

All Known Subinterfaces:
NodeTraversal.ScopedCallback
All Known Implementing Classes:
BranchCoverageInstrumentationCallback, CheckArrayWithGoogObject, CheckConformance, CheckConstantCaseNames, CheckConstPrivateProperties, CheckDuplicateCase, CheckEmptyStatements, CheckEnums, CheckEs6ModuleFileStructure, CheckEs6Modules, CheckExtraRequires, CheckGoogModuleTypeScriptName, CheckInterfaces, CheckJSDocStyle, CheckMissingRequires, CheckMissingSemicolon, CheckNestedNames, CheckNoMutatedEs6Exports, CheckNullabilityModifiers, CheckPrimitiveAsObject, CheckPrototypeProperties, CheckProvidesSorted, CheckRequiresSorted, CheckTypeImportCodeReferences, CheckUnusedLabels, CheckUnusedPrivateProperties, CheckUselessBlocks, CheckVar, ChromePass, ClosureCheckModule, ControlFlowAnalysis, ControlFlowGraph.AbstractCfgNodeTraversalCallback, CrossChunkReferenceCollector, Es6CheckModule, Es6ConvertSuper, Es6ConvertSuperConstructorCalls, Es6ExtractClasses, Es6ForOfConverter, Es6RenameVariablesInParamLists, Es6RewriteArrowFunction, Es6RewriteBlockScopedDeclaration, Es6RewriteBlockScopedFunctionDeclaration, Es6RewriteClass, Es6RewriteClassExtendsExpressions, Es6RewriteDestructuring, Es6RewriteModules, Es6RewriteRestAndSpread, Es6RewriteScriptsToModules, Es6SplitVariableDeclarations, Es7RewriteExponentialOperator, EsModuleProcessor, ExtraRequireRemover, FindModuleDependencies, ForbidDynamicImportUsage, ImplicitNullabilityCheck, InjectTranspilationRuntimeLibraries, InstrumentAsyncContext, J2clAssertRemovalPass, J2clChecksPass, J2clUtilGetDefineRewriterPass, JsMessageVisitor, LateEs6ToEs3Converter, NodeTraversal.AbstractCfgCallback, NodeTraversal.AbstractChangedScopeCallback, NodeTraversal.AbstractModuleCallback, NodeTraversal.AbstractPostOrderCallback, NodeTraversal.AbstractPreOrderCallback, NodeTraversal.AbstractScopedCallback, NodeTraversal.AbstractShallowCallback, NodeTraversal.AbstractShallowStatementCallback, NodeTraversal.ExternsSkippingCallback, ProcessCommonJSModules, RewriteAsyncFunctions, RewriteAsyncIteration, RewriteClassMembers, RewriteDynamicImports, RewriteJsonToModule, RewriteLogicalAssignmentOperatorsPass, RewriteNullishCoalesceOperator, RewriteObjectSpread, SourceInformationAnnotator, TypeCheck
Enclosing class:
NodeTraversal

public static interface NodeTraversal.Callback
Callback for tree-based traversals
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    shouldTraverse(NodeTraversal t, Node n, @Nullable Node parent)
    Visits a node in preorder (before its children) and decides whether the node and its children should be traversed.
    void
    visit(NodeTraversal t, Node n, @Nullable Node parent)
    Visits a node in postorder (after its children).
  • Method Details

    • shouldTraverse

      boolean shouldTraverse(NodeTraversal t, Node n, @Nullable Node parent)
      Visits a node in preorder (before its children) and decides whether the node and its children should be traversed.

      If this method returns true, the node will be visited by visit(NodeTraversal, Node, Node) in postorder and its children will be visited by both shouldTraverse(NodeTraversal, Node, Node) in preorder and by visit(NodeTraversal, Node, Node) in postorder.

      If this method returns false, the node will not be visited by visit(NodeTraversal, Node, Node) and its children will neither be visited by shouldTraverse(NodeTraversal, Node, Node) nor visit(NodeTraversal, Node, Node).

      Siblings are always visited left-to-right.

      Implementations can have side-effects (e.g. modify the parse tree). Removing the current node is legal, but removing or reordering nodes above the current node may cause nodes to be visited twice or not at all.

      Parameters:
      t - The current traversal.
      n - The current node.
      parent - The parent of the current node.
      Returns:
      whether the children of this node should be visited
    • visit

      void visit(NodeTraversal t, Node n, @Nullable Node parent)
      Visits a node in postorder (after its children). A node is visited in postorder iff shouldTraverse(NodeTraversal, Node, Node) returned true for its parent and itself. In particular, the root node is never visited in postorder.

      Siblings are always visited left-to-right.

      Implementations can have side-effects (e.g. modify the parse tree). Removing the current node is legal, but removing or reordering nodes above the current node may cause nodes to be visited twice or not at all.

      Parameters:
      t - The current traversal.
      n - The current node.
      parent - The parent of the current node.