public abstract class ASTNode extends Object
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:
Expression
Name
(a sub-kind of expression)Statement
Type
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.
ASTParser
,
ASTVisitor
,
NodeFinder
Modifier and Type | Field and Description |
---|---|
static int |
ANNOTATION_TYPE_DECLARATION
Node type constant indicating a node of type
AnnotationTypeDeclaration . |
static int |
ANNOTATION_TYPE_MEMBER_DECLARATION
Node type constant indicating a node of type
AnnotationTypeMemberDeclaration . |
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_TYPE
Node type constant indicating a node of type
ArrayType . |
static int |
ASSERT_STATEMENT
Node type constant indicating a node of type
AssertStatement . |
static int |
ASSIGNMENT
Node type constant indicating a node of type
Assignment . |
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 |
CAST_EXPRESSION
Node type constant indicating a node of type
CastExpression . |
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 |
COMPILATION_UNIT
Node type constant indicating a node of type
CompilationUnit . |
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 |
CREATION_REFERENCE
Node type constant indicating a node of type
CreationReference . |
static int |
DIMENSION
Node type constant indicating a node of type
Dimension . |
static int |
DO_STATEMENT
Node type constant indicating a node of type
DoStatement . |
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 |
ENUM_CONSTANT_DECLARATION
Node type constant indicating a node of type
EnumConstantDeclaration . |
static int |
ENUM_DECLARATION
Node type constant indicating a node of type
EnumDeclaration . |
static int |
EXPRESSION_METHOD_REFERENCE
Node type constant indicating a node of type
ExpressionMethodReference . |
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_STATEMENT
Node type constant indicating a node of type
ForStatement . |
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 |
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 |
INTERSECTION_TYPE
Node type constant indicating a node of type
IntersectionType . |
static int |
JAVADOC
Node type constant indicating a node of type
Javadoc . |
static int |
LABELED_STATEMENT
Node type constant indicating a node of type
LabeledStatement . |
static int |
LAMBDA_EXPRESSION
Node type constant indicating a node of type
LambdaExpression . |
static int |
LINE_COMMENT
Node type constant indicating a node of type
LineComment . |
static int |
MALFORMED
Flag constant (bit mask, value 1) indicating that there is something
not quite right with this AST node.
|
static int |
MARKER_ANNOTATION
Node type constant indicating a node of type
MarkerAnnotation . |
static int |
MEMBER_REF
Node type constant indicating a node of type
MemberRef . |
static int |
MEMBER_VALUE_PAIR
Node type constant indicating a node of type
MemberValuePair . |
static int |
METHOD_DECLARATION
Node type constant indicating a node of type
MethodDeclaration . |
static int |
METHOD_INVOCATION
Node type constant indicating a node of type
MethodInvocation . |
static int |
METHOD_REF
Node type constant indicating a node of type
MethodRef . |
static int |
METHOD_REF_PARAMETER
Node type constant indicating a node of type
MethodRefParameter . |
static int |
MODIFIER
Node type constant indicating a node of type
Modifier . |
static int |
NAME_QUALIFIED_TYPE
Node type constant indicating a node of type
NameQualifiedType . |
static int |
NORMAL_ANNOTATION
Node type constant indicating a node of type
NormalAnnotation . |
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 |
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 |
PARAMETERIZED_TYPE
Node type constant indicating a node of type
ParameterizedType . |
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 |
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_MEMBER_ANNOTATION
Node type constant indicating a node of type
SingleMemberAnnotation . |
static int |
SINGLE_VARIABLE_DECLARATION
Node type constant indicating a node of type
SingleVariableDeclaration . |
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 |
SUPER_METHOD_REFERENCE
Node type constant indicating a node of type
SuperMethhodReference . |
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 |
SYNCHRONIZED_STATEMENT
Node type constant indicating a node of type
SynchronizedStatement . |
static int |
TAG_ELEMENT
Node type constant indicating a node of type
TagElement . |
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_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 |
TYPE_METHOD_REFERENCE
Node type constant indicating a node of type
TypeMethodReference . |
static int |
TYPE_PARAMETER
Node type constant indicating a node of type
TypeParameter . |
static int |
UNION_TYPE
Node type constant indicating a node of type
UnionType . |
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 |
WILDCARD_TYPE
Node type constant indicating a node of type
WildcardType . |
Modifier and Type | Method and Description |
---|---|
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 List |
copySubtrees(AST target,
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(Object obj)
The
ASTNode implementation of this Object
method uses object identity (==). |
AST |
getAST()
Returns this node's AST.
|
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. |
Object |
getProperty(String propertyName)
Returns the value of 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.
|
Object |
getStructuralProperty(StructuralPropertyDescriptor property)
Returns the value of the given structural property for this node.
|
int |
hashCode() |
static Class |
nodeClassForType(int nodeType)
Returns the node class for the corresponding node type.
|
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(String propertyName,
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,
Object value)
Sets the value of the given structural property for this node.
|
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,
Object other)
Returns whether the subtree rooted at the given node matches the
given other object as decided by the given matcher.
|
String |
toString()
Returns a string representation of this node suitable for debugging
purposes only.
|
public static final int ANONYMOUS_CLASS_DECLARATION
AnonymousClassDeclaration
.AnonymousClassDeclaration
,
Constant Field Valuespublic static final int ARRAY_ACCESS
ArrayAccess
.ArrayAccess
,
Constant Field Valuespublic static final int ARRAY_CREATION
ArrayCreation
.ArrayCreation
,
Constant Field Valuespublic static final int ARRAY_INITIALIZER
ArrayInitializer
.ArrayInitializer
,
Constant Field Valuespublic static final int ARRAY_TYPE
ArrayType
.ArrayType
,
Constant Field Valuespublic static final int ASSERT_STATEMENT
AssertStatement
.AssertStatement
,
Constant Field Valuespublic static final int ASSIGNMENT
Assignment
.Assignment
,
Constant Field Valuespublic static final int BLOCK
Block
.Block
,
Constant Field Valuespublic static final int BOOLEAN_LITERAL
BooleanLiteral
.BooleanLiteral
,
Constant Field Valuespublic static final int BREAK_STATEMENT
BreakStatement
.BreakStatement
,
Constant Field Valuespublic static final int CAST_EXPRESSION
CastExpression
.CastExpression
,
Constant Field Valuespublic static final int CATCH_CLAUSE
CatchClause
.CatchClause
,
Constant Field Valuespublic static final int CHARACTER_LITERAL
CharacterLiteral
.CharacterLiteral
,
Constant Field Valuespublic static final int CLASS_INSTANCE_CREATION
ClassInstanceCreation
.ClassInstanceCreation
,
Constant Field Valuespublic static final int COMPILATION_UNIT
CompilationUnit
.CompilationUnit
,
Constant Field Valuespublic static final int CONDITIONAL_EXPRESSION
ConditionalExpression
.ConditionalExpression
,
Constant Field Valuespublic static final int CONSTRUCTOR_INVOCATION
ConstructorInvocation
.ConstructorInvocation
,
Constant Field Valuespublic static final int CONTINUE_STATEMENT
ContinueStatement
.ContinueStatement
,
Constant Field Valuespublic static final int DO_STATEMENT
DoStatement
.DoStatement
,
Constant Field Valuespublic static final int EMPTY_STATEMENT
EmptyStatement
.EmptyStatement
,
Constant Field Valuespublic static final int EXPRESSION_STATEMENT
ExpressionStatement
.ExpressionStatement
,
Constant Field Valuespublic static final int FIELD_ACCESS
FieldAccess
.FieldAccess
,
Constant Field Valuespublic static final int FIELD_DECLARATION
FieldDeclaration
.FieldDeclaration
,
Constant Field Valuespublic static final int FOR_STATEMENT
ForStatement
.ForStatement
,
Constant Field Valuespublic static final int IF_STATEMENT
IfStatement
.IfStatement
,
Constant Field Valuespublic static final int IMPORT_DECLARATION
ImportDeclaration
.ImportDeclaration
,
Constant Field Valuespublic static final int INFIX_EXPRESSION
InfixExpression
.InfixExpression
,
Constant Field Valuespublic static final int INITIALIZER
Initializer
.Initializer
,
Constant Field Valuespublic static final int JAVADOC
Javadoc
.Javadoc
,
Constant Field Valuespublic static final int LABELED_STATEMENT
LabeledStatement
.LabeledStatement
,
Constant Field Valuespublic static final int METHOD_DECLARATION
MethodDeclaration
.MethodDeclaration
,
Constant Field Valuespublic static final int METHOD_INVOCATION
MethodInvocation
.MethodInvocation
,
Constant Field Valuespublic static final int NULL_LITERAL
NullLiteral
.NullLiteral
,
Constant Field Valuespublic static final int NUMBER_LITERAL
NumberLiteral
.NumberLiteral
,
Constant Field Valuespublic static final int PACKAGE_DECLARATION
PackageDeclaration
.PackageDeclaration
,
Constant Field Valuespublic static final int PARENTHESIZED_EXPRESSION
ParenthesizedExpression
.ParenthesizedExpression
,
Constant Field Valuespublic static final int POSTFIX_EXPRESSION
PostfixExpression
.PostfixExpression
,
Constant Field Valuespublic static final int PREFIX_EXPRESSION
PrefixExpression
.PrefixExpression
,
Constant Field Valuespublic static final int PRIMITIVE_TYPE
PrimitiveType
.PrimitiveType
,
Constant Field Valuespublic static final int QUALIFIED_NAME
QualifiedName
.QualifiedName
,
Constant Field Valuespublic static final int RETURN_STATEMENT
ReturnStatement
.ReturnStatement
,
Constant Field Valuespublic static final int SIMPLE_NAME
SimpleName
.SimpleName
,
Constant Field Valuespublic static final int SIMPLE_TYPE
SimpleType
.SimpleType
,
Constant Field Valuespublic static final int SINGLE_VARIABLE_DECLARATION
SingleVariableDeclaration
.SingleVariableDeclaration
,
Constant Field Valuespublic static final int STRING_LITERAL
StringLiteral
.StringLiteral
,
Constant Field Valuespublic static final int SUPER_CONSTRUCTOR_INVOCATION
SuperConstructorInvocation
.SuperConstructorInvocation
,
Constant Field Valuespublic static final int SUPER_FIELD_ACCESS
SuperFieldAccess
.SuperFieldAccess
,
Constant Field Valuespublic static final int SUPER_METHOD_INVOCATION
SuperMethodInvocation
.SuperMethodInvocation
,
Constant Field Valuespublic static final int SWITCH_CASE
SwitchCase
.SwitchCase
,
Constant Field Valuespublic static final int SWITCH_STATEMENT
SwitchStatement
.SwitchStatement
,
Constant Field Valuespublic static final int SYNCHRONIZED_STATEMENT
SynchronizedStatement
.SynchronizedStatement
,
Constant Field Valuespublic static final int THIS_EXPRESSION
ThisExpression
.ThisExpression
,
Constant Field Valuespublic static final int THROW_STATEMENT
ThrowStatement
.ThrowStatement
,
Constant Field Valuespublic static final int TRY_STATEMENT
TryStatement
.TryStatement
,
Constant Field Valuespublic static final int TYPE_DECLARATION
TypeDeclaration
.TypeDeclaration
,
Constant Field Valuespublic static final int TYPE_DECLARATION_STATEMENT
TypeDeclarationStatement
.TypeDeclarationStatement
,
Constant Field Valuespublic static final int TYPE_LITERAL
TypeLiteral
.TypeLiteral
,
Constant Field Valuespublic static final int VARIABLE_DECLARATION_EXPRESSION
VariableDeclarationExpression
.public static final int VARIABLE_DECLARATION_FRAGMENT
VariableDeclarationFragment
.VariableDeclarationFragment
,
Constant Field Valuespublic static final int VARIABLE_DECLARATION_STATEMENT
VariableDeclarationStatement
.public static final int WHILE_STATEMENT
WhileStatement
.WhileStatement
,
Constant Field Valuespublic static final int INSTANCEOF_EXPRESSION
InstanceofExpression
.InstanceofExpression
,
Constant Field Valuespublic static final int LINE_COMMENT
LineComment
.LineComment
,
Constant Field Valuespublic static final int BLOCK_COMMENT
BlockComment
.BlockComment
,
Constant Field Valuespublic static final int TAG_ELEMENT
TagElement
.TagElement
,
Constant Field Valuespublic static final int TEXT_ELEMENT
TextElement
.TextElement
,
Constant Field Valuespublic static final int MEMBER_REF
MemberRef
.MemberRef
,
Constant Field Valuespublic static final int METHOD_REF
MethodRef
.MethodRef
,
Constant Field Valuespublic static final int METHOD_REF_PARAMETER
MethodRefParameter
.MethodRefParameter
,
Constant Field Valuespublic static final int ENHANCED_FOR_STATEMENT
EnhancedForStatement
.EnhancedForStatement
,
Constant Field Valuespublic static final int ENUM_DECLARATION
EnumDeclaration
.EnumDeclaration
,
Constant Field Valuespublic static final int ENUM_CONSTANT_DECLARATION
EnumConstantDeclaration
.EnumConstantDeclaration
,
Constant Field Valuespublic static final int TYPE_PARAMETER
TypeParameter
.TypeParameter
,
Constant Field Valuespublic static final int PARAMETERIZED_TYPE
ParameterizedType
.ParameterizedType
,
Constant Field Valuespublic static final int QUALIFIED_TYPE
QualifiedType
.QualifiedType
,
Constant Field Valuespublic static final int WILDCARD_TYPE
WildcardType
.WildcardType
,
Constant Field Valuespublic static final int NORMAL_ANNOTATION
NormalAnnotation
.NormalAnnotation
,
Constant Field Valuespublic static final int MARKER_ANNOTATION
MarkerAnnotation
.MarkerAnnotation
,
Constant Field Valuespublic static final int SINGLE_MEMBER_ANNOTATION
SingleMemberAnnotation
.SingleMemberAnnotation
,
Constant Field Valuespublic static final int MEMBER_VALUE_PAIR
MemberValuePair
.MemberValuePair
,
Constant Field Valuespublic static final int ANNOTATION_TYPE_DECLARATION
AnnotationTypeDeclaration
.AnnotationTypeDeclaration
,
Constant Field Valuespublic static final int ANNOTATION_TYPE_MEMBER_DECLARATION
AnnotationTypeMemberDeclaration
.AnnotationTypeMemberDeclaration
,
Constant Field Valuespublic static final int MODIFIER
Modifier
.Modifier
,
Constant Field Valuespublic static final int UNION_TYPE
UnionType
.UnionType
,
Constant Field Valuespublic static final int DIMENSION
Dimension
.Dimension
,
Constant Field Valuespublic static final int LAMBDA_EXPRESSION
LambdaExpression
.LambdaExpression
,
Constant Field Valuespublic static final int INTERSECTION_TYPE
IntersectionType
.IntersectionType
,
Constant Field Valuespublic static final int NAME_QUALIFIED_TYPE
NameQualifiedType
.NameQualifiedType
,
Constant Field Valuespublic static final int CREATION_REFERENCE
CreationReference
.CreationReference
,
Constant Field Valuespublic static final int EXPRESSION_METHOD_REFERENCE
ExpressionMethodReference
.ExpressionMethodReference
,
Constant Field Valuespublic static final int SUPER_METHOD_REFERENCE
SuperMethhodReference
.SuperMethodReference
,
Constant Field Valuespublic static final int TYPE_METHOD_REFERENCE
TypeMethodReference
.TypeMethodReference
,
Constant Field Valuespublic static final int MALFORMED
The standard parser (ASTParser
) sets this
flag on a node to indicate a syntax error detected in the vicinity.
public static final int ORIGINAL
The standard parser (ASTParser
) sets this
flag on the nodes it creates.
public static final int PROTECT
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.
public static final int RECOVERED
The standard parser (ASTParser
) sets this
flag on a node to indicate a recovered node.
public static Class nodeClassForType(int nodeType)
nodeType
- AST node typeASTNode
subclassIllegalArgumentException
- if nodeType
is
not a legal AST node typegetNodeType()
public final AST getAST()
Note that the relationship between an AST node and its owing AST does not change over the lifetime of a node.
public final ASTNode getParent()
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.
null
if nonepublic final StructuralPropertyDescriptor getLocationInParent()
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.
null
if this node has no parentpublic final ASTNode getRoot()
public final Object getStructuralProperty(StructuralPropertyDescriptor 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 noneChildListPropertyDescriptor
- the list (element type: ASTNode
)property
- the propertynull
if noneRuntimeException
- if this node does not have the given propertypublic final void setStructuralProperty(StructuralPropertyDescriptor property, Object value)
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 noneChildListPropertyDescriptor
- not allowedproperty
- the propertyvalue
- the property valueRuntimeException
- if this node does not have the
given property, or if the given property cannot be setpublic final List structuralPropertiesForType()
Note that property descriptors are a meta-level mechanism
for manipulating ASTNodes in a generic way. They are
unrelated to get/setProperty
.
StructuralPropertyDescriptor
)public final void delete()
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.public final Object getProperty(String propertyName)
null
if none.propertyName
- the property namenull
if nonesetProperty(String,Object)
public final void setProperty(String propertyName, Object data)
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.
propertyName
- the property namedata
- the new property value, or null
if noneIllegalArgumentException
- if the given property name is null
getProperty(String)
public final Map properties()
null
values.String
; value type: Object
)public final int getFlags()
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.setFlags(int)
public final void setFlags(int flags)
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 errorNote that the flags are not considered a structural property of the node, and can be changed even if the node is marked as protected.
flags
- the bitwise-or of individual flagsgetFlags()
public final int getNodeType()
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
.
public final boolean equals(Object obj)
ASTNode
implementation of this Object
method uses object identity (==). Use subtreeMatch
to
compare two subtrees for equality.equals
in class Object
obj
- subtreeMatch(ASTMatcher matcher, Object other)
public final boolean subtreeMatch(ASTMatcher matcher, Object other)
matcher
- the matcherother
- the other object, or null
true
if the subtree matches, or
false
if they do not matchpublic static ASTNode copySubtree(AST target, ASTNode node)
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.
target
- the AST that is to own the nodes in the resultnode
- the node to copy, or null
if nonenull
if node
is null
public static List copySubtrees(AST target, List nodes)
Source range information on the original nodes is automatically copied to the new
nodes. Client properties (properties
) are not carried over.
public final void accept(ASTVisitor visitor)
visitor
- the visitor objectIllegalArgumentException
- if the visitor is nullpublic final int getStartPosition()
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.
-1
if no source position information is recorded for this nodegetLength()
,
ASTParser
public final int getLength()
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.
0
if no source position information is recorded for this nodegetStartPosition()
,
ASTParser
public final void setSourceRange(int startPosition, int length)
See ASTParser.setKind(int)
for details
on precisely where source ranges are supposed to begin and end.
startPosition
- a 0-based character index,
or -1
if no source position information is
available for this nodelength
- a (possibly 0) length,
or 0
if no source position information is recorded
for this nodegetStartPosition()
,
getLength()
,
ASTParser
public final String toString()
public final int subtreeBytes()
Copyright (c) 2000, 2015 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.