Package org.jruby.ast

Class Node

java.lang.Object
org.jruby.ast.Node
Direct Known Subclasses:
AliasNode, AndNode, ArgsCatNode, ArgsNode, ArgsPushNode, ArgumentNode, ArrayPatternNode, AssignableNode, AttrAssignNode, BackRefNode, BeginNode, BlockArgNode, BlockPassNode, BreakNode, CallNode, CaseNode, ClassNode, ClassVarNode, Colon3Node, ConstNode, DefinedNode, DotNode, DVarNode, EncodingNode, EnsureNode, ErrorNode, EvStrNode, FalseNode, FCallNode, FindPatternNode, FlipNode, GlobalVarNode, HashNode, HashPatternNode, IfNode, InNode, InstVarNode, IterNode, KeywordArgNode, ListNode, LiteralNode, LocalVarNode, Match2Node, Match3Node, MatchNode, MethodDefNode, ModuleNode, NewlineNode, NextNode, NilNode, NilRestArgNode, NthRefNode, NumericNode, OpAsgnAndNode, OpAsgnConstDeclNode, OpAsgnNode, OpAsgnOrNode, OpElementAsgnNode, OptArgNode, OrNode, PatternCaseNode, RedoNode, RegexpNode, RequiredKeywordArgumentValueNode, RescueBodyNode, RescueNode, RetryNode, ReturnNode, RootNode, SClassNode, SelfNode, SplatNode, StarNode, StrNode, SuperNode, SValueNode, SymbolNode, TrueNode, UndefNode, UntilNode, VAliasNode, VCallNode, WhenNode, WhileNode, XStrNode, YieldNode, ZSuperNode

public abstract class Node extends Object
Base class for all Nodes in the AST
  • Field Details

    • containsVariableAssignment

      protected boolean containsVariableAssignment
    • newline

      protected boolean newline
  • Constructor Details

    • Node

      public Node(int line, boolean containsAssignment)
  • Method Details

    • setNewline

      public void setNewline()
    • unsetNewline

      public void unsetNewline()
    • isNewline

      public boolean isNewline()
    • getLine

      public int getLine()
    • getFile

      public String getFile()
    • setLine

      public void setLine(int line)
    • accept

      public abstract <T> T accept(NodeVisitor<T> visitor)
    • childNodes

      public abstract List<Node> childNodes()
    • createList

      protected static List<Node> createList(Node node)
    • createList

      protected static List<Node> createList(Node node1, Node node2)
    • createList

      protected static List<Node> createList(Node node1, Node node2, Node node3)
    • createList

      protected static List<Node> createList(Node... nodes)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toStringExtraInfo

      public String toStringExtraInfo()
      Not all interesting info in the AST is from Node data. This method will print out anything else of note (e.g. FixnumNode's long value).
      Returns:
      null for no extra info or something otherwise.
    • toString

      public String toString(boolean indent, int indentation)
    • toStringInternal

      protected String toStringInternal()
      Overridden by nodes that have additional internal state to be displated in toString.

      For nodes that have it, name is handled separately, by implementing INameNode.

      Child nodes are handled via iterating #childNodes.

      Returns:
      A string representing internal node state, or null if none.
    • getNodeName

      protected String getNodeName()
    • getNodeType

      public abstract NodeType getNodeType()
      Returns:
      the nodeId
    • isNil

      public boolean isNil()
      Whether the node evaluates to nil and has no side effects.
      Returns:
      true if nil, false otherwise
    • needsDefinitionCheck

      public boolean needsDefinitionCheck()
      Check whether the given node is considered always "defined" or whether it has some form of definition check.
      Returns:
      Whether the type of node represents a possibly undefined construct
    • containsVariableAssignment

      public boolean containsVariableAssignment()
      Does this node or one of its children contain an assignment?
    • executesOnce

      public boolean executesOnce()
      Returns:
      is it possible this node will execute only once. Note: This is not comprehensive. It is used to look from root node down to class/module nodes to make sure that narrow case can execute once. It is possible much deeper down the tree some nodes can only execute once but it will be marked as false because that case is not what this is for.