org.eclipse.wst.jsdt.core.dom

## Class ASTNode

- java.lang.Object
- - org.eclipse.wst.jsdt.core.dom.ASTNode

Direct Known Subclasses:
  AnonymousClassDeclaration, CatchClause, Comment, ExportDeclaration, Expression, FunctionRef, FunctionRefParameter, ImportDeclaration, JavaScriptUnit, MemberRef, Modifier, ModuleSpecifier, PackageDeclaration, ProgramElement, TagElement, TemplateElement, TextElement, Type, VariableDeclaration

    public abstract class ASTNode
    extends java.lang.Object

Abstract superclass of all Abstract Syntax Tree (AST) node types.

An AST node represents a JavaScript source code construct, such as a name, type, expression, statement, or declaration.

Each AST node belongs to a unique AST instance, called the owning AST. The children of an AST node always have the same owner as their parent node. If a node from one AST is to be added to a different AST, the subtree must be cloned first to ensure that the added nodes have the correct owning AST.

When an AST node is part of an AST, it has a unique parent node. Clients can navigate upwards, from child to parent, as well as downwards, from parent to child. Newly created nodes are unparented. When an unparented node is set as a child of a node (using a `setCHILD` method), its parent link is set automatically and the parent link of the former child is set to `null`. For nodes with properties that include a list of children (for example, `Block` whose `statements` property is a list of statements), adding or removing an element to/for the list property automatically updates the parent links. These lists support the `List.set` method; however, the constraint that the same node cannot appear more than once means that this method cannot be used to swap elements without first removing the node.

ASTs must not contain cycles. All operations that could create a cycle detect this possibility and fail.

ASTs do not contain "holes" (missing subtrees). If a node is required to have a certain property, a syntactically plausible initial value is always supplied.

The hierarchy of AST node types has some convenient groupings marked by abstract superclasses:

- expressions - `Expression`
- names - `Name` (a sub-kind of expression)
- statements - `Statement`
- types - `Type`
- type body declarations - `BodyDeclaration`

Abstract syntax trees may be hand constructed by clients, using the `newTYPE` factory methods (see `AST`) to create new nodes, and the various `setCHILD` methods to connect them together.

The class `ASTParser` parses a string containing a JavaScript source code and returns an abstract syntax tree for it. The resulting nodes carry source ranges relating the node back to the original source characters. The source range covers the construct as a whole.

Each AST node carries bit flags, which may convey additional information about the node. For instance, the parser uses a flag to indicate a syntax error. Newly created nodes have no flags set.

Each AST node is capable of carrying an open-ended collection of client-defined properties. Newly created nodes have none. `getProperty` and `setProperty` are used to access these properties.

AST nodes are thread-safe for readers provided there are no active writers. If one thread is modifying an AST, including creating new nodes or cloning existing ones, it is not safe for another thread to read, visit, write, create, or clone any of the nodes on the same AST. When synchronization is required, consider using the common AST object that owns the node; that is, use `synchronize (node.getAST()) {...}`.

ASTs also support the visitor pattern; see the class `ASTVisitor` for details.

JavaScript units created by `ASTParser` from a source document can be serialized after arbitrary modifications with minimal loss of original formatting. See `JavaScriptUnit.recordModifications()` for details. See also `ASTRewrite` for an alternative way to describe and serialize changes to a read-only AST.

This class is not intended to be subclassed by clients.

See Also:
  `ASTParser`, `Provisional API: This class/interface is part of an interim API that is still under development and expected to change significantly before reaching stability. It is being made available at this early stage to solicit feedback from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken (repeatedly) as the API evolves.`

### Field Summary

