Class NodeVisitor<T extends LexicalContext>

java.lang.Object
com.oracle.js.parser.ir.visitor.NodeVisitor<T>
Type Parameters:
T - lexical context class used by this visitor
Direct Known Subclasses:
JSONWriter, PrintVisitor

public abstract class NodeVisitor<T extends LexicalContext> extends Object
Visitor used to navigate the IR.
  • Field Details

  • Constructor Details

    • NodeVisitor

      public NodeVisitor(T lc)
      Constructor
      Parameters:
      lc - a custom lexical context
  • Method Details

    • getLexicalContext

      public final T getLexicalContext()
      Get the lexical context of this node visitor
      Returns:
      lexical context
    • enterDefault

      protected boolean enterDefault(Node node)
      Override this method to do a double inheritance pattern, e.g. avoid using
       if (x instanceof NodeTypeA) {
          ...
       } else if (x instanceof NodeTypeB) {
          ...
       } else {
          ...
       }
       
      Use a NodeVisitor instead, and this method contents forms the else case.
      Parameters:
      node - the node to visit
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
      See Also:
    • leaveDefault

      protected Node leaveDefault(Node node)
      Override this method to do a double inheritance pattern, e.g. avoid using
       if (x instanceof NodeTypeA) {
          ...
       } else if (x instanceof NodeTypeB) {
          ...
       } else {
          ...
       }
       
      Use a NodeVisitor instead, and this method contents forms the else case.
      Parameters:
      node - the node to visit
      Returns:
      the node
      See Also:
    • enterAccessNode

      public boolean enterAccessNode(AccessNode accessNode)
      Callback for entering an AccessNode
      Parameters:
      accessNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveAccessNode

      public Node leaveAccessNode(AccessNode accessNode)
      Callback for entering an AccessNode
      Parameters:
      accessNode - the node
      Returns:
      processed node, null if traversal should end
    • enterBlock

      public boolean enterBlock(Block block)
      Callback for entering a Block
      Parameters:
      block - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveBlock

      public Node leaveBlock(Block block)
      Callback for leaving a Block
      Parameters:
      block - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterBinaryNode

      public boolean enterBinaryNode(BinaryNode binaryNode)
      Callback for entering a BinaryNode
      Parameters:
      binaryNode - the node
      Returns:
      processed node
    • leaveBinaryNode

      public Node leaveBinaryNode(BinaryNode binaryNode)
      Callback for leaving a BinaryNode
      Parameters:
      binaryNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterBreakNode

      public boolean enterBreakNode(BreakNode breakNode)
      Callback for entering a BreakNode
      Parameters:
      breakNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveBreakNode

      public Node leaveBreakNode(BreakNode breakNode)
      Callback for leaving a BreakNode
      Parameters:
      breakNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterCallNode

      public boolean enterCallNode(CallNode callNode)
      Callback for entering a CallNode
      Parameters:
      callNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveCallNode

      public Node leaveCallNode(CallNode callNode)
      Callback for leaving a CallNode
      Parameters:
      callNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterCaseNode

      public boolean enterCaseNode(CaseNode caseNode)
      Callback for entering a CaseNode
      Parameters:
      caseNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveCaseNode

      public Node leaveCaseNode(CaseNode caseNode)
      Callback for leaving a CaseNode
      Parameters:
      caseNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterCatchNode

      public boolean enterCatchNode(CatchNode catchNode)
      Callback for entering a CatchNode
      Parameters:
      catchNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveCatchNode

      public Node leaveCatchNode(CatchNode catchNode)
      Callback for leaving a CatchNode
      Parameters:
      catchNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterContinueNode

      public boolean enterContinueNode(ContinueNode continueNode)
      Callback for entering a ContinueNode
      Parameters:
      continueNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveContinueNode

      public Node leaveContinueNode(ContinueNode continueNode)
      Callback for leaving a ContinueNode
      Parameters:
      continueNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterDebuggerNode

      public boolean enterDebuggerNode(DebuggerNode debuggerNode)
      Callback for entering a DebuggerNode
      Parameters:
      debuggerNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveDebuggerNode

      public Node leaveDebuggerNode(DebuggerNode debuggerNode)
      Callback for leaving a DebuggerNode
      Parameters:
      debuggerNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterEmptyNode

      public boolean enterEmptyNode(EmptyNode emptyNode)
      Callback for entering an EmptyNode
      Parameters:
      emptyNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveEmptyNode

      public Node leaveEmptyNode(EmptyNode emptyNode)
      Callback for leaving an EmptyNode
      Parameters:
      emptyNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterErrorNode

      public boolean enterErrorNode(ErrorNode errorNode)
      Callback for entering an ErrorNode
      Parameters:
      errorNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveErrorNode

      public Node leaveErrorNode(ErrorNode errorNode)
      Callback for leaving an ErrorNode
      Parameters:
      errorNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterNamedExportsNode

      public boolean enterNamedExportsNode(NamedExportsNode exportClauseNode)
    • leaveNamedExportsNode

      public Node leaveNamedExportsNode(NamedExportsNode exportClauseNode)
    • enterExportNode

      public boolean enterExportNode(ExportNode exportNode)
    • leaveExportNode

      public Node leaveExportNode(ExportNode exportNode)
    • enterExportSpecifierNode

      public boolean enterExportSpecifierNode(ExportSpecifierNode exportSpecifierNode)
    • leaveExportSpecifierNode

      public Node leaveExportSpecifierNode(ExportSpecifierNode exportSpecifierNode)
    • enterExpressionStatement

      public boolean enterExpressionStatement(ExpressionStatement expressionStatement)
      Callback for entering an ExpressionStatement
      Parameters:
      expressionStatement - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveExpressionStatement

      public Node leaveExpressionStatement(ExpressionStatement expressionStatement)
      Callback for leaving an ExpressionStatement
      Parameters:
      expressionStatement - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterBlockStatement

      public boolean enterBlockStatement(BlockStatement blockStatement)
      Callback for entering a BlockStatement
      Parameters:
      blockStatement - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveBlockStatement

      public Node leaveBlockStatement(BlockStatement blockStatement)
      Callback for leaving a BlockStatement
      Parameters:
      blockStatement - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterForNode

      public boolean enterForNode(ForNode forNode)
      Callback for entering a ForNode
      Parameters:
      forNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveForNode

      public Node leaveForNode(ForNode forNode)
      Callback for leaving a ForNode
      Parameters:
      forNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterFunctionNode

      public boolean enterFunctionNode(FunctionNode functionNode)
      Callback for entering a FunctionNode
      Parameters:
      functionNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveFunctionNode

      public Node leaveFunctionNode(FunctionNode functionNode)
      Callback for leaving a FunctionNode
      Parameters:
      functionNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterIdentNode

      public boolean enterIdentNode(IdentNode identNode)
      Callback for entering an IdentNode
      Parameters:
      identNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveIdentNode

      public Node leaveIdentNode(IdentNode identNode)
      Callback for leaving an IdentNode
      Parameters:
      identNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterIfNode

      public boolean enterIfNode(IfNode ifNode)
      Callback for entering an IfNode
      Parameters:
      ifNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveIfNode

      public Node leaveIfNode(IfNode ifNode)
      Callback for leaving an IfNode
      Parameters:
      ifNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterImportClauseNode

      public boolean enterImportClauseNode(ImportClauseNode importClauseNode)
    • leaveImportClauseNode

      public Node leaveImportClauseNode(ImportClauseNode importClauseNode)
    • enterImportNode

      public boolean enterImportNode(ImportNode importNode)
    • leaveImportNode

      public Node leaveImportNode(ImportNode importNode)
    • enterImportSpecifierNode

      public boolean enterImportSpecifierNode(ImportSpecifierNode importSpecifierNode)
    • leaveImportSpecifierNode

      public Node leaveImportSpecifierNode(ImportSpecifierNode importSpecifierNode)
    • enterIndexNode

      public boolean enterIndexNode(IndexNode indexNode)
      Callback for entering an IndexNode
      Parameters:
      indexNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveIndexNode

      public Node leaveIndexNode(IndexNode indexNode)
      Callback for leaving an IndexNode
      Parameters:
      indexNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterLabelNode

      public boolean enterLabelNode(LabelNode labelNode)
      Callback for entering a LabelNode
      Parameters:
      labelNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveLabelNode

      public Node leaveLabelNode(LabelNode labelNode)
      Callback for leaving a LabelNode
      Parameters:
      labelNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterLiteralNode

      public boolean enterLiteralNode(LiteralNode<?> literalNode)
      Callback for entering a LiteralNode
      Parameters:
      literalNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveLiteralNode

      public Node leaveLiteralNode(LiteralNode<?> literalNode)
      Callback for leaving a LiteralNode
      Parameters:
      literalNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterNameSpaceImportNode

      public boolean enterNameSpaceImportNode(NameSpaceImportNode nameSpaceImportNode)
    • leaveNameSpaceImportNode

      public Node leaveNameSpaceImportNode(NameSpaceImportNode nameSpaceImportNode)
    • enterNamedImportsNode

      public boolean enterNamedImportsNode(NamedImportsNode namedImportsNode)
    • leaveNamedImportsNode

      public Node leaveNamedImportsNode(NamedImportsNode namedImportsNode)
    • enterObjectNode

      public boolean enterObjectNode(ObjectNode objectNode)
      Callback for entering an ObjectNode
      Parameters:
      objectNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveObjectNode

      public Node leaveObjectNode(ObjectNode objectNode)
      Callback for leaving an ObjectNode
      Parameters:
      objectNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterPropertyNode

      public boolean enterPropertyNode(PropertyNode propertyNode)
      Callback for entering a PropertyNode
      Parameters:
      propertyNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leavePropertyNode

      public Node leavePropertyNode(PropertyNode propertyNode)
      Callback for leaving a PropertyNode
      Parameters:
      propertyNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterReturnNode

      public boolean enterReturnNode(ReturnNode returnNode)
      Callback for entering a ReturnNode
      Parameters:
      returnNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveReturnNode

      public Node leaveReturnNode(ReturnNode returnNode)
      Callback for leaving a ReturnNode
      Parameters:
      returnNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterSwitchNode

      public boolean enterSwitchNode(SwitchNode switchNode)
      Callback for entering a SwitchNode
      Parameters:
      switchNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveSwitchNode

      public Node leaveSwitchNode(SwitchNode switchNode)
      Callback for leaving a SwitchNode
      Parameters:
      switchNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterTernaryNode

      public boolean enterTernaryNode(TernaryNode ternaryNode)
      Callback for entering a TernaryNode
      Parameters:
      ternaryNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveTernaryNode

      public Node leaveTernaryNode(TernaryNode ternaryNode)
      Callback for leaving a TernaryNode
      Parameters:
      ternaryNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterThrowNode

      public boolean enterThrowNode(ThrowNode throwNode)
      Callback for entering a ThrowNode
      Parameters:
      throwNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveThrowNode

      public Node leaveThrowNode(ThrowNode throwNode)
      Callback for leaving a ThrowNode
      Parameters:
      throwNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterTryNode

      public boolean enterTryNode(TryNode tryNode)
      Callback for entering a TryNode
      Parameters:
      tryNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveTryNode

      public Node leaveTryNode(TryNode tryNode)
      Callback for leaving a TryNode
      Parameters:
      tryNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterUnaryNode

      public boolean enterUnaryNode(UnaryNode unaryNode)
      Callback for entering a UnaryNode
      Parameters:
      unaryNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveUnaryNode

      public Node leaveUnaryNode(UnaryNode unaryNode)
      Callback for leaving a UnaryNode
      Parameters:
      unaryNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterJoinPredecessorExpression

      public boolean enterJoinPredecessorExpression(JoinPredecessorExpression expr)
      Callback for entering a JoinPredecessorExpression.
      Parameters:
      expr - the join predecessor expression
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveJoinPredecessorExpression

      public Node leaveJoinPredecessorExpression(JoinPredecessorExpression expr)
      Callback for leaving a JoinPredecessorExpression.
      Parameters:
      expr - the join predecessor expression
      Returns:
      processed node, which will replace the original one, or the original node
    • enterVarNode

      public boolean enterVarNode(VarNode varNode)
      Callback for entering a VarNode
      Parameters:
      varNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveVarNode

      public Node leaveVarNode(VarNode varNode)
      Callback for leaving a VarNode
      Parameters:
      varNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterWhileNode

      public boolean enterWhileNode(WhileNode whileNode)
      Callback for entering a WhileNode
      Parameters:
      whileNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveWhileNode

      public Node leaveWhileNode(WhileNode whileNode)
      Callback for leaving a WhileNode
      Parameters:
      whileNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterWithNode

      public boolean enterWithNode(WithNode withNode)
      Callback for entering a WithNode
      Parameters:
      withNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveWithNode

      public Node leaveWithNode(WithNode withNode)
      Callback for leaving a WithNode
      Parameters:
      withNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterClassNode

      public boolean enterClassNode(ClassNode classNode)
      Callback for entering a ClassNode
      Parameters:
      classNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveClassNode

      public Node leaveClassNode(ClassNode classNode)
      Callback for leaving a ClassNode
      Parameters:
      classNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterBlockExpression

      public boolean enterBlockExpression(BlockExpression blockExpression)
      Callback for entering a BlockExpression
      Parameters:
      blockExpression - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveBlockExpression

      public Node leaveBlockExpression(BlockExpression blockExpression)
      Callback for leaving a BlockExpression
      Parameters:
      blockExpression - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterParameterNode

      public boolean enterParameterNode(ParameterNode paramNode)
      Callback for entering a ParameterNode
      Parameters:
      paramNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveParameterNode

      public Node leaveParameterNode(ParameterNode paramNode)
      Callback for leaving a ParameterNode
      Parameters:
      paramNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterTemplateLiteralNode

      public boolean enterTemplateLiteralNode(TemplateLiteralNode templateLiteralNode)
      Callback for entering a TemplateLiteralNode
      Parameters:
      templateLiteralNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveTemplateLiteralNode

      public Node leaveTemplateLiteralNode(TemplateLiteralNode templateLiteralNode)
      Callback for leaving a TemplateLiteralNode
      Parameters:
      templateLiteralNode - the node
      Returns:
      processed node, which will replace the original one, or the original node
    • enterClassElement

      public boolean enterClassElement(ClassElement element)
      Callback for entering a ClassElement
      Parameters:
      element - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • leaveClassElement

      public Node leaveClassElement(ClassElement element)
      Callback for leaving a ClassElement
      Parameters:
      element - the node
      Returns:
      processed node, which will replace the original one, or the original node