|
|||||||||
| Home >> All >> org >> eclipse >> jdt >> core >> [ dom overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.eclipse.jdt.core.dom
Class ASTNode

java.lang.Objectorg.eclipse.jdt.core.dom.ASTNode
- Direct Known Subclasses:
- AnonymousClassDeclaration, BodyDeclaration, CatchClause, Comment, CompilationUnit, Expression, ImportDeclaration, MemberRef, MemberValuePair, MethodRef, MethodRefParameter, Modifier, PackageDeclaration, Statement, TagElement, TextElement, Type, TypeParameter, VariableDeclaration
- public abstract class ASTNode
- extends java.lang.Object
Abstract superclass of all Abstract Syntax Tree (AST) node types.
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
set 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
new factory methods (see AST) to
create new nodes, and the various set 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.
Compilation units created by ASTParser from a
source document can be serialized after arbitrary modifications
with minimal loss of original formatting. See
CompilationUnit.recordModifications() 55 for details.
See also org.eclipse.jdt.core.dom.rewrite.ASTRewrite for
an alternative way to describe and serialize changes to a
read-only AST.
- Since:
- 2.0
| Nested Class Summary | |
(package private) class |
ASTNode.NodeList
A specialized implementation of a list of ASTNodes. |
| Field Summary | |
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. |
(package private) AST |
ast
Owning AST. |
(package private) static int |
BASE_NODE_SIZE
Approximate base size of an AST node instance in bytes, including object header and instance fields. |
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. |
(package private) static boolean |
CYCLE_RISK
Internal convenience constant indicating that there is definite risk of cycles. |
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_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. |
(package private) static int |
HEADERS
Estimate of size of an object header in bytes. |
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 |
JAVADOC
Node type constant indicating a node of type Javadoc. |
static int |
LABELED_STATEMENT
Node type constant indicating a node of type LabeledStatement. |
private int |
length
A character length, or 0 if no source position
information is recorded for this node; 0 by default. |
static int |
LINE_COMMENT
Node type constant indicating a node of type LineComment. |
private StructuralPropertyDescriptor |
location
Property of parent in which this node is a child, or null
if this node is a root. |
static int |
MALFORMED
Flag constant (bit mask, value 1) indicating that there is something not quite right with this AST node. |
(package private) static boolean |
MANDATORY
Internal convenience constant indicating that a structural property is mandatory. |
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. |
(package private) static boolean |
NO_CYCLE_RISK
Internal convenience constant indicating that there is no risk of cycles. |
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. |
(package private) static boolean |
OPTIONAL
Internal convenience constant indicating that a structural property is optional. |
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. |
private ASTNode |
parent
Parent AST node, or null if this node is a root. |
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. |
private java.lang.Object |
property1
Primary field used in representing node properties efficiently. |
private java.lang.Object |
property2
Auxillary field used in representing node properties efficiently. |
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 |
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. |
private int |
startPosition
A character index into the original source string, or -1 if no source position information is available
for this node; -1 by default. |
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 |
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_PARAMETER
Node type constant indicating a node of type TypeParameter. |
(package private) int |
typeAndFlags
int containing the node type in the top 16 bits and flags in the bottom 16 bits; none set by default. |
private static java.util.Map |
UNMODIFIABLE_EMPTY_MAP
An unmodifiable empty map (used to implement properties()). |
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. |
| Constructor Summary | |
(package private) |
ASTNode(AST ast)
Creates a new AST node owned by the given AST. |
| Method Summary | |
void |
accept(ASTVisitor visitor)
Accepts the given visitor on a visit of the current node. |
(package private) abstract void |
accept0(ASTVisitor visitor)
Accepts the given visitor on a type-specific visit of the current node. |
(package private) void |
acceptChild(ASTVisitor visitor,
ASTNode child)
Accepts the given visitor on a visit of the current node. |
(package private) void |
acceptChildren(ASTVisitor visitor,
ASTNode.NodeList children)
Accepts the given visitor on a visit of the given live list of child nodes. |
(package private) static void |
addProperty(StructuralPropertyDescriptor property,
java.util.List propertyList)
Internal helper method that adding a property descriptor. |
(package private) void |
appendDebugString(java.lang.StringBuffer buffer)
Appends a debug representation of this node to the given string buffer. |
(package private) void |
appendPrintString(java.lang.StringBuffer buffer)
Appends a standard Java source code representation of this subtree to the given string buffer. |
(package private) void |
checkModifiable()
Ensures that this node is modifiable (that is, not marked PROTECTED). |
(package private) static void |
checkNewChild(ASTNode node,
ASTNode newChild,
boolean cycleCheck,
java.lang.Class nodeType)
Checks whether the given new child node is a node in a different AST from its parent-to-be, whether it is already has a parent, whether adding it to its parent-to-be would create a cycle, and whether the child is of the right type. |
(package private) ASTNode |
clone(AST target)
Returns a deep copy of the subtree of AST nodes rooted at this node. |
(package private) abstract ASTNode |
clone0(AST target)
Returns a deep copy of the subtree of AST nodes rooted at this 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. |
(package private) static void |
createPropertyList(java.lang.Class nodeClass,
java.util.List propertyList)
Internal helper method that starts the building a list of property descriptors for the given node type. |
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. |
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. |
(package private) abstract int |
getNodeType0()
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. |
(package private) java.util.List |
internalGetChildListProperty(ChildListPropertyDescriptor property)
Returns the list value of the given property for this node. |
(package private) boolean |
internalGetSetBooleanProperty(SimplePropertyDescriptor property,
boolean get,
boolean value)
Sets the value of the given boolean-valued property for this node. |
(package private) ASTNode |
internalGetSetChildProperty(ChildPropertyDescriptor property,
boolean get,
ASTNode child)
Sets the child value of the given property for this node. |
(package private) int |
internalGetSetIntProperty(SimplePropertyDescriptor property,
boolean get,
int value)
Sets the value of the given int-valued property for this node. |
(package private) java.lang.Object |
internalGetSetObjectProperty(SimplePropertyDescriptor property,
boolean get,
java.lang.Object value)
Sets the value of the given property for this node. |
(package private) abstract java.util.List |
internalStructuralPropertiesForType(int apiLevel)
Returns a list of property descriptors for this node type. |
(package private) abstract int |
memSize()
Returns an estimate of the memory footprint of this node in bytes. |
static java.lang.Class |
nodeClassForType(int nodeType)
Returns the node class for the corresponding node type. |
(package private) void |
postLazyInit(ASTNode newChild,
ChildPropertyDescriptor property)
End lazy initialization of this node. |
(package private) void |
postReplaceChild(ASTNode oldChild,
ASTNode newChild,
ChildPropertyDescriptor property)
Postlude portion of the "3 step program" for replacing the old child of this node with another node. |
(package private) void |
postValueChange(SimplePropertyDescriptor property)
Postlude portion of the "3 step program" for replacing the old child of this node with another node. |
(package private) void |
preLazyInit()
Begin lazy initialization of this node. |
(package private) void |
preReplaceChild(ASTNode oldChild,
ASTNode newChild,
ChildPropertyDescriptor property)
Prelude portion of the "3 step program" for replacing the old child of this node with another node. |
(package private) void |
preValueChange(SimplePropertyDescriptor property)
Prelude portion of the "3 step program" for changing the value of a simple property of this node. |
java.util.Map |
properties()
Returns an unmodifiable table of the properties of this node with non- null values. |
(package private) static java.util.List |
reapPropertyList(java.util.List propertyList)
Internal helper method that completes the building of a node type's structural property descriptor list. |
void |
setFlags(int flags)
Sets the flags associated with this node to the given value. |
private void |
setNodeType(int nodeType)
Sets the integer value identifying the type of this concrete AST node. |
(package private) void |
setParent(ASTNode parent,
StructuralPropertyDescriptor property)
Sets or clears this node's parent node and location. |
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. |
(package private) java.lang.String |
standardToString()
Returns the string representation of this node produced by the standard Object.toString method. |
(package private) static int |
stringSize(java.lang.String string)
Returns an estimate of the memory footprint, in bytes, of the given string. |
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. |
(package private) abstract boolean |
subtreeMatch0(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. |
(package private) void |
supportedOnlyIn2()
Checks that this AST operation is only used when building JLS2 level ASTs. |
java.lang.String |
toString()
Returns a string representation of this node suitable for debugging purposes only. |
(package private) abstract int |
treeSize()
Returns an estimate of the memory footprint in bytes of the entire subtree rooted at this node. |
(package private) void |
unsupportedIn2()
Checks that this AST operation is not used when building JLS2 level ASTs. |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, 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.
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
ASSERT_STATEMENT
public static final int ASSERT_STATEMENT
- Node type constant indicating a node of type
AssertStatement.- See Also:
- AssertStatement, 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
CAST_EXPRESSION
public static final int CAST_EXPRESSION
- Node type constant indicating a node of type
CastExpression.- See Also:
- CastExpression, 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
COMPILATION_UNIT
public static final int COMPILATION_UNIT
- Node type constant indicating a node of type
CompilationUnit.- See Also:
- CompilationUnit, 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
JAVADOC
public static final int JAVADOC
- Node type constant indicating a node of type
Javadoc.- See Also:
- Javadoc, 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
METHOD_DECLARATION
public static final int METHOD_DECLARATION
- Node type constant indicating a node of type
MethodDeclaration.- See Also:
- MethodDeclaration, Constant Field Values
METHOD_INVOCATION
public static final int METHOD_INVOCATION
- Node type constant indicating a node of type
MethodInvocation.- See Also:
- MethodInvocation, 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.
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.
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
SYNCHRONIZED_STATEMENT
public static final int SYNCHRONIZED_STATEMENT
- Node type constant indicating a node of type
SynchronizedStatement.- See Also:
- SynchronizedStatement, 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.
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.
VARIABLE_DECLARATION_FRAGMENT
public static final int VARIABLE_DECLARATION_FRAGMENT
- Node type constant indicating a node of type
VariableDeclarationFragment.
VARIABLE_DECLARATION_STATEMENT
public static final int VARIABLE_DECLARATION_STATEMENT
- Node type constant indicating a node of type
VariableDeclarationStatement.
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.- Since:
- 3.0
- See Also:
- LineComment, Constant Field Values
BLOCK_COMMENT
public static final int BLOCK_COMMENT
- Node type constant indicating a node of type
BlockComment.- Since:
- 3.0
- See Also:
- BlockComment, Constant Field Values
TAG_ELEMENT
public static final int TAG_ELEMENT
- Node type constant indicating a node of type
TagElement.- Since:
- 3.0
- See Also:
- TagElement, Constant Field Values
TEXT_ELEMENT
public static final int TEXT_ELEMENT
- Node type constant indicating a node of type
TextElement.- Since:
- 3.0
- See Also:
- TextElement, Constant Field Values
MEMBER_REF
public static final int MEMBER_REF
- Node type constant indicating a node of type
MemberRef.- Since:
- 3.0
- See Also:
- MemberRef, Constant Field Values
METHOD_REF
public static final int METHOD_REF
- Node type constant indicating a node of type
MethodRef.- Since:
- 3.0
- See Also:
- MethodRef, Constant Field Values
METHOD_REF_PARAMETER
public static final int METHOD_REF_PARAMETER
- Node type constant indicating a node of type
MethodRefParameter.- Since:
- 3.0
- See Also:
- MethodRefParameter, Constant Field Values
ENHANCED_FOR_STATEMENT
public static final int ENHANCED_FOR_STATEMENT
- Node type constant indicating a node of type
EnhancedForStatement.- Since:
- 3.0
- See Also:
- EnhancedForStatement, Constant Field Values
ENUM_DECLARATION
public static final int ENUM_DECLARATION
- Node type constant indicating a node of type
EnumDeclaration.- Since:
- 3.0
- See Also:
- EnumDeclaration, Constant Field Values
ENUM_CONSTANT_DECLARATION
public static final int ENUM_CONSTANT_DECLARATION
- Node type constant indicating a node of type
EnumConstantDeclaration.- Since:
- 3.0
- See Also:
- EnumConstantDeclaration, Constant Field Values
TYPE_PARAMETER
public static final int TYPE_PARAMETER
- Node type constant indicating a node of type
TypeParameter.- Since:
- 3.0
- See Also:
- TypeParameter, Constant Field Values
PARAMETERIZED_TYPE
public static final int PARAMETERIZED_TYPE
- Node type constant indicating a node of type
ParameterizedType.- Since:
- 3.0
- See Also:
- ParameterizedType, Constant Field Values
QUALIFIED_TYPE
public static final int QUALIFIED_TYPE
- Node type constant indicating a node of type
QualifiedType.- Since:
- 3.0
- See Also:
- QualifiedType, Constant Field Values
WILDCARD_TYPE
public static final int WILDCARD_TYPE
- Node type constant indicating a node of type
WildcardType.- Since:
- 3.0
- See Also:
- WildcardType, Constant Field Values
NORMAL_ANNOTATION
public static final int NORMAL_ANNOTATION
- Node type constant indicating a node of type
NormalAnnotation.- Since:
- 3.0
- See Also:
- NormalAnnotation, Constant Field Values
MARKER_ANNOTATION
public static final int MARKER_ANNOTATION
- Node type constant indicating a node of type
MarkerAnnotation.- Since:
- 3.0
- See Also:
- MarkerAnnotation, Constant Field Values
SINGLE_MEMBER_ANNOTATION
public static final int SINGLE_MEMBER_ANNOTATION
- Node type constant indicating a node of type
SingleMemberAnnotation.- Since:
- 3.0
- See Also:
- SingleMemberAnnotation, Constant Field Values
MEMBER_VALUE_PAIR
public static final int MEMBER_VALUE_PAIR
- Node type constant indicating a node of type
MemberValuePair.- Since:
- 3.0
- See Also:
- MemberValuePair, Constant Field Values
ANNOTATION_TYPE_DECLARATION
public static final int ANNOTATION_TYPE_DECLARATION
- Node type constant indicating a node of type
AnnotationTypeDeclaration.- Since:
- 3.0
- See Also:
- AnnotationTypeDeclaration, Constant Field Values
ANNOTATION_TYPE_MEMBER_DECLARATION
public static final int ANNOTATION_TYPE_MEMBER_DECLARATION
- Node type constant indicating a node of type
AnnotationTypeMemberDeclaration.- Since:
- 3.0
- See Also:
- AnnotationTypeMemberDeclaration, Constant Field Values
MODIFIER
public static final int MODIFIER
- Node type constant indicating a node of type
Modifier.- Since:
- 3.0
- See Also:
- Modifier, Constant Field Values
ast
final AST ast
- Owning AST.
N.B. This ia a private field, but declared as package-visible for more efficient access from inner classes.
parent
private ASTNode parent
- Parent AST node, or
nullif this node is a root. Initiallynull.
UNMODIFIABLE_EMPTY_MAP
private static java.util.Map UNMODIFIABLE_EMPTY_MAP
- An unmodifiable empty map (used to implement
properties()).
property1
private java.lang.Object property1
- Primary field used in representing node properties efficiently.
If
null, this node has no properties. If aString, this is the name of this node's sole property, andproperty2contains its value. If aHashMap, this is the table of property name-value mappings;property2, if non-null is its unmodifiable equivalent. Initiallynull.- See Also:
property255
property2
private java.lang.Object property2
- Auxillary field used in representing node properties efficiently.
- See Also:
property155
startPosition
private int startPosition
- A character index into the original source string,
or
-1if no source position information is available for this node;-1by default.
length
private int length
- A character length, or
0if no source position information is recorded for this node;0by default.
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.- Since:
- 3.0
- 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.- Since:
- 3.0
- See Also:
- Constant Field Values
typeAndFlags
int typeAndFlags
- int containing the node type in the top 16 bits and
flags in the bottom 16 bits; none set by default.
N.B. This is a private field, but declared as package-visible for more efficient access from inner classes.
- See Also:
MALFORMED55
location
private StructuralPropertyDescriptor location
- Property of parent in which this node is a child, or
nullif this node is a root. Initiallynull.- Since:
- 3.0
- See Also:
getLocationInParent()55
CYCLE_RISK
static boolean CYCLE_RISK
- Internal convenience constant indicating that there is definite risk of cycles.
- Since:
- 3.0
NO_CYCLE_RISK
static boolean NO_CYCLE_RISK
- Internal convenience constant indicating that there is no risk of cycles.
- Since:
- 3.0
MANDATORY
static boolean MANDATORY
- Internal convenience constant indicating that a structural property is mandatory.
- Since:
- 3.0
OPTIONAL
static boolean OPTIONAL
- Internal convenience constant indicating that a structural property is optional.
- Since:
- 3.0
HEADERS
static final int HEADERS
- Estimate of size of an object header in bytes.
- See Also:
- Constant Field Values
BASE_NODE_SIZE
static final int BASE_NODE_SIZE
- Approximate base size of an AST node instance in bytes,
including object header and instance fields.
That is, HEADERS + (# instance vars in ASTNode)*4.
- See Also:
- Constant Field Values
| Constructor Detail |
ASTNode
ASTNode(AST ast)
- Creates a new AST node owned by the given AST. Once established,
the relationship between an AST node and its owning AST does not change
over the lifetime of the node. The new node has no parent node,
and no properties.
N.B. This constructor is package-private; all subclasses my be declared in the same package; clients are unable to declare additional subclasses.
| Method Detail |
nodeClassForType
public static java.lang.Class nodeClassForType(int nodeType)
- Returns the node class for the corresponding node type.
- Since:
- 3.0
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.
getParent
public final ASTNode getParent()
- Returns this node's parent node, or
nullif 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.
getLocationInParent
public final StructuralPropertyDescriptor getLocationInParent()
- Returns the location of this node within its parent,
or
nullif 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.
- Since:
- 3.0
getRoot
public final ASTNode getRoot()
- Returns the root node at or above this node; returns this node if
it is a root.
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
nullif none; primitive values are "boxed" - ChildPropertyDescriptor - the child node (type
ASTNode), ornullif none - ChildListPropertyDescriptor - the list (element type: ASTNode)
- Since:
- 3.0
- SimplePropertyDescriptor - the value of the given simple property,
or
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
nullif none; primitive values are "boxed" - ChildPropertyDescriptor - the new child node (type
ASTNode), ornullif none - ChildListPropertyDescriptor - not allowed
- Since:
- 3.0
- SimplePropertyDescriptor - the new value of the given simple property,
or
internalGetSetIntProperty
int internalGetSetIntProperty(SimplePropertyDescriptor property, boolean get, int value)
- Sets the value of the given int-valued property for this node.
The default implementation of this method throws an exception explaining
that this node does not have such a property. This method should be
extended in subclasses that have at leasy one simple property whose value
type is int.
- Since:
- 3.0
internalGetSetBooleanProperty
boolean internalGetSetBooleanProperty(SimplePropertyDescriptor property, boolean get, boolean value)
- Sets the value of the given boolean-valued property for this node.
The default implementation of this method throws an exception explaining
that this node does not have such a property. This method should be
extended in subclasses that have at leasy one simple property whose value
type is boolean.
- Since:
- 3.0
internalGetSetObjectProperty
java.lang.Object internalGetSetObjectProperty(SimplePropertyDescriptor property, boolean get, java.lang.Object value)
- Sets the value of the given property for this node.
The default implementation of this method throws an exception explaining
that this node does not have such a property. This method should be
extended in subclasses that have at leasy one simple property whose value
type is a reference type.
- Since:
- 3.0
internalGetSetChildProperty
ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child)
- Sets the child value of the given property for this node.
The default implementation of this method throws an exception explaining
that this node does not have such a property. This method should be
extended in subclasses that have at leasy one child property.
- Since:
- 3.0
internalGetChildListProperty
java.util.List internalGetChildListProperty(ChildListPropertyDescriptor property)
- Returns the list value of the given property for this node.
The default implementation of this method throws an exception explaining
that this noed does not have such a property. This method should be
extended in subclasses that have at leasy one child list property.
- Since:
- 3.0
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.- Since:
- 3.0
internalStructuralPropertiesForType
abstract java.util.List internalStructuralPropertiesForType(int apiLevel)
- Returns a list of property descriptors for this node type.
Clients must not modify the result. This abstract method
must be implemented in each concrete AST node type.
N.B. This method is package-private, so that the implementations of this method in each of the concrete AST node types do not clutter up the API doc.
- Since:
- 3.0
createPropertyList
static void createPropertyList(java.lang.Class nodeClass, java.util.List propertyList)
- Internal helper method that starts the building a list of
property descriptors for the given node type.
addProperty
static void addProperty(StructuralPropertyDescriptor property, java.util.List propertyList)
- Internal helper method that adding a property descriptor.
reapPropertyList
static java.util.List reapPropertyList(java.util.List propertyList)
- Internal helper method that completes the building of
a node type's structural property descriptor list.
unsupportedIn2
final void unsupportedIn2()
- Checks that this AST operation is not used when
building JLS2 level ASTs.
- Since:
- 3.0
supportedOnlyIn2
final void supportedOnlyIn2()
- Checks that this AST operation is only used when
building JLS2 level ASTs.
- Since:
- 3.0
setParent
final void setParent(ASTNode parent, StructuralPropertyDescriptor property)
- Sets or clears this node's parent node and location.
Note that this method is package-private. The pointer from a node to its parent is set implicitly as a side effect of inserting or removing the node as a child of another node. This method calls
ast.modifying().- 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 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 passingnullto the appropriate setter method; this operation fails if this node is in a mandatory property.- Since:
- 3.0
checkNewChild
static void checkNewChild(ASTNode node, ASTNode newChild, boolean cycleCheck, java.lang.Class nodeType)
- Checks whether the given new child node is a node
in a different AST from its parent-to-be, whether it is
already has a parent, whether adding it to its
parent-to-be would create a cycle, and whether the child is of
the right type. The parent-to-be is the enclosing instance.
preReplaceChild
final void preReplaceChild(ASTNode oldChild, ASTNode newChild, ChildPropertyDescriptor property)
- Prelude portion of the "3 step program" for replacing the
old child of this node with another node.
Here is the code pattern found in all AST node subclasses:
ASTNode oldChild = this.foo; preReplaceChild(oldChild, newFoo, FOO_PROPERTY); this.foo = newFoo; postReplaceChild(oldChild, newFoo, FOO_PROPERTY);
The first part (preReplaceChild) does all the precondition checks, reports pre-delete events, and changes parent links. The old child is delinked from its parent (making it a root node), and the new child node is linked to its parent. The new child node must be a root node in the same AST as its new parent, and must not be an ancestor of this node. All three nodes must be modifiable (not PROTECTED). The replace operation must fail atomically; so it is crucial that all precondition checks be done before any linking and delinking happens. The final part (postReplaceChild )reports post-add events.This method calls
ast.modifying()for the nodes affected.- Since:
- 3.0
postReplaceChild
final void postReplaceChild(ASTNode oldChild, ASTNode newChild, ChildPropertyDescriptor property)
- Postlude portion of the "3 step program" for replacing the
old child of this node with another node.
See
preReplaceChild(ASTNode, ASTNode, ChildPropertyDescriptor)55 for details.- Since:
- 3.0
preValueChange
final void preValueChange(SimplePropertyDescriptor property)
- Prelude portion of the "3 step program" for changing the
value of a simple property of this node.
Here is the code pattern found in all AST node subclasses:
preValueChange(FOO_PROPERTY); this.foo = newFoo; postValueChange(FOO_PROPERTY);
The first part (preValueChange) does the precondition check to make sure the node is modifiable (not PROTECTED). The change operation must fail atomically; so it is crucial that the precondition checks are done before the field is hammered. The final part (postValueChange)reports post-change events.This method calls
ast.modifying()for the node affected.- Since:
- 3.0
postValueChange
final void postValueChange(SimplePropertyDescriptor property)
- Postlude portion of the "3 step program" for replacing the
old child of this node with another node.
See
preValueChange(SimplePropertyDescriptor)55 for details.- Since:
- 3.0
checkModifiable
final void checkModifiable()
- Ensures that this node is modifiable (that is, not marked PROTECTED).
If successful, calls ast.modifying().
preLazyInit
final void preLazyInit()
- Begin lazy initialization of this node.
Here is the code pattern found in all AST
node subclasses:
if (this.foo == null) { // lazy init must be thread-safe for readers synchronized (this) { if (this.foo == null) { preLazyInit(); this.foo = ...; // code to create new node postLazyInit(this.foo, FOO_PROPERTY); } } }- Since:
- 3.0
postLazyInit
final void postLazyInit(ASTNode newChild, ChildPropertyDescriptor property)
- End lazy initialization of this node.
- Since:
- 3.0
getProperty
public final java.lang.Object getProperty(java.lang.String propertyName)
- Returns the named property of this node, or
nullif none.
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
nullto 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.
properties
public final java.util.Map properties()
- Returns an unmodifiable table of the properties of this node with
non-
nullvalues.
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:
MALFORMED55 - indicates node is syntactically malformedORIGINAL55 - indicates original node created by ASTParserPROTECT55 - indicates node is protected from further modification
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:
MALFORMED55 - indicates node is syntactically malformedORIGINAL55 - indicates original node created by ASTParserPROTECT55 - indicates node is protected from further modification
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.
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.
setNodeType
private void setNodeType(int nodeType)
- Sets the integer value identifying the type of this concrete AST node.
The values are small positive integers, suitable for use in switch statements.
getNodeType0
abstract int getNodeType0()
- Returns an integer value identifying the type of this concrete AST node.
This internal method is implemented in each of the concrete node subclasses.
equals
public final boolean equals(java.lang.Object obj)
- The
ASTNodeimplementation of thisObjectmethod uses object identity (==). UsesubtreeMatchto compare two subtrees for equality.
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.
subtreeMatch0
abstract boolean subtreeMatch0(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.
This internal method is implemented in each of the concrete node subclasses.
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
ASTand the targetASTmust support the same API level.
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.
clone
final ASTNode clone(AST target)
- Returns a deep copy of the subtree of AST nodes rooted at this node.
The resulting nodes are owned by the given AST, which may be different
from the AST of this node. Even if this node has a parent, the
result node will be unparented.
This method reports pre- and post-clone events, and dispatches to
clone0(AST)which is reimplemented in node subclasses.
clone0
abstract ASTNode clone0(AST target)
- Returns a deep copy of the subtree of AST nodes rooted at this node.
The resulting nodes are owned by the given AST, which may be different
from the AST of this node. Even if this node has a parent, the
result node will be unparented.
This method must be implemented in subclasses.
This method does not report pre- and post-clone events. All callers should instead call
clone(AST)to ensure that pre- and post-clone events are reported.N.B. This method is package-private, so that the implementations of this method in each of the concrete AST node types do not clutter up the API doc.
accept
public final void accept(ASTVisitor visitor)
- Accepts the given visitor on a visit of the current node.
accept0
abstract void accept0(ASTVisitor visitor)
- Accepts the given visitor on a type-specific visit of the current node.
This method must be implemented in all concrete AST node types.
General template for implementation on each concrete ASTNode class:
Note that the caller (boolean visitChildren = visitor.visit(this); if (visitChildren) { // visit children in normal left to right reading order acceptChild(visitor, getProperty1()); acceptChildren(visitor, rawListProperty); acceptChild(visitor, getProperty2()); } visitor.endVisit(this);accept) take cares of invokingvisitor.preVisit(this)andvisitor.postVisit(this).
acceptChild
final void acceptChild(ASTVisitor visitor, ASTNode child)
- Accepts the given visitor on a visit of the current node.
This method should be used by the concrete implementations of
accept0to traverse optional properties. Equivalent tochild.accept(visitor)ifchildis notnull.
acceptChildren
final void acceptChildren(ASTVisitor visitor, ASTNode.NodeList children)
- Accepts the given visitor on a visit of the given live list of
child nodes.
This method must be used by the concrete implementations of
acceptto traverse list-values properties; it encapsulates the proper handling of on-the-fly changes to the list.
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 for details on precisely where source ranges begin and end.
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 methods for details on precisely where source ranges begin and end.
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 for details on precisely where source ranges begin and end.
toString
public final java.lang.String toString()
- Returns a string representation of this node suitable for debugging
purposes only.
standardToString
final java.lang.String standardToString()
- Returns the string representation of this node produced by the standard
Object.toStringmethod.
appendDebugString
void appendDebugString(java.lang.StringBuffer buffer)
- Appends a debug representation of this node to the given string buffer.
The
ASTNodeimplementation of this method prints out the entire subtree. Subclasses may override to provide a more succinct representation.
appendPrintString
final void appendPrintString(java.lang.StringBuffer buffer)
- Appends a standard Java source code representation of this subtree to the given
string buffer.
stringSize
static int stringSize(java.lang.String string)
- Returns an estimate of the memory footprint, in bytes,
of the given string.
- Since:
- 3.0
subtreeBytes
public final int subtreeBytes()
- Returns an estimate of the memory footprint in bytes of the entire
subtree rooted at this node.
treeSize
abstract int treeSize()
- Returns an estimate of the memory footprint in bytes of the entire
subtree rooted at this node.
N.B. This method is package-private, so that the implementations of this method in each of the concrete AST node types do not clutter up the API doc.
memSize
abstract int memSize()
- Returns an estimate of the memory footprint of this node in bytes.
The estimate does not include the space occupied by child nodes.
|
|||||||||
| Home >> All >> org >> eclipse >> jdt >> core >> [ dom overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.eclipse.jdt.core.dom.ASTNode