Package org.jruby.ast

Class ListNode

java.lang.Object
org.jruby.ast.Node
org.jruby.ast.ListNode
All Implemented Interfaces:
Iterable<Node>
Direct Known Subclasses:
ArrayNode, BlockNode, DNode, ZArrayNode

public class ListNode extends Node implements Iterable<Node>
All Nodes which have a list representation inherit this. This is also used as generic container for additional information that is not directly evaluated. In particular, f_arg production rule uses this to capture arg information for the editor projects who want position info saved.
  • Field Details

    • EMPTY

      private static final Node[] EMPTY
    • INITIAL_SIZE

      private static final int INITIAL_SIZE
      See Also:
    • list

      private Node[] list
    • size

      private int size
    • single

      private Node single
      This is used to reduce the need to allocate an array for the many single-element ListNode instances in a typical Ruby app. The methods below detect if single has been set and act accordingly, expanding it to an array lazily only when needed.
  • Constructor Details

    • ListNode

      public ListNode(int line, Node firstNode)
      Create a new ListNode.
      Parameters:
      line - where list is
      firstNode - first element of the list
    • ListNode

      public ListNode(int line)
  • Method Details

    • getNodeType

      public NodeType getNodeType()
      Specified by:
      getNodeType in class Node
      Returns:
      the nodeId
    • growList

      private Node[] growList(int mustBeDelta)
    • addInternal

      protected void addInternal(Node node)
    • addAllInternal

      protected void addAllInternal(ListNode other)
    • addToSingle

      private void addToSingle(Node single, Node node)
    • arrayifySingle

      private Node[] arrayifySingle(Node single)
    • add

      public ListNode add(Node node)
    • size

      public int size()
    • addAll

      public ListNode addAll(ListNode other)
      Add all elements in other list to this list node.
      Parameters:
      other - list which has elements
      Returns:
      this instance for method chaining
    • addAll

      public ListNode addAll(Node[] other, int index, int length)
    • addAll

      public ListNode addAll(Node other)
      Add other element to this list
      Parameters:
      other - list which has elements
      Returns:
      this instance for method chaining
    • getLast

      public Node getLast()
    • isEmpty

      public boolean isEmpty()
    • children

      public Node[] children()
    • childNodes

      @Deprecated public List<Node> childNodes()
      Deprecated.
      Specified by:
      childNodes in class Node
    • accept

      public <T> T accept(NodeVisitor<T> visitor)
      Specified by:
      accept in class Node
    • get

      public Node get(int idx)
    • iterator

      public Iterator<Node> iterator()
      Specified by:
      iterator in interface Iterable<Node>