Fields
`static int` `ANONYMOUS_CLASS_DECLARATION` Node type constant indicating a node of type `AnonymousClassDeclaration`.
`static int` `ARRAY_ACCESS` Node type constant indicating a node of type `ArrayAccess`.
`static int` `ARRAY_CREATION` Node type constant indicating a node of type `ArrayCreation`.
`static int` `ARRAY_INITIALIZER` Node type constant indicating a node of type `ArrayInitializer`.
`static int` `ARRAY_NAME`
`static int` `ARRAY_TYPE` Node type constant indicating a node of type `ArrayType`.
`static int` `ARROW_FUNCTION_EXPRESSION`
`static int` `ASSIGNMENT` Node type constant indicating a node of type `Assignment`.
`static int` `ASSIGNMENT_NAME`
`static int` `BLOCK` Node type constant indicating a node of type `Block`.
`static int` `BLOCK_COMMENT` Node type constant indicating a node of type `BlockComment`.
`static int` `BOOLEAN_LITERAL` Node type constant indicating a node of type `BooleanLiteral`.
`static int` `BREAK_STATEMENT` Node type constant indicating a node of type `BreakStatement`.
`static int` `CATCH_CLAUSE` Node type constant indicating a node of type `CatchClause`.
`static int` `CHARACTER_LITERAL` Node type constant indicating a node of type `CharacterLiteral`.
`static int` `CLASS_INSTANCE_CREATION` Node type constant indicating a node of type `ClassInstanceCreation`.
`static int` `CONDITIONAL_EXPRESSION` Node type constant indicating a node of type `ConditionalExpression`.
`static int` `CONSTRUCTOR_INVOCATION` Node type constant indicating a node of type `ConstructorInvocation`.
`static int` `CONTINUE_STATEMENT` Node type constant indicating a node of type `ContinueStatement`.
`static int` `DEBUGGER_STATEMENT`
`static int` `DO_STATEMENT` Node type constant indicating a node of type `DoStatement`.
`static int` `EMPTY_EXPRESSION`
`static int` `EMPTY_STATEMENT` Node type constant indicating a node of type `EmptyStatement`.
`static int` `ENHANCED_FOR_STATEMENT` Node type constant indicating a node of type `EnhancedForStatement`.
`static int` `EXPORT_DECLARATION`
`static int` `EXPRESSION_STATEMENT` Node type constant indicating a node of type `ExpressionStatement`.
`static int` `FIELD_ACCESS` Node type constant indicating a node of type `FieldAccess`.
`static int` `FIELD_DECLARATION` Node type constant indicating a node of type `FieldDeclaration`.
`static int` `FOR_IN_STATEMENT`
`static int` `FOR_OF_STATEMENT`
`static int` `FOR_STATEMENT` Node type constant indicating a node of type `ForStatement`.
`static int` `FUNCTION_DECLARATION` Node type constant indicating a node of type `FunctionDeclaration`.
`static int` `FUNCTION_DECLARATION_STATEMENT`
`static int` `FUNCTION_EXPRESSION`
`static int` `FUNCTION_INVOCATION` Node type constant indicating a node of type `FunctionInvocation`.
`static int` `FUNCTION_REF` Node type constant indicating a node of type `FunctionRef`.
`static int` `FUNCTION_REF_PARAMETER` Node type constant indicating a node of type `FunctionRefParameter`.
`static int` `IF_STATEMENT` Node type constant indicating a node of type `IfStatement`.
`static int` `IMPORT_DECLARATION` Node type constant indicating a node of type `ImportDeclaration`.
`static int` `INFERRED_TYPE`
`static int` `INFIX_EXPRESSION` Node type constant indicating a node of type `InfixExpression`.
`static int` `INITIALIZER` Node type constant indicating a node of type `Initializer`.
`static int` `INSTANCEOF_EXPRESSION` Node type constant indicating a node of type `InstanceofExpression`.
`static int` `JAVASCRIPT_UNIT` Node type constant indicating a node of type `JavaScriptUnit`.
`static int` `JSDOC` Node type constant indicating a node of type `Javadoc`.
`static int` `LABELED_STATEMENT` Node type constant indicating a node of type `LabeledStatement`.
`static int` `LINE_COMMENT` Node type constant indicating a node of type `LineComment`.
`static int` `LIST_EXPRESSION`
`static int` `MALFORMED` Flag constant (bit mask, value 1) indicating that there is something not quite right with this AST node.
`static int` `MEMBER_REF` Node type constant indicating a node of type `MemberRef`.
`static int` `META_PROPERTY`
`static int` `MODIFIER` Node type constant indicating a node of type `Modifier`.
`static int` `MODULE_SPECIFIER`
`static int` `NULL_LITERAL` Node type constant indicating a node of type `NullLiteral`.
`static int` `NUMBER_LITERAL` Node type constant indicating a node of type `NumberLiteral`.
`static int` `OBJECT_LITERAL`
`static int` `OBJECT_LITERAL_FIELD`
`static int` `OBJECT_NAME`
`static int` `ORIGINAL` Flag constant (bit mask, value 2) indicating that this is a node that was created by the parser (as opposed to one created by another party).
`static int` `PACKAGE_DECLARATION` Node type constant indicating a node of type `PackageDeclaration`.
`static int` `PARENTHESIZED_EXPRESSION` Node type constant indicating a node of type `ParenthesizedExpression`.
`static int` `POSTFIX_EXPRESSION` Node type constant indicating a node of type `PostfixExpression`.
`static int` `PREFIX_EXPRESSION` Node type constant indicating a node of type `PrefixExpression`.
`static int` `PRIMITIVE_TYPE` Node type constant indicating a node of type `PrimitiveType`.
`static int` `PROTECT` Flag constant (bit mask, value 4) indicating that this node is unmodifiable.
`static int` `QUALIFIED_NAME` Node type constant indicating a node of type `QualifiedName`.
`static int` `QUALIFIED_TYPE` Node type constant indicating a node of type `QualifiedType`.
`static int` `RECOVERED` Flag constant (bit mask, value 8) indicating that this node or a part of this node is recovered from source that contains a syntax error detected in the vicinity.
`static int` `REGULAR_EXPRESSION_LITERAL`
`static int` `REST_ELEMENT_NAME`
`static int` `RETURN_STATEMENT` Node type constant indicating a node of type `ReturnStatement`.
`static int` `SIMPLE_NAME` Node type constant indicating a node of type `SimpleName`.
`static int` `SIMPLE_TYPE` Node type constant indicating a node of type `SimpleType`.
`static int` `SINGLE_VARIABLE_DECLARATION` Node type constant indicating a node of type `SingleVariableDeclaration`.
`static int` `SPREAD_ELEMENT`
`static int` `STRING_LITERAL` Node type constant indicating a node of type `StringLiteral`.
`static int` `SUPER_CONSTRUCTOR_INVOCATION` Node type constant indicating a node of type `SuperConstructorInvocation`.
`static int` `SUPER_FIELD_ACCESS` Node type constant indicating a node of type `SuperFieldAccess`.
`static int` `SUPER_METHOD_INVOCATION` Node type constant indicating a node of type `SuperMethodInvocation`.
`static int` `SWITCH_CASE` Node type constant indicating a node of type `SwitchCase`.
`static int` `SWITCH_STATEMENT` Node type constant indicating a node of type `SwitchStatement`.
`static int` `TAG_ELEMENT` Node type constant indicating a node of type `TagElement`.
`static int` `TEMPLATE_ELEMENT`
`static int` `TEMPLATE_LITERAL`
`static int` `TEXT_ELEMENT` Node type constant indicating a node of type `TextElement`.
`static int` `THIS_EXPRESSION` Node type constant indicating a node of type `ThisExpression`.
`static int` `THROW_STATEMENT` Node type constant indicating a node of type `ThrowStatement`.
`static int` `TRY_STATEMENT` Node type constant indicating a node of type `TryStatement`.
`static int` `TYPE_DECLARATION` Node type constant indicating a node of type `TypeDeclaration`.
`static int` `TYPE_DECLARATION_EXPRESSION`
`static int` `TYPE_DECLARATION_STATEMENT` Node type constant indicating a node of type `TypeDeclarationStatement`.
`static int` `TYPE_LITERAL` Node type constant indicating a node of type `TypeLiteral`.
`static int` `UNDEFINED_LITERAL`
`static int` `VARIABLE_DECLARATION_EXPRESSION` Node type constant indicating a node of type `VariableDeclarationExpression`.
`static int` `VARIABLE_DECLARATION_FRAGMENT` Node type constant indicating a node of type `VariableDeclarationFragment`.
`static int` `VARIABLE_DECLARATION_STATEMENT` Node type constant indicating a node of type `VariableDeclarationStatement`.
`static int` `WHILE_STATEMENT` Node type constant indicating a node of type `WhileStatement`.
`static int` `WITH_STATEMENT`
`static int` `YIELD_EXPRESSION`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`void` `accept(ASTVisitor visitor)` Accepts the given visitor on a visit of the current node.
`static ASTNode` `copySubtree(AST target, ASTNode node)` Returns a deep copy of the subtree of AST nodes rooted at the given node.
`static java.util.List` `copySubtrees(AST target, java.util.List nodes)` Returns a deep copy of the subtrees of AST nodes rooted at the given list of nodes.
`void` `delete()` Removes this node from its parent.
`boolean` `equals(java.lang.Object obj)` The `ASTNode` implementation of this `Object` method uses object identity (==).
`AST` `getAST()` Returns this node's AST.
`ASTNode` `getBodyChild()`
`int` `getFlags()` Returns the flags associated with this node.
`int` `getLength()` Returns the length in characters of the original source file indicating where the source fragment corresponding to this node ends.
`StructuralPropertyDescriptor` `getLocationInParent()` Returns the location of this node within its parent, or `null` if this is a root node.
`int` `getNodeType()` Returns an integer value identifying the type of this concrete AST node.
`ASTNode` `getParent()` Returns this node's parent node, or `null` if this is the root node.
`java.lang.Object` `getProperty(java.lang.String propertyName)` Returns the named property of this node, or `null` if none.
`ASTNode` `getRoot()` Returns the root node at or above this node; returns this node if it is a root.
`int` `getStartPosition()` Returns the character index into the original source file indicating where the source fragment corresponding to this node begins.
`java.lang.Object` `getStructuralProperty(StructuralPropertyDescriptor property)` Returns the value of the given structural property for this node.
`int` `hashCode()`
`static java.lang.Class` `nodeClassForType(int nodeType)` Returns the node class for the corresponding node type.
`java.util.Map` `properties()` Returns an unmodifiable table of the properties of this node with non-`null` values.
`void` `setFlags(int flags)` Sets the flags associated with this node to the given value.
`void` `setProperty(java.lang.String propertyName, java.lang.Object data)` Sets the named property of this node to the given value, or to `null` to clear it.
`void` `setSourceRange(int startPosition, int length)` Sets the source range of the original source file where the source fragment corresponding to this node was found.
`void` `setStructuralProperty(StructuralPropertyDescriptor property, java.lang.Object value)` Sets the value of the given structural property for this node.
`java.util.List` `structuralPropertiesForType()` Returns a list of structural property descriptors for nodes of the same type as this node.
`int` `subtreeBytes()` Returns an estimate of the memory footprint in bytes of the entire subtree rooted at this node.
`boolean` `subtreeMatch(ASTMatcher matcher, java.lang.Object other)` Returns whether the subtree rooted at the given node matches the given other object as decided by the given matcher.
`java.lang.String` `toString()` Returns a string representation of this node suitable for debugging purposes only.

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

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

### Field Detail

#### ANONYMOUS_CLASS_DECLARATION

    public static final int ANONYMOUS_CLASS_DECLARATION

Node type constant indicating a node of type `AnonymousClassDeclaration`.

See Also:
  `AnonymousClassDeclaration`, Constant Field Values

#### ARRAY_ACCESS

    public static final int ARRAY_ACCESS

Node type constant indicating a node of type `ArrayAccess`.

See Also:
  `ArrayAccess`, Constant Field Values

#### ARRAY_CREATION

    public static final int ARRAY_CREATION

Node type constant indicating a node of type `ArrayCreation`.

See Also:
  `ArrayCreation`, Constant Field Values

#### ARRAY_INITIALIZER

    public static final int ARRAY_INITIALIZER

Node type constant indicating a node of type `ArrayInitializer`.

See Also:
  `ArrayInitializer`, Constant Field Values

#### ARRAY_TYPE

    public static final int ARRAY_TYPE

Node type constant indicating a node of type `ArrayType`.

See Also:
  `ArrayType`, Constant Field Values

#### ASSIGNMENT

    public static final int ASSIGNMENT

Node type constant indicating a node of type `Assignment`.

See Also:
  `Assignment`, Constant Field Values

#### BLOCK

    public static final int BLOCK

Node type constant indicating a node of type `Block`.

See Also:
  `Block`, Constant Field Values

#### BOOLEAN_LITERAL

    public static final int BOOLEAN_LITERAL

Node type constant indicating a node of type `BooleanLiteral`.

See Also:
  `BooleanLiteral`, Constant Field Values

#### BREAK_STATEMENT

    public static final int BREAK_STATEMENT

Node type constant indicating a node of type `BreakStatement`.

See Also:
  `BreakStatement`, Constant Field Values

#### CATCH_CLAUSE

    public static final int CATCH_CLAUSE

Node type constant indicating a node of type `CatchClause`.

See Also:
  `CatchClause`, Constant Field Values

#### CHARACTER_LITERAL

    public static final int CHARACTER_LITERAL

Node type constant indicating a node of type `CharacterLiteral`.

See Also:
  `CharacterLiteral`, Constant Field Values

#### CLASS_INSTANCE_CREATION

    public static final int CLASS_INSTANCE_CREATION

Node type constant indicating a node of type `ClassInstanceCreation`.

See Also:
  `ClassInstanceCreation`, Constant Field Values

#### JAVASCRIPT_UNIT

    public static final int JAVASCRIPT_UNIT

Node type constant indicating a node of type `JavaScriptUnit`.

See Also:
  `JavaScriptUnit`, Constant Field Values

#### CONDITIONAL_EXPRESSION

    public static final int CONDITIONAL_EXPRESSION

Node type constant indicating a node of type `ConditionalExpression`.

See Also:
  `ConditionalExpression`, Constant Field Values

#### CONSTRUCTOR_INVOCATION

    public static final int CONSTRUCTOR_INVOCATION

Node type constant indicating a node of type `ConstructorInvocation`.

See Also:
  `ConstructorInvocation`, Constant Field Values

#### CONTINUE_STATEMENT

    public static final int CONTINUE_STATEMENT

Node type constant indicating a node of type `ContinueStatement`.

See Also:
  `ContinueStatement`, Constant Field Values

#### DO_STATEMENT

    public static final int DO_STATEMENT

Node type constant indicating a node of type `DoStatement`.

See Also:
  `DoStatement`, Constant Field Values

#### EMPTY_STATEMENT

    public static final int EMPTY_STATEMENT

Node type constant indicating a node of type `EmptyStatement`.

See Also:
  `EmptyStatement`, Constant Field Values

#### EXPRESSION_STATEMENT

    public static final int EXPRESSION_STATEMENT

Node type constant indicating a node of type `ExpressionStatement`.

See Also:
  `ExpressionStatement`, Constant Field Values

#### FIELD_ACCESS

    public static final int FIELD_ACCESS

Node type constant indicating a node of type `FieldAccess`.

See Also:
  `FieldAccess`, Constant Field Values

#### FIELD_DECLARATION

    public static final int FIELD_DECLARATION

Node type constant indicating a node of type `FieldDeclaration`.

See Also:
  `FieldDeclaration`, Constant Field Values

#### FOR_STATEMENT

    public static final int FOR_STATEMENT

Node type constant indicating a node of type `ForStatement`.

See Also:
  `ForStatement`, Constant Field Values

#### IF_STATEMENT

    public static final int IF_STATEMENT

Node type constant indicating a node of type `IfStatement`.

See Also:
  `IfStatement`, Constant Field Values

#### IMPORT_DECLARATION

    public static final int IMPORT_DECLARATION

Node type constant indicating a node of type `ImportDeclaration`.

See Also:
  `ImportDeclaration`, Constant Field Values

#### INFIX_EXPRESSION

    public static final int INFIX_EXPRESSION

Node type constant indicating a node of type `InfixExpression`.

See Also:
  `InfixExpression`, Constant Field Values

#### INITIALIZER

    public static final int INITIALIZER

Node type constant indicating a node of type `Initializer`.

See Also:
  `Initializer`, Constant Field Values

#### JSDOC

    public static final int JSDOC

Node type constant indicating a node of type `Javadoc`.

See Also:
  `JSdoc`, Constant Field Values

#### LABELED_STATEMENT

    public static final int LABELED_STATEMENT

Node type constant indicating a node of type `LabeledStatement`.

See Also:
  `LabeledStatement`, Constant Field Values

#### FUNCTION_DECLARATION

    public static final int FUNCTION_DECLARATION

Node type constant indicating a node of type `FunctionDeclaration`.

See Also:
  `FunctionDeclaration`, Constant Field Values

#### FUNCTION_INVOCATION

    public static final int FUNCTION_INVOCATION

Node type constant indicating a node of type `FunctionInvocation`.

See Also:
  `FunctionInvocation`, Constant Field Values

#### NULL_LITERAL

    public static final int NULL_LITERAL

Node type constant indicating a node of type `NullLiteral`.

See Also:
  `NullLiteral`, Constant Field Values

#### NUMBER_LITERAL

    public static final int NUMBER_LITERAL

Node type constant indicating a node of type `NumberLiteral`.

See Also:
  `NumberLiteral`, Constant Field Values

#### PACKAGE_DECLARATION

    public static final int PACKAGE_DECLARATION

Node type constant indicating a node of type `PackageDeclaration`.

See Also:
  `PackageDeclaration`, Constant Field Values

#### PARENTHESIZED_EXPRESSION

    public static final int PARENTHESIZED_EXPRESSION

Node type constant indicating a node of type `ParenthesizedExpression`.

See Also:
  `ParenthesizedExpression`, Constant Field Values

#### POSTFIX_EXPRESSION

    public static final int POSTFIX_EXPRESSION

Node type constant indicating a node of type `PostfixExpression`.

See Also:
  `PostfixExpression`, Constant Field Values

#### PREFIX_EXPRESSION

    public static final int PREFIX_EXPRESSION

Node type constant indicating a node of type `PrefixExpression`.

See Also:
  `PrefixExpression`, Constant Field Values

#### PRIMITIVE_TYPE

    public static final int PRIMITIVE_TYPE

Node type constant indicating a node of type `PrimitiveType`.

See Also:
  `PrimitiveType`, Constant Field Values

#### QUALIFIED_NAME

    public static final int QUALIFIED_NAME

Node type constant indicating a node of type `QualifiedName`.

See Also:
  `QualifiedName`, Constant Field Values

#### RETURN_STATEMENT

    public static final int RETURN_STATEMENT

Node type constant indicating a node of type `ReturnStatement`.

See Also:
  `ReturnStatement`, Constant Field Values

#### SIMPLE_NAME

    public static final int SIMPLE_NAME

Node type constant indicating a node of type `SimpleName`.

See Also:
  `SimpleName`, Constant Field Values

#### SIMPLE_TYPE

    public static final int SIMPLE_TYPE

Node type constant indicating a node of type `SimpleType`.

See Also:
  `SimpleType`, Constant Field Values

#### SINGLE_VARIABLE_DECLARATION

    public static final int SINGLE_VARIABLE_DECLARATION

Node type constant indicating a node of type `SingleVariableDeclaration`.

See Also:
  `SingleVariableDeclaration`, Constant Field Values

#### STRING_LITERAL

    public static final int STRING_LITERAL

Node type constant indicating a node of type `StringLiteral`.

See Also:
  `StringLiteral`, Constant Field Values

#### SUPER_CONSTRUCTOR_INVOCATION

    public static final int SUPER_CONSTRUCTOR_INVOCATION

Node type constant indicating a node of type `SuperConstructorInvocation`.

See Also:
  `SuperConstructorInvocation`, Constant Field Values

#### SUPER_FIELD_ACCESS

    public static final int SUPER_FIELD_ACCESS

Node type constant indicating a node of type `SuperFieldAccess`.

See Also:
  `SuperFieldAccess`, Constant Field Values

#### SUPER_METHOD_INVOCATION

    public static final int SUPER_METHOD_INVOCATION

Node type constant indicating a node of type `SuperMethodInvocation`.

See Also:
  `SuperMethodInvocation`, Constant Field Values

#### SWITCH_CASE

    public static final int SWITCH_CASE

Node type constant indicating a node of type `SwitchCase`.

See Also:
  `SwitchCase`, Constant Field Values

#### SWITCH_STATEMENT

    public static final int SWITCH_STATEMENT

Node type constant indicating a node of type `SwitchStatement`.

See Also:
  `SwitchStatement`, Constant Field Values

#### THIS_EXPRESSION

    public static final int THIS_EXPRESSION

Node type constant indicating a node of type `ThisExpression`.

See Also:
  `ThisExpression`, Constant Field Values

#### THROW_STATEMENT

    public static final int THROW_STATEMENT

Node type constant indicating a node of type `ThrowStatement`.

See Also:
  `ThrowStatement`, Constant Field Values

#### TRY_STATEMENT

    public static final int TRY_STATEMENT

Node type constant indicating a node of type `TryStatement`.

See Also:
  `TryStatement`, Constant Field Values

#### TYPE_DECLARATION

    public static final int TYPE_DECLARATION

Node type constant indicating a node of type `TypeDeclaration`.

See Also:
  `TypeDeclaration`, Constant Field Values

#### TYPE_DECLARATION_STATEMENT

    public static final int TYPE_DECLARATION_STATEMENT

Node type constant indicating a node of type `TypeDeclarationStatement`.

See Also:
  `TypeDeclarationStatement`, Constant Field Values

#### TYPE_LITERAL

    public static final int TYPE_LITERAL

Node type constant indicating a node of type `TypeLiteral`.

See Also:
  `TypeLiteral`, Constant Field Values

#### VARIABLE_DECLARATION_EXPRESSION

    public static final int VARIABLE_DECLARATION_EXPRESSION

Node type constant indicating a node of type `VariableDeclarationExpression`.

See Also:
  `VariableDeclarationExpression`, Constant Field Values

#### VARIABLE_DECLARATION_FRAGMENT

    public static final int VARIABLE_DECLARATION_FRAGMENT

Node type constant indicating a node of type `VariableDeclarationFragment`.

See Also:
  `VariableDeclarationFragment`, Constant Field Values

#### VARIABLE_DECLARATION_STATEMENT

    public static final int VARIABLE_DECLARATION_STATEMENT

Node type constant indicating a node of type `VariableDeclarationStatement`.

See Also:
  `VariableDeclarationStatement`, Constant Field Values

#### WHILE_STATEMENT

    public static final int WHILE_STATEMENT

Node type constant indicating a node of type `WhileStatement`.

See Also:
  `WhileStatement`, Constant Field Values

#### INSTANCEOF_EXPRESSION

    public static final int INSTANCEOF_EXPRESSION

Node type constant indicating a node of type `InstanceofExpression`.

See Also:
  `InstanceofExpression`, Constant Field Values

#### LINE_COMMENT

    public static final int LINE_COMMENT

Node type constant indicating a node of type `LineComment`.

See Also:
  `LineComment`, Constant Field Values

#### BLOCK_COMMENT

    public static final int BLOCK_COMMENT

Node type constant indicating a node of type `BlockComment`.

See Also:
  `BlockComment`, Constant Field Values

#### TAG_ELEMENT

    public static final int TAG_ELEMENT

Node type constant indicating a node of type `TagElement`.

See Also:
  `TagElement`, Constant Field Values

#### TEXT_ELEMENT

    public static final int TEXT_ELEMENT

Node type constant indicating a node of type `TextElement`.

See Also:
  `TextElement`, Constant Field Values

#### MEMBER_REF

    public static final int MEMBER_REF

Node type constant indicating a node of type `MemberRef`.

See Also:
  `MemberRef`, Constant Field Values

#### FUNCTION_REF

    public static final int FUNCTION_REF

Node type constant indicating a node of type `FunctionRef`.

See Also:
  `FunctionRef`, Constant Field Values

#### FUNCTION_REF_PARAMETER

    public static final int FUNCTION_REF_PARAMETER

Node type constant indicating a node of type `FunctionRefParameter`.

See Also:
  `FunctionRefParameter`, Constant Field Values

#### ENHANCED_FOR_STATEMENT

    public static final int ENHANCED_FOR_STATEMENT

Node type constant indicating a node of type `EnhancedForStatement`.

See Also:
  `EnhancedForStatement`, Constant Field Values

#### QUALIFIED_TYPE

    public static final int QUALIFIED_TYPE

Node type constant indicating a node of type `QualifiedType`.

See Also:
  `QualifiedType`, Constant Field Values

#### FOR_IN_STATEMENT

    public static final int FOR_IN_STATEMENT

See Also:
  Constant Field Values

#### FUNCTION_EXPRESSION

    public static final int FUNCTION_EXPRESSION

See Also:
  Constant Field Values

#### OBJECT_LITERAL

    public static final int OBJECT_LITERAL

See Also:
  Constant Field Values

#### OBJECT_LITERAL_FIELD

    public static final int OBJECT_LITERAL_FIELD

See Also:
  Constant Field Values

#### UNDEFINED_LITERAL

    public static final int UNDEFINED_LITERAL

See Also:
  Constant Field Values

#### REGULAR_EXPRESSION_LITERAL

    public static final int REGULAR_EXPRESSION_LITERAL

See Also:
  Constant Field Values

#### INFERRED_TYPE

    public static final int INFERRED_TYPE

See Also:
  Constant Field Values

#### WITH_STATEMENT

    public static final int WITH_STATEMENT

See Also:
  Constant Field Values

#### LIST_EXPRESSION

    public static final int LIST_EXPRESSION

See Also:
  Constant Field Values

#### EMPTY_EXPRESSION

    public static final int EMPTY_EXPRESSION

See Also:
  Constant Field Values

#### YIELD_EXPRESSION

    public static final int YIELD_EXPRESSION

Since:
  2.0
See Also:
  Constant Field Values

#### ARROW_FUNCTION_EXPRESSION

    public static final int ARROW_FUNCTION_EXPRESSION

Since:
  2.0
See Also:
  Constant Field Values

#### DEBUGGER_STATEMENT

    public static final int DEBUGGER_STATEMENT

Since:
  2.0
See Also:
  Constant Field Values

#### FOR_OF_STATEMENT

    public static final int FOR_OF_STATEMENT

Since:
  2.0
See Also:
  Constant Field Values

#### ARRAY_NAME

    public static final int ARRAY_NAME

Since:
  2.0
See Also:
  Constant Field Values

#### OBJECT_NAME

    public static final int OBJECT_NAME

Since:
  2.0
See Also:
  Constant Field Values

#### MODIFIER

    public static final int MODIFIER

Node type constant indicating a node of type `Modifier`.

See Also:
  `Modifier`, Constant Field Values

#### TEMPLATE_LITERAL

    public static final int TEMPLATE_LITERAL

Since:
  2.0
See Also:
  Constant Field Values

#### TEMPLATE_ELEMENT

    public static final int TEMPLATE_ELEMENT

Since:
  2.0
See Also:
  Constant Field Values

#### ASSIGNMENT_NAME

    public static final int ASSIGNMENT_NAME

Since:
  2.0
See Also:
  Constant Field Values

#### REST_ELEMENT_NAME

    public static final int REST_ELEMENT_NAME

Since:
  2.0
See Also:
  Constant Field Values

#### SPREAD_ELEMENT

    public static final int SPREAD_ELEMENT

Since:
  2.0
See Also:
  Constant Field Values

#### META_PROPERTY

    public static final int META_PROPERTY

Since:
  2.0
See Also:
  Constant Field Values

#### MODULE_SPECIFIER

    public static final int MODULE_SPECIFIER

Since:
  2.0
See Also:
  Constant Field Values

#### EXPORT_DECLARATION

    public static final int EXPORT_DECLARATION

Since:
  2.0
See Also:
  Constant Field Values

#### TYPE_DECLARATION_EXPRESSION

    public static final int TYPE_DECLARATION_EXPRESSION

Since:
  2.0
See Also:
  Constant Field Values

#### FUNCTION_DECLARATION_STATEMENT

    public static final int FUNCTION_DECLARATION_STATEMENT

Since:
  2.0
See Also:
  Constant Field Values

#### MALFORMED

    public static final int MALFORMED

Flag constant (bit mask, value 1) indicating that there is something not quite right with this AST node.

The standard parser (`ASTParser`) sets this flag on a node to indicate a syntax error detected in the vicinity.

See Also:
  Constant Field Values

#### ORIGINAL

    public static final int ORIGINAL

Flag constant (bit mask, value 2) indicating that this is a node that was created by the parser (as opposed to one created by another party).

The standard parser (`ASTParser`) sets this flag on the nodes it creates.

See Also:
  Constant Field Values

#### PROTECT

    public static final int PROTECT

Flag constant (bit mask, value 4) indicating that this node is unmodifiable. When a node is marked unmodifiable, the following operations result in a runtime exception:

- Change a simple property of this node.
- Add or remove a child node from this node.
- Parent (or reparent) this node.

The standard parser (`ASTParser`) does not set this flag on the nodes it creates. However, clients may set this flag on a node to prevent further modification of the its structural properties.

See Also:
  Constant Field Values

#### RECOVERED

    public static final int RECOVERED

Flag constant (bit mask, value 8) indicating that this node or a part of this node is recovered from source that contains a syntax error detected in the vicinity.

The standard parser (`ASTParser`) sets this flag on a node to indicate a recovered node.

See Also:
  Constant Field Values

### Method Detail

#### nodeClassForType

    public static java.lang.Class nodeClassForType(int nodeType)

Returns the node class for the corresponding node type.

Parameters:
  `nodeType` - AST node type
Returns:
  the corresponding `ASTNode` subclass
Throws:
  `java.lang.IllegalArgumentException` - if `nodeType` is not a legal AST node type
See Also:
  `getNodeType()`

#### getAST

    public final AST getAST()

Returns this node's AST.

Note that the relationship between an AST node and its owing AST does not change over the lifetime of a node.

Returns:
  the AST that owns this node

#### getParent

    public final ASTNode getParent()

Returns this node's parent node, or `null` if this is the root node.

Note that the relationship between an AST node and its parent node may change over the lifetime of a node.

Returns:
  the parent of this node, or `null` if none

#### getLocationInParent

    public final StructuralPropertyDescriptor getLocationInParent()

Returns the location of this node within its parent, or `null` if this is a root node.

     ASTNode node = ...;
     ASTNode parent = node.getParent();
     StructuralPropertyDescriptor location = node.getLocationInParent();
     assert (parent != null) == (location != null);
     if ((location != null) && location.isChildProperty())
        assert parent.getStructuralProperty(location) == node;
     if ((location != null) && location.isChildListProperty())
        assert ((List) parent.getStructuralProperty(location)).contains(node);

Note that the relationship between an AST node and its parent node may change over the lifetime of a node.

Returns:
  the location of this node in its parent, or `null` if this node has no parent

#### getRoot

    public final ASTNode getRoot()

Returns the root node at or above this node; returns this node if it is a root.

Returns:
  the root node at or above this node

#### getStructuralProperty

    public final java.lang.Object getStructuralProperty(StructuralPropertyDescriptor property)

Returns the value of the given structural property for this node. The value returned depends on the kind of property:

- `SimplePropertyDescriptor` - the value of the given simple property, or `null` if none; primitive values are "boxed"
- `ChildPropertyDescriptor` - the child node (type `ASTNode`), or `null` if none
- `ChildListPropertyDescriptor` - the list (element type: `ASTNode`)

Parameters:
  `property` - the property
Returns:
  the value, or `null` if none
Throws:
  `java.lang.RuntimeException` - if this node does not have the given property

#### setStructuralProperty

    public final void setStructuralProperty(StructuralPropertyDescriptor property,
                                            java.lang.Object value)

Sets the value of the given structural property for this node. The value passed depends on the kind of property:

- `SimplePropertyDescriptor` - the new value of the given simple property, or `null` if none; primitive values are "boxed"
- `ChildPropertyDescriptor` - the new child node (type `ASTNode`), or `null` if none
- `ChildListPropertyDescriptor` - not allowed

Parameters:
  `property` - the property
  `value` - the property value
Throws:
  `java.lang.RuntimeException` - if this node does not have the given property, or if the given property cannot be set

#### structuralPropertiesForType

    public final java.util.List structuralPropertiesForType()

Returns a list of structural property descriptors for nodes of the same type as this node. Clients must not modify the result.

Note that property descriptors are a meta-level mechanism for manipulating ASTNodes in a generic way. They are unrelated to `get/setProperty`.

Returns:
  a list of property descriptors (element type: `StructuralPropertyDescriptor`)

#### delete

    public final void delete()

Removes this node from its parent. Has no effect if this node is unparented. If this node appears as an element of a child list property of its parent, then this node is removed from the list using `List.remove`. If this node appears as the value of a child property of its parent, then this node is detached from its parent by passing `null` to the appropriate setter method; this operation fails if this node is in a mandatory property.

#### getProperty

    public final java.lang.Object getProperty(java.lang.String propertyName)

Returns the named property of this node, or `null` if none.

Parameters:
  `propertyName` - the property name
Returns:
  the property value, or `null` if none
See Also:
  `setProperty(String,Object)`

#### setProperty

    public final void setProperty(java.lang.String propertyName,
                                  java.lang.Object data)

Sets the named property of this node to the given value, or to `null` to clear it.

Clients should employ property names that are sufficiently unique to avoid inadvertent conflicts with other clients that might also be setting properties on the same node.

Note that modifying a property is not considered a modification to the AST itself. This is to allow clients to decorate existing nodes with their own properties without jeopardizing certain things (like the validity of bindings), which rely on the underlying tree remaining static.

Parameters:
  `propertyName` - the property name
  `data` - the new property value, or `null` if none
See Also:
  `getProperty(String)`

#### properties

    public final java.util.Map properties()

Returns an unmodifiable table of the properties of this node with non-`null` values.

Returns:
  the table of property values keyed by property name (key type: `String`; value type: `Object`)

#### getFlags

    public final int getFlags()

Returns the flags associated with this node.

No flags are associated with newly created nodes.

The flags are the bitwise-or of individual flags. The following flags are currently defined:

- `MALFORMED` - indicates node is syntactically malformed
- `ORIGINAL` - indicates original node created by ASTParser
- `PROTECT` - indicates node is protected from further modification
- `RECOVERED` - indicates node or a part of this node is recovered from source that contains a syntax error

Other bit positions are reserved for future use.

Returns:
  the bitwise-or of individual flags
See Also:
  `setFlags(int)`

#### setFlags

    public final void setFlags(int flags)

Sets the flags associated with this node to the given value.

The flags are the bitwise-or of individual flags. The following flags are currently defined:

- `MALFORMED` - indicates node is syntactically malformed
- `ORIGINAL` - indicates original node created by ASTParser
- `PROTECT` - indicates node is protected from further modification
- `RECOVERED` - indicates node or a part of this node is recovered from source that contains a syntax error

Other bit positions are reserved for future use.

Note that the flags are not considered a structural property of the node, and can be changed even if the node is marked as protected.

Parameters:
  `flags` - the bitwise-or of individual flags
See Also:
  `getFlags()`

#### getNodeType

    public final int getNodeType()

Returns an integer value identifying the type of this concrete AST node. The values are small positive integers, suitable for use in switch statements.

For each concrete node type there is a unique node type constant (name and value). The unique node type constant for a concrete node type such as `CastExpression` is `ASTNode.CAST_EXPRESSION`.

Returns:
  one of the node type constants

#### equals

    public final boolean equals(java.lang.Object obj)

The `ASTNode` implementation of this `Object` method uses object identity (==). Use `subtreeMatch` to compare two subtrees for equality.

Overrides:
  `equals` in class `java.lang.Object`
Parameters:
  `obj` -
Returns:
See Also:
  `subtreeMatch(ASTMatcher matcher, Object other)`

#### hashCode

    public final int hashCode()

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

#### subtreeMatch

    public final boolean subtreeMatch(ASTMatcher matcher,
                                      java.lang.Object other)

Returns whether the subtree rooted at the given node matches the given other object as decided by the given matcher.

Parameters:
  `matcher` - the matcher
  `other` - the other object, or `null`
Returns:
  `true` if the subtree matches, or `false` if they do not match

#### copySubtree

    public static ASTNode copySubtree(AST target,
                                      ASTNode node)

Returns a deep copy of the subtree of AST nodes rooted at the given node. The resulting nodes are owned by the given AST, which may be different from the ASTs of the given node. Even if the given node has a parent, the result node will be unparented.

Source range information on the original nodes is automatically copied to the new nodes. Client properties (`properties`) are not carried over.

The node's `AST` and the target `AST` must support the same API level.

Parameters:
  `target` - the AST that is to own the nodes in the result
  `node` - the node to copy, or `null` if none
Returns:
  the copied node, or `null` if `node` is `null`

#### copySubtrees

    public static java.util.List copySubtrees(AST target,
                                              java.util.List nodes)

Returns a deep copy of the subtrees of AST nodes rooted at the given list of nodes. The resulting nodes are owned by the given AST, which may be different from the ASTs of the nodes in the list. Even if the nodes in the list have parents, the nodes in the result will be unparented.

Source range information on the original nodes is automatically copied to the new nodes. Client properties (`properties`) are not carried over.

Parameters:
  `target` - the AST that is to own the nodes in the result
  `nodes` - the list of nodes to copy (element type: `ASTNode`)
Returns:
  the list of copied subtrees (element type: `ASTNode`)

#### accept

    public final void accept(ASTVisitor visitor)

Accepts the given visitor on a visit of the current node.

Parameters:
  `visitor` - the visitor object
Throws:
  `java.lang.IllegalArgumentException` - if the visitor is null

#### getStartPosition

    public final int getStartPosition()

Returns the character index into the original source file indicating where the source fragment corresponding to this node begins.

The parser supplies useful well-defined source ranges to the nodes it creates. See `ASTParser.setKind(int)` for details on precisely where source ranges begin and end.

Returns:
  the 0-based character index, or `-1` if no source position information is recorded for this node
See Also:
  `getLength()`, `ASTParser`

#### getLength

    public final int getLength()

Returns the length in characters of the original source file indicating where the source fragment corresponding to this node ends.

The parser supplies useful well-defined source ranges to the nodes it creates. See `ASTParser.setKind(int)` methods for details on precisely where source ranges begin and end.

Returns:
  a (possibly 0) length, or `0` if no source position information is recorded for this node
See Also:
  `getStartPosition()`, `ASTParser`

#### setSourceRange

    public final void setSourceRange(int startPosition,
                                     int length)

Sets the source range of the original source file where the source fragment corresponding to this node was found.

See `ASTParser.setKind(int)` for details on precisely where source ranges are supposed to begin and end.

Parameters:
  `startPosition` - a 0-based character index, or `-1` if no source position information is available for this node
  `length` - a (possibly 0) length, or `0` if no source position information is recorded for this node
See Also:
  `getStartPosition()`, `getLength()`, `ASTParser`

#### toString

    public final java.lang.String toString()

Returns a string representation of this node suitable for debugging purposes only.

Overrides:
  `toString` in class `java.lang.Object`
Returns:
  a debug string

#### subtreeBytes

    public final int subtreeBytes()

Returns an estimate of the memory footprint in bytes of the entire subtree rooted at this node.

Returns:
  the size of this subtree in bytes

#### getBodyChild

    public ASTNode getBodyChild()