Class ASTNode
- Direct Known Subclasses:
AbstractTagElement,AbstractTextElement,AnonymousClassDeclaration,BodyDeclaration,CatchClause,Comment,CompilationUnit,Dimension,Expression,ImportDeclaration,MemberRef,MemberValuePair,MethodRef,MethodRefParameter,Modifier,ModuleDeclaration,ModuleDirective,ModuleModifier,PackageDeclaration,Statement,TagProperty,Type,TypeParameter,VariableDeclaration
An AST node represents a Java 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 Java 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. The NodeFinder class can be used to find a specific
node inside a tree.
Compilation units created by ASTParser from a
source document can be serialized after arbitrary modifications
with minimal loss of original formatting. See
CompilationUnit.recordModifications() for details.
See also ASTRewrite for
an alternative way to describe and serialize changes to a
read-only AST.
- Since:
- 2.0
- See Also:
- Restriction:
- This class is not intended to be subclassed by clients.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intNode type constant indicating a node of typeAnnotationTypeDeclaration.static final intNode type constant indicating a node of typeAnnotationTypeMemberDeclaration.static final intNode type constant indicating a node of typeAnonymousClassDeclaration.static final intNode type constant indicating a node of typeArrayAccess.static final intNode type constant indicating a node of typeArrayCreation.static final intNode type constant indicating a node of typeArrayInitializer.static final intNode type constant indicating a node of typeArrayType.static final intNode type constant indicating a node of typeAssertStatement.static final intNode type constant indicating a node of typeAssignment.static final intNode type constant indicating a node of typeBlock.static final intNode type constant indicating a node of typeBlockComment.static final intNode type constant indicating a node of typeBooleanLiteral.static final intNode type constant indicating a node of typeBreakStatement.static final intNode type constant indicating a node of typeCaseDefaultExpression.static final intNode type constant indicating a node of typeCastExpression.static final intNode type constant indicating a node of typeCatchClause.static final intNode type constant indicating a node of typeCharacterLiteral.static final intNode type constant indicating a node of typeClassInstanceCreation.static final intNode type constant indicating a node of typeCompilationUnit.static final intNode type constant indicating a node of typeConditionalExpression.static final intNode type constant indicating a node of typeConstructorInvocation.static final intNode type constant indicating a node of typeContinueStatement.static final intNode type constant indicating a node of typeCreationReference.static final intNode type constant indicating a node of typeDimension.static final intNode type constant indicating a node of typeDoStatement.static final intNode type constant indicating a node of typeEitherOrMultiPattern.static final intNode type constant indicating a node of typeEmptyStatement.static final intNode type constant indicating a node of typeEnhancedForStatement.static final intNode type constant indicating a node of typeEnumConstantDeclaration.static final intNode type constant indicating a node of typeEnumDeclaration.static final intNode type constant indicating a node of typeExportsDirective.static final intNode type constant indicating a node of typeExpressionMethodReference.static final intNode type constant indicating a node of typeExpressionStatement.static final intNode type constant indicating a node of typeFieldAccess.static final intNode type constant indicating a node of typeFieldDeclaration.static final intNode type constant indicating a node of typeForStatement.static final intNode type constant indicating a node of typeGuardedPattern.static final intNode type constant indicating a node of typeIfStatement.static final intNode type constant indicating a node of typeImportDeclaration.static final intNode type constant indicating a node of typeInfixExpression.static final intNode type constant indicating a node of typeInitializer.static final intNode type constant indicating a node of typeInstanceofExpression.static final intNode type constant indicating a node of typeIntersectionType.static final intNode type constant indicating a node of typeJavadoc.static final intNode type constant indicating a node of typeJavaDocRegion.static final intNode type constant indicating a node of typeTextElement.static final intNode type constant indicating a node of typeLabeledStatement.static final intNode type constant indicating a node of typeLambdaExpression.static final intNode type constant indicating a node of typeLineComment.static final intFlag constant (bit mask, value 1) indicating that there is something not quite right with this AST node.static final intNode type constant indicating a node of typeMarkerAnnotation.static final intNode type constant indicating a node of typeMemberRef.static final intNode type constant indicating a node of typeMemberValuePair.static final intNode type constant indicating a node of typeMethodDeclaration.static final intNode type constant indicating a node of typeMethodInvocation.static final intNode type constant indicating a node of typeMethodRef.static final intNode type constant indicating a node of typeMethodRefParameter.static final intNode type constant indicating a node of typeModifier.static final intNode type constant indicating a node of typeModuleDeclaration.static final intNode type constant indicating a node of typeModuleModifier.static final intNode type constant indicating a node of typeModuleQualifiedName.static final intNode type constant indicating a node of typeNameQualifiedType.static final intNode type constant indicating a node of typeNormalAnnotation.static final intNode type constant indicating a node of typeNullLiteral.static final intNode type constant indicating a node of typeNullPattern.static final intNode type constant indicating a node of typeNumberLiteral.static final intNode type constant indicating a node of typeOpensDirective.static final intFlag 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 final intNode type constant indicating a node of typePackageDeclaration.static final intNode type constant indicating a node of typeParameterizedType.static final intNode type constant indicating a node of typeParenthesizedExpression.static final intNode type constant indicating a node of typePatternInstanceofExpression.static final intNode type constant indicating a node of typePostfixExpression.static final intNode type constant indicating a node of typePrefixExpression.static final intNode type constant indicating a node of typePrimitiveType.static final intFlag constant (bit mask, value 4) indicating that this node is unmodifiable.static final intNode type constant indicating a node of typeProvidesDirective.static final intNode type constant indicating a node of typeQualifiedName.static final intNode type constant indicating a node of typeQualifiedType.static final intNode type constant indicating a node of typeRecordDeclaration.static final intNode type constant indicating a node of typeRecordPattern.static final intFlag 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 final intNode type constant indicating a node of typeRequiresDirective.static final intNode type constant indicating a node of typeReturnStatement.static final intNode type constant indicating a node of typeSimpleName.static final intNode type constant indicating a node of typeSimpleType.static final intNode type constant indicating a node of typeSingleMemberAnnotation.static final intNode type constant indicating a node of typeSingleVariableDeclaration.static final intNode type constant indicating a node of typeStringLiteral.static final intNode type constant indicating a node of typeSuperConstructorInvocation.static final intNode type constant indicating a node of typeSuperFieldAccess.static final intNode type constant indicating a node of typeSuperMethodInvocation.static final intNode type constant indicating a node of typeSuperMethhodReference.static final intNode type constant indicating a node of typeSwitchCase.static final intNode type constant indicating a node of typeSwitchExpression.static final intNode type constant indicating a node of typeSwitchStatement.static final intNode type constant indicating a node of typeSynchronizedStatement.static final intNode type constant indicating a node of typeTagElement.static final intNode type constant indicating a node of typeTagProperty.static final intNode type constant indicating a node of typeTextBlock.static final intNode type constant indicating a node of typeTextElement.static final intNode type constant indicating a node of typeThisExpression.static final intNode type constant indicating a node of typeThrowStatement.static final intNode type constant indicating a node of typeTryStatement.static final intNode type constant indicating a node of typeTypeDeclaration.static final intNode type constant indicating a node of typeTypeDeclarationStatement.static final intNode type constant indicating a node of typeTypeLiteral.static final intNode type constant indicating a node of typeTypeMethodReference.static final intNode type constant indicating a node of typeTypeParameter.static final intNode type constant indicating a node of typeTypePattern.static final intNode type constant indicating a node of typeUnionType.static final intstatic final intNode type constant indicating a node of typeUsesDirective.static final intNode type constant indicating a node of typeVariableDeclarationExpression.static final intNode type constant indicating a node of typeVariableDeclarationFragment.static final intNode type constant indicating a node of typeVariableDeclarationStatement.static final intNode type constant indicating a node of typeWhileStatement.static final intNode type constant indicating a node of typeWildcardType.static final intNode type constant indicating a node of typeYieldStatement. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaccept(ASTVisitor visitor) Accepts the given visitor on a visit of the current node.static ASTNodecopySubtree(AST target, ASTNode node) Returns a deep copy of the subtree of AST nodes rooted at the given node.static ListcopySubtrees(AST target, List nodes) Returns a deep copy of the subtrees of AST nodes rooted at the given list of nodes.final voiddelete()Removes this node from its parent.final booleanTheASTNodeimplementation of thisObjectmethod uses object identity (==).final ASTgetAST()Returns this node's AST.final intgetFlags()Returns the flags associated with this node.final intReturns the length in characters of the original source file indicating where the source fragment corresponding to this node ends.Returns the location of this node within its parent, ornullif this is a root node.final intReturns an integer value identifying the type of this concrete AST node.final ASTNodeReturns this node's parent node, ornullif this is the root node.final ObjectgetProperty(String propertyName) Returns the value of the named property of this node, ornullif none.final ASTNodegetRoot()Returns the root node at or above this node; returns this node if it is a root.final intReturns the character index into the original source file indicating where the source fragment corresponding to this node begins.final ObjectReturns the value of the given structural property for this node.final inthashCode()static ClassnodeClassForType(int nodeType) Returns the node class for the corresponding node type.final MapReturns an unmodifiable table of the properties of this node with non-nullvalues.final voidsetFlags(int flags) Sets the flags associated with this node to the given value.final voidsetProperty(String propertyName, Object data) Sets the named property of this node to the given value, or tonullto clear it.final voidsetSourceRange(int startPosition, int length) Sets the source range of the original source file where the source fragment corresponding to this node was found.final voidsetStructuralProperty(StructuralPropertyDescriptor property, Object value) Sets the value of the given structural property for this node.final ListReturns a list of structural property descriptors for nodes of the same type as this node.final intReturns an estimate of the memory footprint in bytes of the entire subtree rooted at this node.final booleansubtreeMatch(ASTMatcher matcher, Object other) Returns whether the subtree rooted at the given node matches the given other object as decided by the given matcher.final StringtoString()Returns a string representation of this node suitable for debugging purposes only.
-
Field Details
-
ANONYMOUS_CLASS_DECLARATION
public static final int ANONYMOUS_CLASS_DECLARATIONNode type constant indicating a node of typeAnonymousClassDeclaration.- See Also:
-
ARRAY_ACCESS
public static final int ARRAY_ACCESSNode type constant indicating a node of typeArrayAccess.- See Also:
-
ARRAY_CREATION
public static final int ARRAY_CREATIONNode type constant indicating a node of typeArrayCreation.- See Also:
-
ARRAY_INITIALIZER
public static final int ARRAY_INITIALIZERNode type constant indicating a node of typeArrayInitializer.- See Also:
-
ARRAY_TYPE
public static final int ARRAY_TYPENode type constant indicating a node of typeArrayType.- See Also:
-
ASSERT_STATEMENT
public static final int ASSERT_STATEMENTNode type constant indicating a node of typeAssertStatement.- See Also:
-
ASSIGNMENT
public static final int ASSIGNMENTNode type constant indicating a node of typeAssignment.- See Also:
-
BLOCK
public static final int BLOCKNode type constant indicating a node of typeBlock.- See Also:
-
BOOLEAN_LITERAL
public static final int BOOLEAN_LITERALNode type constant indicating a node of typeBooleanLiteral.- See Also:
-
BREAK_STATEMENT
public static final int BREAK_STATEMENTNode type constant indicating a node of typeBreakStatement.- See Also:
-
CAST_EXPRESSION
public static final int CAST_EXPRESSIONNode type constant indicating a node of typeCastExpression.- See Also:
-
CATCH_CLAUSE
public static final int CATCH_CLAUSENode type constant indicating a node of typeCatchClause.- See Also:
-
CHARACTER_LITERAL
public static final int CHARACTER_LITERALNode type constant indicating a node of typeCharacterLiteral.- See Also:
-
CLASS_INSTANCE_CREATION
public static final int CLASS_INSTANCE_CREATIONNode type constant indicating a node of typeClassInstanceCreation.- See Also:
-
COMPILATION_UNIT
public static final int COMPILATION_UNITNode type constant indicating a node of typeCompilationUnit.- See Also:
-
CONDITIONAL_EXPRESSION
public static final int CONDITIONAL_EXPRESSIONNode type constant indicating a node of typeConditionalExpression.- See Also:
-
CONSTRUCTOR_INVOCATION
public static final int CONSTRUCTOR_INVOCATIONNode type constant indicating a node of typeConstructorInvocation.- See Also:
-
CONTINUE_STATEMENT
public static final int CONTINUE_STATEMENTNode type constant indicating a node of typeContinueStatement.- See Also:
-
DO_STATEMENT
public static final int DO_STATEMENTNode type constant indicating a node of typeDoStatement.- See Also:
-
EMPTY_STATEMENT
public static final int EMPTY_STATEMENTNode type constant indicating a node of typeEmptyStatement.- See Also:
-
EXPRESSION_STATEMENT
public static final int EXPRESSION_STATEMENTNode type constant indicating a node of typeExpressionStatement.- See Also:
-
FIELD_ACCESS
public static final int FIELD_ACCESSNode type constant indicating a node of typeFieldAccess.- See Also:
-
FIELD_DECLARATION
public static final int FIELD_DECLARATIONNode type constant indicating a node of typeFieldDeclaration.- See Also:
-
FOR_STATEMENT
public static final int FOR_STATEMENTNode type constant indicating a node of typeForStatement.- See Also:
-
IF_STATEMENT
public static final int IF_STATEMENTNode type constant indicating a node of typeIfStatement.- See Also:
-
IMPORT_DECLARATION
public static final int IMPORT_DECLARATIONNode type constant indicating a node of typeImportDeclaration.- See Also:
-
INFIX_EXPRESSION
public static final int INFIX_EXPRESSIONNode type constant indicating a node of typeInfixExpression.- See Also:
-
INITIALIZER
public static final int INITIALIZERNode type constant indicating a node of typeInitializer.- See Also:
-
JAVADOC
public static final int JAVADOCNode type constant indicating a node of typeJavadoc.- See Also:
-
LABELED_STATEMENT
public static final int LABELED_STATEMENTNode type constant indicating a node of typeLabeledStatement.- See Also:
-
METHOD_DECLARATION
public static final int METHOD_DECLARATIONNode type constant indicating a node of typeMethodDeclaration.- See Also:
-
METHOD_INVOCATION
public static final int METHOD_INVOCATIONNode type constant indicating a node of typeMethodInvocation.- See Also:
-
NULL_LITERAL
public static final int NULL_LITERALNode type constant indicating a node of typeNullLiteral.- See Also:
-
NUMBER_LITERAL
public static final int NUMBER_LITERALNode type constant indicating a node of typeNumberLiteral.- See Also:
-
PACKAGE_DECLARATION
public static final int PACKAGE_DECLARATIONNode type constant indicating a node of typePackageDeclaration.- See Also:
-
PARENTHESIZED_EXPRESSION
public static final int PARENTHESIZED_EXPRESSIONNode type constant indicating a node of typeParenthesizedExpression.- See Also:
-
POSTFIX_EXPRESSION
public static final int POSTFIX_EXPRESSIONNode type constant indicating a node of typePostfixExpression.- See Also:
-
PREFIX_EXPRESSION
public static final int PREFIX_EXPRESSIONNode type constant indicating a node of typePrefixExpression.- See Also:
-
PRIMITIVE_TYPE
public static final int PRIMITIVE_TYPENode type constant indicating a node of typePrimitiveType.- See Also:
-
QUALIFIED_NAME
public static final int QUALIFIED_NAMENode type constant indicating a node of typeQualifiedName.- See Also:
-
RETURN_STATEMENT
public static final int RETURN_STATEMENTNode type constant indicating a node of typeReturnStatement.- See Also:
-
SIMPLE_NAME
public static final int SIMPLE_NAMENode type constant indicating a node of typeSimpleName.- See Also:
-
SIMPLE_TYPE
public static final int SIMPLE_TYPENode type constant indicating a node of typeSimpleType.- See Also:
-
SINGLE_VARIABLE_DECLARATION
public static final int SINGLE_VARIABLE_DECLARATIONNode type constant indicating a node of typeSingleVariableDeclaration.- See Also:
-
STRING_LITERAL
public static final int STRING_LITERALNode type constant indicating a node of typeStringLiteral.- See Also:
-
SUPER_CONSTRUCTOR_INVOCATION
public static final int SUPER_CONSTRUCTOR_INVOCATIONNode type constant indicating a node of typeSuperConstructorInvocation.- See Also:
-
SUPER_FIELD_ACCESS
public static final int SUPER_FIELD_ACCESSNode type constant indicating a node of typeSuperFieldAccess.- See Also:
-
SUPER_METHOD_INVOCATION
public static final int SUPER_METHOD_INVOCATIONNode type constant indicating a node of typeSuperMethodInvocation.- See Also:
-
SWITCH_CASE
public static final int SWITCH_CASENode type constant indicating a node of typeSwitchCase.- See Also:
-
SWITCH_STATEMENT
public static final int SWITCH_STATEMENTNode type constant indicating a node of typeSwitchStatement.- See Also:
-
SYNCHRONIZED_STATEMENT
public static final int SYNCHRONIZED_STATEMENTNode type constant indicating a node of typeSynchronizedStatement.- See Also:
-
THIS_EXPRESSION
public static final int THIS_EXPRESSIONNode type constant indicating a node of typeThisExpression.- See Also:
-
THROW_STATEMENT
public static final int THROW_STATEMENTNode type constant indicating a node of typeThrowStatement.- See Also:
-
TRY_STATEMENT
public static final int TRY_STATEMENTNode type constant indicating a node of typeTryStatement.- See Also:
-
TYPE_DECLARATION
public static final int TYPE_DECLARATIONNode type constant indicating a node of typeTypeDeclaration.- See Also:
-
TYPE_DECLARATION_STATEMENT
public static final int TYPE_DECLARATION_STATEMENTNode type constant indicating a node of typeTypeDeclarationStatement.- See Also:
-
TYPE_LITERAL
public static final int TYPE_LITERALNode type constant indicating a node of typeTypeLiteral.- See Also:
-
VARIABLE_DECLARATION_EXPRESSION
public static final int VARIABLE_DECLARATION_EXPRESSIONNode type constant indicating a node of typeVariableDeclarationExpression.- See Also:
-
VARIABLE_DECLARATION_FRAGMENT
public static final int VARIABLE_DECLARATION_FRAGMENTNode type constant indicating a node of typeVariableDeclarationFragment.- See Also:
-
VARIABLE_DECLARATION_STATEMENT
public static final int VARIABLE_DECLARATION_STATEMENTNode type constant indicating a node of typeVariableDeclarationStatement.- See Also:
-
WHILE_STATEMENT
public static final int WHILE_STATEMENTNode type constant indicating a node of typeWhileStatement.- See Also:
-
INSTANCEOF_EXPRESSION
public static final int INSTANCEOF_EXPRESSIONNode type constant indicating a node of typeInstanceofExpression.- See Also:
-
LINE_COMMENT
public static final int LINE_COMMENTNode type constant indicating a node of typeLineComment.- Since:
- 3.0
- See Also:
-
BLOCK_COMMENT
public static final int BLOCK_COMMENTNode type constant indicating a node of typeBlockComment.- Since:
- 3.0
- See Also:
-
TAG_ELEMENT
public static final int TAG_ELEMENTNode type constant indicating a node of typeTagElement.- Since:
- 3.0
- See Also:
-
TEXT_ELEMENT
public static final int TEXT_ELEMENTNode type constant indicating a node of typeTextElement.- Since:
- 3.0
- See Also:
-
MEMBER_REF
public static final int MEMBER_REFNode type constant indicating a node of typeMemberRef.- Since:
- 3.0
- See Also:
-
METHOD_REF
public static final int METHOD_REFNode type constant indicating a node of typeMethodRef.- Since:
- 3.0
- See Also:
-
METHOD_REF_PARAMETER
public static final int METHOD_REF_PARAMETERNode type constant indicating a node of typeMethodRefParameter.- Since:
- 3.0
- See Also:
-
ENHANCED_FOR_STATEMENT
public static final int ENHANCED_FOR_STATEMENTNode type constant indicating a node of typeEnhancedForStatement.- Since:
- 3.1
- See Also:
-
ENUM_DECLARATION
public static final int ENUM_DECLARATIONNode type constant indicating a node of typeEnumDeclaration.- Since:
- 3.1
- See Also:
-
ENUM_CONSTANT_DECLARATION
public static final int ENUM_CONSTANT_DECLARATIONNode type constant indicating a node of typeEnumConstantDeclaration.- Since:
- 3.1
- See Also:
-
TYPE_PARAMETER
public static final int TYPE_PARAMETERNode type constant indicating a node of typeTypeParameter.- Since:
- 3.1
- See Also:
-
PARAMETERIZED_TYPE
public static final int PARAMETERIZED_TYPENode type constant indicating a node of typeParameterizedType.- Since:
- 3.1
- See Also:
-
QUALIFIED_TYPE
public static final int QUALIFIED_TYPENode type constant indicating a node of typeQualifiedType.- Since:
- 3.1
- See Also:
-
WILDCARD_TYPE
public static final int WILDCARD_TYPENode type constant indicating a node of typeWildcardType.- Since:
- 3.1
- See Also:
-
NORMAL_ANNOTATION
public static final int NORMAL_ANNOTATIONNode type constant indicating a node of typeNormalAnnotation.- Since:
- 3.1
- See Also:
-
MARKER_ANNOTATION
public static final int MARKER_ANNOTATIONNode type constant indicating a node of typeMarkerAnnotation.- Since:
- 3.1
- See Also:
-
SINGLE_MEMBER_ANNOTATION
public static final int SINGLE_MEMBER_ANNOTATIONNode type constant indicating a node of typeSingleMemberAnnotation.- Since:
- 3.1
- See Also:
-
MEMBER_VALUE_PAIR
public static final int MEMBER_VALUE_PAIRNode type constant indicating a node of typeMemberValuePair.- Since:
- 3.1
- See Also:
-
ANNOTATION_TYPE_DECLARATION
public static final int ANNOTATION_TYPE_DECLARATIONNode type constant indicating a node of typeAnnotationTypeDeclaration.- Since:
- 3.1
- See Also:
-
ANNOTATION_TYPE_MEMBER_DECLARATION
public static final int ANNOTATION_TYPE_MEMBER_DECLARATIONNode type constant indicating a node of typeAnnotationTypeMemberDeclaration.- Since:
- 3.1
- See Also:
-
MODIFIER
public static final int MODIFIERNode type constant indicating a node of typeModifier.- Since:
- 3.1
- See Also:
-
UNION_TYPE
public static final int UNION_TYPENode type constant indicating a node of typeUnionType.- Since:
- 3.7.1
- See Also:
-
DIMENSION
public static final int DIMENSIONNode type constant indicating a node of typeDimension.- Since:
- 3.10
- See Also:
-
LAMBDA_EXPRESSION
public static final int LAMBDA_EXPRESSIONNode type constant indicating a node of typeLambdaExpression.- Since:
- 3.10
- See Also:
-
INTERSECTION_TYPE
public static final int INTERSECTION_TYPENode type constant indicating a node of typeIntersectionType.- Since:
- 3.10
- See Also:
-
NAME_QUALIFIED_TYPE
public static final int NAME_QUALIFIED_TYPENode type constant indicating a node of typeNameQualifiedType.- Since:
- 3.10
- See Also:
-
CREATION_REFERENCE
public static final int CREATION_REFERENCENode type constant indicating a node of typeCreationReference.- Since:
- 3.10
- See Also:
-
EXPRESSION_METHOD_REFERENCE
public static final int EXPRESSION_METHOD_REFERENCENode type constant indicating a node of typeExpressionMethodReference.- Since:
- 3.10
- See Also:
-
SUPER_METHOD_REFERENCE
public static final int SUPER_METHOD_REFERENCENode type constant indicating a node of typeSuperMethhodReference.- Since:
- 3.10
- See Also:
-
TYPE_METHOD_REFERENCE
public static final int TYPE_METHOD_REFERENCENode type constant indicating a node of typeTypeMethodReference.- Since:
- 3.10
- See Also:
-
MODULE_DECLARATION
public static final int MODULE_DECLARATIONNode type constant indicating a node of typeModuleDeclaration.- Since:
- 3.14
- See Also:
-
REQUIRES_DIRECTIVE
public static final int REQUIRES_DIRECTIVENode type constant indicating a node of typeRequiresDirective.- Since:
- 3.14
- See Also:
-
EXPORTS_DIRECTIVE
public static final int EXPORTS_DIRECTIVENode type constant indicating a node of typeExportsDirective.- Since:
- 3.14
- See Also:
-
OPENS_DIRECTIVE
public static final int OPENS_DIRECTIVENode type constant indicating a node of typeOpensDirective.- Since:
- 3.14
- See Also:
-
USES_DIRECTIVE
public static final int USES_DIRECTIVENode type constant indicating a node of typeUsesDirective.- Since:
- 3.14
- See Also:
-
PROVIDES_DIRECTIVE
public static final int PROVIDES_DIRECTIVENode type constant indicating a node of typeProvidesDirective.- Since:
- 3.14
- See Also:
-
MODULE_MODIFIER
public static final int MODULE_MODIFIERNode type constant indicating a node of typeModuleModifier.- Since:
- 3.14
- See Also:
-
SWITCH_EXPRESSION
public static final int SWITCH_EXPRESSIONNode type constant indicating a node of typeSwitchExpression.- Since:
- 3.18
- See Also:
-
YIELD_STATEMENT
public static final int YIELD_STATEMENTNode type constant indicating a node of typeYieldStatement.- Since:
- 3.20
- See Also:
-
TEXT_BLOCK
public static final int TEXT_BLOCKNode type constant indicating a node of typeTextBlock.- Since:
- 3.20
- See Also:
-
RECORD_DECLARATION
public static final int RECORD_DECLARATIONNode type constant indicating a node of typeRecordDeclaration.- Since:
- 3.22
- See Also:
-
PATTERN_INSTANCEOF_EXPRESSION
public static final int PATTERN_INSTANCEOF_EXPRESSIONNode type constant indicating a node of typePatternInstanceofExpression.- Since:
- 3.26
- See Also:
-
MODULE_QUALIFIED_NAME
public static final int MODULE_QUALIFIED_NAMENode type constant indicating a node of typeModuleQualifiedName.- Since:
- 3.24
- See Also:
-
TYPE_PATTERN
public static final int TYPE_PATTERNNode type constant indicating a node of typeTypePattern.- Since:
- 3.28
- See Also:
-
GUARDED_PATTERN
public static final int GUARDED_PATTERNNode type constant indicating a node of typeGuardedPattern.- Since:
- 3.28
- See Also:
-
NULL_PATTERN
public static final int NULL_PATTERNNode type constant indicating a node of typeNullPattern.- Since:
- 3.28
- See Also:
-
CASE_DEFAULT_EXPRESSION
public static final int CASE_DEFAULT_EXPRESSIONNode type constant indicating a node of typeCaseDefaultExpression.- Since:
- 3.28
- See Also:
-
TAG_PROPERTY
public static final int TAG_PROPERTYNode type constant indicating a node of typeTagProperty.- Since:
- 3.30
- See Also:
-
JAVADOC_REGION
public static final int JAVADOC_REGIONNode type constant indicating a node of typeJavaDocRegion.- Since:
- 3.30
- See Also:
-
JAVADOC_TEXT_ELEMENT
public static final int JAVADOC_TEXT_ELEMENTNode type constant indicating a node of typeTextElement.- Since:
- 3.31
- See Also:
-
RECORD_PATTERN
public static final int RECORD_PATTERNNode type constant indicating a node of typeRecordPattern.- Since:
- 3.32
- See Also:
-
EitherOr_MultiPattern
public static final int EitherOr_MultiPatternNode type constant indicating a node of typeEitherOrMultiPattern.- Since:
- 3.38
- See Also:
- Restriction:
- This field is not intended to be referenced by clients.
-
UNNAMED_CLASS
public static final int UNNAMED_CLASS- Since:
- 3.38
- See Also:
- Restriction:
- This field is not intended to be referenced by clients.
-
MALFORMED
public static final int MALFORMEDFlag 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:
-
ORIGINAL
public static final int ORIGINALFlag 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.- Since:
- 3.0
- See Also:
-
PROTECT
public static final int PROTECTFlag 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.- Since:
- 3.0
- See Also:
-
RECOVERED
public static final int RECOVEREDFlag 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.- Since:
- 3.2
- See Also:
-
-
Method Details
-
nodeClassForType
Returns the node class for the corresponding node type.- Parameters:
nodeType- AST node type- Returns:
- the corresponding
ASTNodesubclass - Throws:
IllegalArgumentException- ifnodeTypeis not a legal AST node type- Since:
- 3.0
- See Also:
-
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
Returns this node's parent node, ornullif 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
nullif none
-
getLocationInParent
Returns the location of this node within its parent, ornullif 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
nullif this node has no parent - Since:
- 3.0
-
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
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, ornullif none; primitive values are "boxed"ChildPropertyDescriptor- the child node (typeASTNode), ornullif noneChildListPropertyDescriptor- the list (element type:ASTNode)
- Parameters:
property- the property- Returns:
- the value, or
nullif none - Throws:
RuntimeException- if this node does not have the given property- Since:
- 3.0
-
setStructuralProperty
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, ornullif none; primitive values are "boxed"ChildPropertyDescriptor- the new child node (typeASTNode), ornullif noneChildListPropertyDescriptor- not allowed
- Parameters:
property- the propertyvalue- the property value- Throws:
RuntimeException- if this node does not have the given property, or if the given property cannot be set- Since:
- 3.0
-
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) - Since:
- 3.0
-
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 usingList.remove. If this node appears as the value of a child property of its parent, then this node is detached from its parent by passingnullto the appropriate setter method; this operation fails if this node is in a mandatory property.- Since:
- 3.0
-
getProperty
Returns the value of the named property of this node, ornullif none.- Parameters:
propertyName- the property name- Returns:
- the property value, or
nullif none - See Also:
-
setProperty
Sets the named property of this node to the given value, or tonullto 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 namedata- the new property value, ornullif none- Throws:
IllegalArgumentException- if the given property name isnull- See Also:
-
properties
Returns an unmodifiable table of the properties of this node with non-nullvalues.- 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:
Other bit positions are reserved for future use.- Returns:
- the bitwise-or of individual flags
- See Also:
-
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 malformedORIGINAL- indicates original node created by ASTParserPROTECT- indicates node is protected from further modificationRECOVERED- indicates node or a part of this node is recovered from source that contains a syntax error
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:
-
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
CastExpressionisASTNode.CAST_EXPRESSION.- Returns:
- one of the node type constants
-
equals
TheASTNodeimplementation of thisObjectmethod uses object identity (==). UsesubtreeMatchto compare two subtrees for equality. -
hashCode
public final int hashCode() -
subtreeMatch
Returns whether the subtree rooted at the given node matches the given other object as decided by the given matcher.- Parameters:
matcher- the matcherother- the other object, ornull- Returns:
trueif the subtree matches, orfalseif they do not match
-
copySubtree
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
ASTand the targetASTmust support the same API level.- Parameters:
target- the AST that is to own the nodes in the resultnode- the node to copy, ornullif none- Returns:
- the copied node, or
nullifnodeisnull
-
copySubtrees
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. -
accept
Accepts the given visitor on a visit of the current node.- Parameters:
visitor- the visitor object- Throws:
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
-1if no source position information is recorded for this node - See Also:
-
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
0if no source position information is recorded for this node - See Also:
-
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-1if no source position information is available for this nodelength- a (possibly 0) length, or0if no source position information is recorded for this node- See Also:
-
toString
Returns a string representation of this node suitable for debugging purposes only. -
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
-