org.mozilla.javascript

## Class Node

- java.lang.Object
- - org.mozilla.javascript.Node

- All Implemented Interfaces:
    java.lang.Iterable<Node>
  Direct Known Subclasses:
    AstNode

      public class Node
      extends java.lang.Object
      implements java.lang.Iterable<Node>

  This class implements the root of the intermediate representation.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `class` | `Node.NodeIterator` Iterates over the children of this Node.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `ARROW_FUNCTION_PROP`
    `static int` | `ATTRIBUTE_FLAG`
    `static int` | `BOTH`
    `static int` | `CASEARRAY_PROP`
    `static int` | `CATCH_SCOPE_PROP`
    `static int` | `CONTROL_BLOCK_PROP`
    `static int` | `DECR_FLAG`
    `static int` | `DESCENDANTS_FLAG`
    `static int` | `DESTRUCTURING_ARRAY_LENGTH`
    `static int` | `DESTRUCTURING_NAMES`
    `static int` | `DESTRUCTURING_PARAMS`
    `static int` | `DESTRUCTURING_SHORTHAND`
    `static int` | `DIRECTCALL_PROP`
    `static int` | `END_DROPS_OFF`
    `static int` | `END_RETURNS`
    `static int` | `END_RETURNS_VALUE`
    `static int` | `END_UNREACHED` These flags enumerate the possible ways a statement/function can terminate.
    `static int` | `END_YIELDS`
    `static int` | `EXPRESSION_CLOSURE_PROP`
    `protected Node` | `first`
    `static int` | `FUNCTION_PROP`
    `static int` | `GENERATOR_END_PROP`
    `static int` | `INCRDECR_PROP`
    `static int` | `ISNUMBER_PROP`
    `static int` | `JSDOC_PROP`
    `static int` | `LABEL_ID_PROP`
    `protected Node` | `last`
    `static int` | `LAST_PROP`
    `static int` | `LEFT`
    `protected int` | `lineno`
    `static int` | `LOCAL_BLOCK_PROP`
    `static int` | `LOCAL_PROP`
    `static int` | `MEMBER_TYPE_PROP`
    `static int` | `NAME_PROP`
    `protected Node` | `next`
    `static int` | `NON_SPECIALCALL`
    `static int` | `OBJECT_IDS_PROP`
    `static int` | `PARENTHESIZED_PROP`
    `static int` | `POST_FLAG`
    `static int` | `PROPERTY_FLAG`
    `protected org.mozilla.javascript.Node.PropListItem` | `propListHead` Linked list of properties.
    `static int` | `REGEXP_PROP`
    `static int` | `RIGHT`
    `static int` | `SKIP_INDEXES_PROP`
    `static int` | `SPECIALCALL_EVAL`
    `static int` | `SPECIALCALL_PROP`
    `static int` | `SPECIALCALL_WITH`
    `static int` | `TARGETBLOCK_PROP`
    `protected int` | `type`
    `static int` | `VARIABLE_PROP`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Node(int nodeType)`
    `Node(int nodeType, int line)`
    `Node(int nodeType, Node child)`
    `Node(int nodeType, Node child, int line)`
    `Node(int nodeType, Node left, Node right)`
    `Node(int nodeType, Node left, Node right, int line)`
    `Node(int nodeType, Node left, Node mid, Node right)`
    `Node(int nodeType, Node left, Node mid, Node right, int line)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addChildAfter(Node newChild, Node node)` Add 'child' after 'node'.
    `void` | `addChildBefore(Node newChild, Node node)` Add 'child' before 'node'.
    `void` | `addChildrenToBack(Node children)`
    `void` | `addChildrenToFront(Node children)`
    `void` | `addChildToBack(Node child)`
    `void` | `addChildToFront(Node child)`
    `Node` | `getChildBefore(Node child)`
    `double` | `getDouble()` Can only be called when `getType() == Token.NUMBER`
    `int` | `getExistingIntProp(int propType)`
    `Node` | `getFirstChild()`
    `int` | `getIntProp(int propType, int defaultValue)`
    `java.lang.String` | `getJsDoc()` Gets the JsDoc comment string attached to this node.
    `Comment` | `getJsDocNode()` Gets the JsDoc Comment object attached to this node.
    `Node` | `getLastChild()`
    `Node` | `getLastSibling()`
    `int` | `getLineno()` Return the line number recorded for this node.
    `Node` | `getNext()`
    `java.lang.Object` | `getProp(int propType)`
    `Scope` | `getScope()` Can only be called when node has String context.
    `java.lang.String` | `getString()` Can only be called when node has String context.
    `int` | `getType()`
    `boolean` | `hasChildren()`
    `boolean` | `hasConsistentReturnUsage()` Checks that every return usage in a function body is consistent with the requirements of strict-mode.
    `boolean` | `hasSideEffects()`
    `java.util.Iterator<Node>` | `iterator()` Returns an `Iterator` over the node's children.
    `int` | `labelId()`
    `void` | `labelId(int labelId)`
    `static Node` | `newNumber(double number)`
    `static Node` | `newString(int type, java.lang.String str)`
    `static Node` | `newString(java.lang.String str)`
    `static Node` | `newTarget()`
    `void` | `putIntProp(int propType, int prop)`
    `void` | `putProp(int propType, java.lang.Object prop)`
    `void` | `removeChild(Node child)`
    `void` | `removeChildren()`
    `void` | `removeProp(int propType)`
    `void` | `replaceChild(Node child, Node newChild)`
    `void` | `replaceChildAfter(Node prevChild, Node newChild)`
    `void` | `resetTargets()` Recursively unlabel every TARGET or YIELD node in the tree.
    `void` | `setDouble(double number)`
    `void` | `setJsDocNode(Comment jsdocNode)` Sets the JsDoc comment string attached to this node.
    `void` | `setLineno(int lineno)`
    `void` | `setScope(Scope s)` Can only be called when node has String context.
    `void` | `setString(java.lang.String s)` Can only be called when node has String context.
    `Node` | `setType(int type)` Sets the node type and returns this node.
    `java.lang.String` | `toString()`
    `java.lang.String` | `toStringTree(ScriptNode treeTop)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface java.lang.Iterable

      `forEach, spliterator`

- - ### Field Detail

    - #### FUNCTION_PROP

          public static final int FUNCTION_PROP

      See Also:
        Constant Field Values

    - #### LOCAL_PROP

          public static final int LOCAL_PROP

      See Also:
        Constant Field Values

    - #### LOCAL_BLOCK_PROP

          public static final int LOCAL_BLOCK_PROP

      See Also:
        Constant Field Values

    - #### REGEXP_PROP

          public static final int REGEXP_PROP

      See Also:
        Constant Field Values

    - #### CASEARRAY_PROP

          public static final int CASEARRAY_PROP

      See Also:
        Constant Field Values

    - #### TARGETBLOCK_PROP

          public static final int TARGETBLOCK_PROP

      See Also:
        Constant Field Values

    - #### VARIABLE_PROP

          public static final int VARIABLE_PROP

      See Also:
        Constant Field Values

    - #### ISNUMBER_PROP

          public static final int ISNUMBER_PROP

      See Also:
        Constant Field Values

    - #### DIRECTCALL_PROP

          public static final int DIRECTCALL_PROP

      See Also:
        Constant Field Values

    - #### SPECIALCALL_PROP

          public static final int SPECIALCALL_PROP

      See Also:
        Constant Field Values

    - #### SKIP_INDEXES_PROP

          public static final int SKIP_INDEXES_PROP

      See Also:
        Constant Field Values

    - #### OBJECT_IDS_PROP

          public static final int OBJECT_IDS_PROP

      See Also:
        Constant Field Values

    - #### INCRDECR_PROP

          public static final int INCRDECR_PROP

      See Also:
        Constant Field Values

    - #### CATCH_SCOPE_PROP

          public static final int CATCH_SCOPE_PROP

      See Also:
        Constant Field Values

    - #### LABEL_ID_PROP

          public static final int LABEL_ID_PROP

      See Also:
        Constant Field Values

    - #### MEMBER_TYPE_PROP

          public static final int MEMBER_TYPE_PROP

      See Also:
        Constant Field Values

    - #### NAME_PROP

          public static final int NAME_PROP

      See Also:
        Constant Field Values

    - #### CONTROL_BLOCK_PROP

          public static final int CONTROL_BLOCK_PROP

      See Also:
        Constant Field Values

    - #### PARENTHESIZED_PROP

          public static final int PARENTHESIZED_PROP

      See Also:
        Constant Field Values

    - #### GENERATOR_END_PROP

          public static final int GENERATOR_END_PROP

      See Also:
        Constant Field Values

    - #### DESTRUCTURING_ARRAY_LENGTH

          public static final int DESTRUCTURING_ARRAY_LENGTH

      See Also:
        Constant Field Values

    - #### DESTRUCTURING_NAMES

          public static final int DESTRUCTURING_NAMES

      See Also:
        Constant Field Values

    - #### DESTRUCTURING_PARAMS

          public static final int DESTRUCTURING_PARAMS

      See Also:
        Constant Field Values

    - #### JSDOC_PROP

          public static final int JSDOC_PROP

      See Also:
        Constant Field Values

    - #### EXPRESSION_CLOSURE_PROP

          public static final int EXPRESSION_CLOSURE_PROP

      See Also:
        Constant Field Values

    - #### DESTRUCTURING_SHORTHAND

          public static final int DESTRUCTURING_SHORTHAND

      See Also:
        Constant Field Values

    - #### ARROW_FUNCTION_PROP

          public static final int ARROW_FUNCTION_PROP

      See Also:
        Constant Field Values

    - #### LAST_PROP

          public static final int LAST_PROP

      See Also:
        Constant Field Values

    - #### BOTH

          public static final int BOTH

      See Also:
        Constant Field Values

    - #### LEFT

          public static final int LEFT

      See Also:
        Constant Field Values

    - #### RIGHT

          public static final int RIGHT

      See Also:
        Constant Field Values

    - #### NON_SPECIALCALL

          public static final int NON_SPECIALCALL

      See Also:
        Constant Field Values

    - #### SPECIALCALL_EVAL

          public static final int SPECIALCALL_EVAL

      See Also:
        Constant Field Values

    - #### SPECIALCALL_WITH

          public static final int SPECIALCALL_WITH

      See Also:
        Constant Field Values

    - #### DECR_FLAG

          public static final int DECR_FLAG

      See Also:
        Constant Field Values

    - #### POST_FLAG

          public static final int POST_FLAG

      See Also:
        Constant Field Values

    - #### PROPERTY_FLAG

          public static final int PROPERTY_FLAG

      See Also:
        Constant Field Values

    - #### ATTRIBUTE_FLAG

          public static final int ATTRIBUTE_FLAG

      See Also:
        Constant Field Values

    - #### DESCENDANTS_FLAG

          public static final int DESCENDANTS_FLAG

      See Also:
        Constant Field Values

    - #### END_UNREACHED

          public static final int END_UNREACHED

      These flags enumerate the possible ways a statement/function can terminate. These flags are used by endCheck() and by the Parser to detect inconsistent return usage. END_UNREACHED is reserved for code paths that are assumed to always be able to execute (example: throw, continue) END_DROPS_OFF indicates if the statement can transfer control to the next one. Statement such as return dont. A compound statement may have some branch that drops off control to the next statement. END_RETURNS indicates that the statement can return (without arguments) END_RETURNS_VALUE indicates that the statement can return a value. A compound statement such as if (condition) { return value; } Will be detected as (END_DROPS_OFF | END_RETURN_VALUE) by endCheck()
      See Also:
        Constant Field Values

    - #### END_DROPS_OFF

          public static final int END_DROPS_OFF

      See Also:
        Constant Field Values

    - #### END_RETURNS

          public static final int END_RETURNS

      See Also:
        Constant Field Values

    - #### END_RETURNS_VALUE

          public static final int END_RETURNS_VALUE

      See Also:
        Constant Field Values

    - #### END_YIELDS

          public static final int END_YIELDS

      See Also:
        Constant Field Values

    - #### type

          protected int type

    - #### next

          protected Node next

    - #### first

          protected Node first

    - #### last

          protected Node last

    - #### lineno

          protected int lineno

    - #### propListHead

          protected org.mozilla.javascript.Node.PropListItem propListHead

      Linked list of properties. Since vast majority of nodes would have no more then 2 properties, linked list saves memory and provides fast lookup. If this does not holds, propListHead can be replaced by UintMap.

  - ### Constructor Detail

    - #### Node

          public Node(int nodeType)

    - #### Node

          public Node(int nodeType,
                      Node child)

    - #### Node

          public Node(int nodeType,
                      Node left,
                      Node right)

    - #### Node

          public Node(int nodeType,
                      Node left,
                      Node mid,
                      Node right)

    - #### Node

          public Node(int nodeType,
                      int line)

    - #### Node

          public Node(int nodeType,
                      Node child,
                      int line)

    - #### Node

          public Node(int nodeType,
                      Node left,
                      Node right,
                      int line)

    - #### Node

          public Node(int nodeType,
                      Node left,
                      Node mid,
                      Node right,
                      int line)

  - ### Method Detail

    - #### newNumber

          public static Node newNumber(double number)

    - #### newString

          public static Node newString(java.lang.String str)

    - #### newString

          public static Node newString(int type,
                                       java.lang.String str)

    - #### getType

          public int getType()

    - #### setType

          public Node setType(int type)

      Sets the node type and returns this node.

    - #### getJsDoc

          public java.lang.String getJsDoc()

      Gets the JsDoc comment string attached to this node.
      Returns:
        the comment string or `null` if no JsDoc is attached to this node

    - #### getJsDocNode

          public Comment getJsDocNode()

      Gets the JsDoc Comment object attached to this node.
      Returns:
        the Comment or `null` if no JsDoc is attached to this node

    - #### setJsDocNode

          public void setJsDocNode(Comment jsdocNode)

      Sets the JsDoc comment string attached to this node.

    - #### hasChildren

          public boolean hasChildren()

    - #### getFirstChild

          public Node getFirstChild()

    - #### getLastChild

          public Node getLastChild()

    - #### getNext

          public Node getNext()

    - #### getChildBefore

          public Node getChildBefore(Node child)

    - #### getLastSibling

          public Node getLastSibling()

    - #### addChildToFront

          public void addChildToFront(Node child)

    - #### addChildToBack

          public void addChildToBack(Node child)

    - #### addChildrenToFront

          public void addChildrenToFront(Node children)

    - #### addChildrenToBack

          public void addChildrenToBack(Node children)

    - #### addChildBefore

          public void addChildBefore(Node newChild,
                                     Node node)

      Add 'child' before 'node'.

    - #### addChildAfter

          public void addChildAfter(Node newChild,
                                    Node node)

      Add 'child' after 'node'.

    - #### removeChild

          public void removeChild(Node child)

    - #### replaceChild

          public void replaceChild(Node child,
                                   Node newChild)

    - #### replaceChildAfter

          public void replaceChildAfter(Node prevChild,
                                        Node newChild)

    - #### removeChildren

          public void removeChildren()

    - #### iterator

          public java.util.Iterator<Node> iterator()

      Returns an `Iterator` over the node's children.
      Specified by:
        `iterator` in interface `java.lang.Iterable<Node>`

    - #### removeProp

          public void removeProp(int propType)

    - #### getProp

          public java.lang.Object getProp(int propType)

    - #### getIntProp

          public int getIntProp(int propType,
                                int defaultValue)

    - #### getExistingIntProp

          public int getExistingIntProp(int propType)

    - #### putProp

          public void putProp(int propType,
                              java.lang.Object prop)

    - #### putIntProp

          public void putIntProp(int propType,
                                 int prop)

    - #### getLineno

          public int getLineno()

      Return the line number recorded for this node.
      Returns:
        the line number

    - #### setLineno

          public void setLineno(int lineno)

    - #### getDouble

          public final double getDouble()

      Can only be called when `getType() == Token.NUMBER`

    - #### setDouble

          public final void setDouble(double number)

    - #### getString

          public final java.lang.String getString()

      Can only be called when node has String context.

    - #### setString

          public final void setString(java.lang.String s)

      Can only be called when node has String context.

    - #### getScope

          public Scope getScope()

      Can only be called when node has String context.

    - #### setScope

          public void setScope(Scope s)

      Can only be called when node has String context.

    - #### newTarget

          public static Node newTarget()

    - #### labelId

          public final int labelId()

    - #### labelId

          public void labelId(int labelId)

    - #### hasConsistentReturnUsage

          public boolean hasConsistentReturnUsage()

      Checks that every return usage in a function body is consistent with the requirements of strict-mode.
      Returns:
        true if the function satisfies strict mode requirement.

    - #### hasSideEffects

          public boolean hasSideEffects()

    - #### resetTargets

          public void resetTargets()

      Recursively unlabel every TARGET or YIELD node in the tree. This is used and should only be used for inlining finally blocks where jsr instructions used to be. It is somewhat hackish, but implementing a clone() operation would take much, much more effort. This solution works for inlining finally blocks because you should never be writing any given block to the class file simultaneously. Therefore, an unlabeling will never occur in the middle of a block.

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

    - #### toStringTree

          public java.lang.String toStringTree(ScriptNode treeTop)