Class JSONWriter

java.lang.Object
com.oracle.js.parser.ir.visitor.NodeVisitor<LexicalContext>
com.oracle.truffle.js.parser.internal.ir.debug.JSONWriter

public final class JSONWriter extends NodeVisitor<LexicalContext>
This IR writer produces a JSON string that represents AST as a JSON string.
  • Method Details

    • parse

      public static String parse(ScriptEnvironment env, String code, String name, boolean includeLoc)
      Returns AST as JSON compatible string.
      Parameters:
      env - environment
      code - code to be parsed
      name - name of the code source (used for location)
      includeLoc - tells whether to include location information for nodes or not
      Returns:
      JSON string representation of AST of the supplied code
    • enterJoinPredecessorExpression

      public boolean enterJoinPredecessorExpression(JoinPredecessorExpression joinPredecessorExpression)
      Description copied from class: NodeVisitor
      Callback for entering a JoinPredecessorExpression.
      Overrides:
      enterJoinPredecessorExpression in class NodeVisitor<LexicalContext>
      Parameters:
      joinPredecessorExpression - the join predecessor expression
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterDefault

      protected boolean enterDefault(Node node)
      Description copied from class: NodeVisitor
      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.
      Overrides:
      enterDefault in class NodeVisitor<LexicalContext>
      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)
      Description copied from class: NodeVisitor
      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.
      Overrides:
      leaveDefault in class NodeVisitor<LexicalContext>
      Parameters:
      node - the node to visit
      Returns:
      the node
      See Also:
    • enterAccessNode

      public boolean enterAccessNode(AccessNode accessNode)
      Description copied from class: NodeVisitor
      Callback for entering an AccessNode
      Overrides:
      enterAccessNode in class NodeVisitor<LexicalContext>
      Parameters:
      accessNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterBlock

      public boolean enterBlock(Block block)
      Description copied from class: NodeVisitor
      Callback for entering a Block
      Overrides:
      enterBlock in class NodeVisitor<LexicalContext>
      Parameters:
      block - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterBinaryNode

      public boolean enterBinaryNode(BinaryNode binaryNode)
      Description copied from class: NodeVisitor
      Callback for entering a BinaryNode
      Overrides:
      enterBinaryNode in class NodeVisitor<LexicalContext>
      Parameters:
      binaryNode - the node
      Returns:
      processed node
    • enterBreakNode

      public boolean enterBreakNode(BreakNode breakNode)
      Description copied from class: NodeVisitor
      Callback for entering a BreakNode
      Overrides:
      enterBreakNode in class NodeVisitor<LexicalContext>
      Parameters:
      breakNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterCallNode

      public boolean enterCallNode(CallNode callNode)
      Description copied from class: NodeVisitor
      Callback for entering a CallNode
      Overrides:
      enterCallNode in class NodeVisitor<LexicalContext>
      Parameters:
      callNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterCaseNode

      public boolean enterCaseNode(CaseNode caseNode)
      Description copied from class: NodeVisitor
      Callback for entering a CaseNode
      Overrides:
      enterCaseNode in class NodeVisitor<LexicalContext>
      Parameters:
      caseNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterCatchNode

      public boolean enterCatchNode(CatchNode catchNode)
      Description copied from class: NodeVisitor
      Callback for entering a CatchNode
      Overrides:
      enterCatchNode in class NodeVisitor<LexicalContext>
      Parameters:
      catchNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterContinueNode

      public boolean enterContinueNode(ContinueNode continueNode)
      Description copied from class: NodeVisitor
      Callback for entering a ContinueNode
      Overrides:
      enterContinueNode in class NodeVisitor<LexicalContext>
      Parameters:
      continueNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterDebuggerNode

      public boolean enterDebuggerNode(DebuggerNode debuggerNode)
      Description copied from class: NodeVisitor
      Callback for entering a DebuggerNode
      Overrides:
      enterDebuggerNode in class NodeVisitor<LexicalContext>
      Parameters:
      debuggerNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterEmptyNode

      public boolean enterEmptyNode(EmptyNode emptyNode)
      Description copied from class: NodeVisitor
      Callback for entering an EmptyNode
      Overrides:
      enterEmptyNode in class NodeVisitor<LexicalContext>
      Parameters:
      emptyNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterExpressionStatement

      public boolean enterExpressionStatement(ExpressionStatement expressionStatement)
      Description copied from class: NodeVisitor
      Callback for entering an ExpressionStatement
      Overrides:
      enterExpressionStatement in class NodeVisitor<LexicalContext>
      Parameters:
      expressionStatement - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterBlockStatement

      public boolean enterBlockStatement(BlockStatement blockStatement)
      Description copied from class: NodeVisitor
      Callback for entering a BlockStatement
      Overrides:
      enterBlockStatement in class NodeVisitor<LexicalContext>
      Parameters:
      blockStatement - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterForNode

      public boolean enterForNode(ForNode forNode)
      Description copied from class: NodeVisitor
      Callback for entering a ForNode
      Overrides:
      enterForNode in class NodeVisitor<LexicalContext>
      Parameters:
      forNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterFunctionNode

      public boolean enterFunctionNode(FunctionNode functionNode)
      Description copied from class: NodeVisitor
      Callback for entering a FunctionNode
      Overrides:
      enterFunctionNode in class NodeVisitor<LexicalContext>
      Parameters:
      functionNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterClassNode

      public boolean enterClassNode(ClassNode classNode)
      Description copied from class: NodeVisitor
      Callback for entering a ClassNode
      Overrides:
      enterClassNode in class NodeVisitor<LexicalContext>
      Parameters:
      classNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterIdentNode

      public boolean enterIdentNode(IdentNode identNode)
      Description copied from class: NodeVisitor
      Callback for entering an IdentNode
      Overrides:
      enterIdentNode in class NodeVisitor<LexicalContext>
      Parameters:
      identNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterIfNode

      public boolean enterIfNode(IfNode ifNode)
      Description copied from class: NodeVisitor
      Callback for entering an IfNode
      Overrides:
      enterIfNode in class NodeVisitor<LexicalContext>
      Parameters:
      ifNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterIndexNode

      public boolean enterIndexNode(IndexNode indexNode)
      Description copied from class: NodeVisitor
      Callback for entering an IndexNode
      Overrides:
      enterIndexNode in class NodeVisitor<LexicalContext>
      Parameters:
      indexNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterLabelNode

      public boolean enterLabelNode(LabelNode labelNode)
      Description copied from class: NodeVisitor
      Callback for entering a LabelNode
      Overrides:
      enterLabelNode in class NodeVisitor<LexicalContext>
      Parameters:
      labelNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterLiteralNode

      public boolean enterLiteralNode(LiteralNode literalNode)
      Description copied from class: NodeVisitor
      Callback for entering a LiteralNode
      Overrides:
      enterLiteralNode in class NodeVisitor<LexicalContext>
      Parameters:
      literalNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterObjectNode

      public boolean enterObjectNode(ObjectNode objectNode)
      Description copied from class: NodeVisitor
      Callback for entering an ObjectNode
      Overrides:
      enterObjectNode in class NodeVisitor<LexicalContext>
      Parameters:
      objectNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterPropertyNode

      public boolean enterPropertyNode(PropertyNode propertyNode)
      Description copied from class: NodeVisitor
      Callback for entering a PropertyNode
      Overrides:
      enterPropertyNode in class NodeVisitor<LexicalContext>
      Parameters:
      propertyNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterReturnNode

      public boolean enterReturnNode(ReturnNode returnNode)
      Description copied from class: NodeVisitor
      Callback for entering a ReturnNode
      Overrides:
      enterReturnNode in class NodeVisitor<LexicalContext>
      Parameters:
      returnNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterSwitchNode

      public boolean enterSwitchNode(SwitchNode switchNode)
      Description copied from class: NodeVisitor
      Callback for entering a SwitchNode
      Overrides:
      enterSwitchNode in class NodeVisitor<LexicalContext>
      Parameters:
      switchNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterTernaryNode

      public boolean enterTernaryNode(TernaryNode ternaryNode)
      Description copied from class: NodeVisitor
      Callback for entering a TernaryNode
      Overrides:
      enterTernaryNode in class NodeVisitor<LexicalContext>
      Parameters:
      ternaryNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterThrowNode

      public boolean enterThrowNode(ThrowNode throwNode)
      Description copied from class: NodeVisitor
      Callback for entering a ThrowNode
      Overrides:
      enterThrowNode in class NodeVisitor<LexicalContext>
      Parameters:
      throwNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterTryNode

      public boolean enterTryNode(TryNode tryNode)
      Description copied from class: NodeVisitor
      Callback for entering a TryNode
      Overrides:
      enterTryNode in class NodeVisitor<LexicalContext>
      Parameters:
      tryNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterUnaryNode

      public boolean enterUnaryNode(UnaryNode unaryNode)
      Description copied from class: NodeVisitor
      Callback for entering a UnaryNode
      Overrides:
      enterUnaryNode in class NodeVisitor<LexicalContext>
      Parameters:
      unaryNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterVarNode

      public boolean enterVarNode(VarNode varNode)
      Description copied from class: NodeVisitor
      Callback for entering a VarNode
      Overrides:
      enterVarNode in class NodeVisitor<LexicalContext>
      Parameters:
      varNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterWhileNode

      public boolean enterWhileNode(WhileNode whileNode)
      Description copied from class: NodeVisitor
      Callback for entering a WhileNode
      Overrides:
      enterWhileNode in class NodeVisitor<LexicalContext>
      Parameters:
      whileNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterWithNode

      public boolean enterWithNode(WithNode withNode)
      Description copied from class: NodeVisitor
      Callback for entering a WithNode
      Overrides:
      enterWithNode in class NodeVisitor<LexicalContext>
      Parameters:
      withNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterTemplateLiteralNode

      public boolean enterTemplateLiteralNode(TemplateLiteralNode templateLiteralNode)
      Description copied from class: NodeVisitor
      Callback for entering a TemplateLiteralNode
      Overrides:
      enterTemplateLiteralNode in class NodeVisitor<LexicalContext>
      Parameters:
      templateLiteralNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise