|
|||||||||
| 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 AST

java.lang.Objectorg.eclipse.jdt.core.dom.AST
- public final class AST
- extends java.lang.Object
Umbrella owner and abstract syntax tree node factory.
An AST instance serves as the common owner of any number of
AST nodes, and as the factory for creating new AST nodes owned by that
instance.
Abstract syntax trees may be hand constructed by clients, using the
new factory methods to create new nodes, and the
various set methods
(see ASTNode and its subclasses)
to connect them together.
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 ensures that the added nodes have the correct owning AST.
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.
Compilation units created by ASTParser from a
source document can be serialized after arbitrary modifications
with minimal loss of original formatting. Here is an example:
Document doc = new Document("import java.util.List;\nclass X {}\n");
ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setSource(doc.get().toCharArray());
CompilationUnit cu = (CompilationUnit) parser.createAST(null);
cu.recordModifications();
AST ast = cu.getAST();
ImportDeclaration id = ast.newImportDeclaration();
id.setName(ast.newName(new String[] {"java", "util", "Set"});
cu.imports().add(id); // add import declaration at end
TextEdit edits = cu.rewrite(document, null);
UndoEdit undo = edits.apply(document);
See also org.eclipse.jdt.core.dom.rewrite.ASTRewrite for
an alternative way to describe and serialize changes to a
read-only AST.
Clients may create instances of this class, which is not intended to be subclassed.
- Since:
- 2.0
| Field Summary | |
(package private) int |
apiLevel
Level of AST API supported by this AST. |
private static java.lang.Class[] |
AST_CLASS
new Class[] {AST.class} |
private int |
defaultNodeFlag
Default value of flag |
private int |
disableEvents
When disableEvents > 0, events are not reported and the modification count stays fixed. |
private NodeEventHandler |
eventHandler
The event handler for this AST. |
private java.lang.Object |
internalASTLock
Internal object unique to the AST instance. |
static int |
JLS2
Constant for indicating the AST API that handles JLS2. |
static int |
JLS3
Constant for indicating the AST API that handles JLS3. |
private long |
modificationCount
Internal modification count; initially 0; increases monotonically by one or more as the AST is successively modified. |
private long |
originalModificationCount
Internal original modification count; value is equals to
modificationCount at the end of the parse (ASTParser
). |
private BindingResolver |
resolver
The binding resolver for this AST. |
(package private) InternalASTRewrite |
rewriter
Internal ast rewriter used to record ast modification when record mode is enabled. |
(package private) org.eclipse.jdt.internal.compiler.parser.Scanner |
scanner
Java Scanner used to validate preconditions for the creation of specific nodes like CharacterLiteral, NumberLiteral, StringLiteral or SimpleName. |
private java.lang.Object[] |
THIS_AST
new Object[] {this} |
| Constructor Summary | |
|
AST()
Creates a new, empty abstract syntax tree using default options. |
private |
AST(int level)
Creates a new Java abstract syntax tree (AST) following the specified set of API rules. |
|
AST(java.util.Map options)
Creates a new, empty abstract syntax tree using the given options. |
| Method Summary | |
int |
apiLevel()
Return the API level supported by this AST. |
static CompilationUnit |
convertCompilationUnit(int level,
org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration compilationUnitDeclaration,
char[] source,
java.util.Map options,
boolean isResolved,
org.eclipse.core.runtime.IProgressMonitor monitor)
Internal method. |
ASTNode |
createInstance(java.lang.Class nodeClass)
Creates an unparented node of the given node class (non-abstract subclass of ASTNode). |
ASTNode |
createInstance(int nodeType)
Creates an unparented node of the given node type. |
(package private) void |
disableEvents()
Disable events. |
(package private) BindingResolver |
getBindingResolver()
Returns the binding resolver for this AST. |
(package private) int |
getDefaultNodeFlag()
Returns default node flags of new nodes of this AST. |
(package private) NodeEventHandler |
getEventHandler()
Returns the event handler for this AST. |
long |
modificationCount()
Returns the modification count for this AST. |
(package private) void |
modifying()
Indicates that this AST is about to be modified. |
AnnotationTypeDeclaration |
newAnnotationTypeDeclaration()
Creates and returns a new unparented annotation type declaration node for an unspecified, but legal, name; no modifiers; no javadoc; and an empty list of member declarations. |
AnnotationTypeMemberDeclaration |
newAnnotationTypeMemberDeclaration()
Creates and returns a new unparented annotation type member declaration node for an unspecified, but legal, member name and type; no modifiers; no javadoc; and no default value. |
AnonymousClassDeclaration |
newAnonymousClassDeclaration()
Creates and returns a new unparented anonymous class declaration node owned by this AST. |
ArrayAccess |
newArrayAccess()
Creates and returns a new unparented array access expression node owned by this AST. |
ArrayCreation |
newArrayCreation()
Creates and returns a new unparented array creation expression node owned by this AST. |
ArrayInitializer |
newArrayInitializer()
Creates and returns a new unparented array initializer node owned by this AST. |
ArrayType |
newArrayType(Type componentType)
Creates and returns a new unparented array type node with the given component type, which may be another array type. |
ArrayType |
newArrayType(Type elementType,
int dimensions)
Creates and returns a new unparented array type node with the given element type and number of dimensions. |
AssertStatement |
newAssertStatement()
Creates a new unparented assert statement node owned by this AST. |
Assignment |
newAssignment()
Creates and returns a new unparented assignment expression node owned by this AST. |
static AST |
newAST(int level)
Creates a new Java abstract syntax tree (AST) following the specified set of API rules. |
Block |
newBlock()
Creates an unparented block node owned by this AST, for an empty list of statements. |
BlockComment |
newBlockComment()
Creates and returns a new block comment placeholder node. |
BooleanLiteral |
newBooleanLiteral(boolean value)
Creates and returns a new unparented boolean literal node. |
BreakStatement |
newBreakStatement()
Creates an unparented break statement node owned by this AST. |
CastExpression |
newCastExpression()
Creates and returns a new unparented cast expression node owned by this AST. |
CatchClause |
newCatchClause()
Creates a new unparented catch clause node owned by this AST. |
CharacterLiteral |
newCharacterLiteral()
Creates and returns a new unparented character literal node. |
ClassInstanceCreation |
newClassInstanceCreation()
Creates and returns a new unparented class instance creation ("new") expression node owned by this AST. |
CompilationUnit |
newCompilationUnit()
Creates an unparented compilation unit node owned by this AST. |
ConditionalExpression |
newConditionalExpression()
Creates and returns a new unparented conditional expression node owned by this AST. |
ConstructorInvocation |
newConstructorInvocation()
Creates an unparented alternate constructor ("this(...);") invocation statement node owned by this AST. |
ContinueStatement |
newContinueStatement()
Creates an unparented continue statement node owned by this AST. |
DoStatement |
newDoStatement()
Creates a new unparented do statement node owned by this AST. |
EmptyStatement |
newEmptyStatement()
Creates a new unparented empty statement node owned by this AST. |
EnhancedForStatement |
newEnhancedForStatement()
Creates a new unparented enhanced for statement node owned by this AST. |
EnumConstantDeclaration |
newEnumConstantDeclaration()
Creates an unparented enum constant declaration node owned by this AST. |
EnumDeclaration |
newEnumDeclaration()
Creates an unparented enum declaration node owned by this AST. |
ExpressionStatement |
newExpressionStatement(Expression expression)
Creates a new unparented expression statement node owned by this AST, for the given expression. |
FieldAccess |
newFieldAccess()
Creates and returns a new unparented field access expression node owned by this AST. |
FieldDeclaration |
newFieldDeclaration(VariableDeclarationFragment fragment)
Creates a new unparented field declaration node owned by this AST, for the given variable declaration fragment. |
ForStatement |
newForStatement()
Creates a new unparented for statement node owned by this AST. |
IfStatement |
newIfStatement()
Creates a new unparented if statement node owned by this AST. |
ImportDeclaration |
newImportDeclaration()
Creates an unparented import declaration node owned by this AST. |
InfixExpression |
newInfixExpression()
Creates and returns a new unparented infix expression node owned by this AST. |
Initializer |
newInitializer()
Creates an unparented initializer node owned by this AST, with an empty block. |
InstanceofExpression |
newInstanceofExpression()
Creates and returns a new unparented instanceof expression node owned by this AST. |
Javadoc |
newJavadoc()
Creates and returns a new doc comment node. |
LabeledStatement |
newLabeledStatement()
Creates a new unparented labeled statement node owned by this AST. |
LineComment |
newLineComment()
Creates and returns a new line comment placeholder node. |
MarkerAnnotation |
newMarkerAnnotation()
Creates and returns a new unparented marker annotation node with an unspecified type name. |
MemberRef |
newMemberRef()
Creates and returns a new member reference node. |
MemberValuePair |
newMemberValuePair()
Creates and returns a new unparented member value pair node with an unspecified member name and value. |
MethodDeclaration |
newMethodDeclaration()
Creates an unparented method declaration node owned by this AST. |
MethodInvocation |
newMethodInvocation()
Creates an unparented method invocation expression node owned by this AST. |
MethodRef |
newMethodRef()
Creates and returns a new method reference node. |
MethodRefParameter |
newMethodRefParameter()
Creates and returns a new method reference node. |
Modifier |
newModifier(Modifier.ModifierKeyword keyword)
Creates and returns a new unparented modifier node for the given modifier. |
Name |
newName(java.lang.String[] identifiers)
Creates and returns a new unparented name node for the given name segments. |
NormalAnnotation |
newNormalAnnotation()
Creates and returns a new unparented normal annotation node with an unspecified type name and an empty list of member value pairs. |
NullLiteral |
newNullLiteral()
Creates and returns a new unparented null literal node. |
NumberLiteral |
newNumberLiteral()
Creates and returns a new unparented number literal node. |
NumberLiteral |
newNumberLiteral(java.lang.String literal)
Creates and returns a new unparented number literal node. |
PackageDeclaration |
newPackageDeclaration()
Creates an unparented package declaration node owned by this AST. |
ParameterizedType |
newParameterizedType(Type type)
Creates and returns a new unparented parameterized type node with the given type and an empty list of type arguments. |
ParenthesizedExpression |
newParenthesizedExpression()
Creates and returns a new unparented parenthesized expression node owned by this AST. |
PostfixExpression |
newPostfixExpression()
Creates and returns a new unparented postfix expression node owned by this AST. |
PrefixExpression |
newPrefixExpression()
Creates and returns a new unparented prefix expression node owned by this AST. |
PrimitiveType |
newPrimitiveType(PrimitiveType.Code typeCode)
Creates and returns a new unparented primitive type node with the given type code. |
QualifiedName |
newQualifiedName(Name qualifier,
SimpleName name)
Creates and returns a new unparented qualified name node for the given qualifier and simple name child node. |
QualifiedType |
newQualifiedType(Type qualifier,
SimpleName name)
Creates and returns a new unparented qualified type node with the given qualifier type and name. |
ReturnStatement |
newReturnStatement()
Creates a new unparented return statement node owned by this AST. |
SimpleName |
newSimpleName(java.lang.String identifier)
Creates and returns a new unparented simple name node for the given identifier. |
SimpleType |
newSimpleType(Name typeName)
Creates and returns a new unparented simple type node with the given type name. |
SingleMemberAnnotation |
newSingleMemberAnnotation()
Creates and returns a new unparented single member annotation node with an unspecified type name and value. |
SingleVariableDeclaration |
newSingleVariableDeclaration()
Creates an unparented single variable declaration node owned by this AST. |
StringLiteral |
newStringLiteral()
Creates and returns a new unparented string literal node for the empty string literal. |
SuperConstructorInvocation |
newSuperConstructorInvocation()
Creates an unparented alternate super constructor ("super(...);") invocation statement node owned by this AST. |
SuperFieldAccess |
newSuperFieldAccess()
Creates and returns a new unparented super field access expression node owned by this AST. |
SuperMethodInvocation |
newSuperMethodInvocation()
Creates an unparented "super" method invocation expression node owned by this AST. |
SwitchCase |
newSwitchCase()
Creates a new unparented switch case statement node owned by this AST. |
SwitchStatement |
newSwitchStatement()
Creates a new unparented switch statement node owned by this AST. |
SynchronizedStatement |
newSynchronizedStatement()
Creates a new unparented synchronized statement node owned by this AST. |
TagElement |
newTagElement()
Creates and returns a new tag element node. |
TextElement |
newTextElement()
Creates and returns a new text element node. |
ThisExpression |
newThisExpression()
Creates and returns a new unparented "this" expression node owned by this AST. |
ThrowStatement |
newThrowStatement()
Creates a new unparented throw statement node owned by this AST. |
TryStatement |
newTryStatement()
Creates a new unparented try statement node owned by this AST. |
TypeDeclaration |
newTypeDeclaration()
Creates an unparented class declaration node owned by this AST. |
TypeDeclarationStatement |
newTypeDeclarationStatement(AbstractTypeDeclaration decl)
Creates a new unparented local type declaration statement node owned by this AST, for the given type declaration. |
TypeDeclarationStatement |
newTypeDeclarationStatement(TypeDeclaration decl)
Creates a new unparented local type declaration statement node owned by this AST, for the given type declaration. |
TypeLiteral |
newTypeLiteral()
Creates and returns a new unparented type literal expression node owned by this AST. |
TypeParameter |
newTypeParameter()
Creates and returns a new unparented type parameter type node with an unspecified type variable name and an empty list of type bounds. |
VariableDeclarationExpression |
newVariableDeclarationExpression(VariableDeclarationFragment fragment)
Creates a new unparented local variable declaration expression node owned by this AST, for the given variable declaration fragment. |
VariableDeclarationFragment |
newVariableDeclarationFragment()
Creates an unparented variable declaration fragment node owned by this AST. |
VariableDeclarationStatement |
newVariableDeclarationStatement(VariableDeclarationFragment fragment)
Creates a new unparented local variable declaration statement node owned by this AST, for the given variable declaration fragment. |
WhileStatement |
newWhileStatement()
Creates a new unparented while statement node owned by this AST. |
WildcardType |
newWildcardType()
Creates and returns a new unparented wildcard type node with no type bound. |
static CompilationUnit |
parseCompilationUnit(char[] source)
Deprecated. Use ASTParser instead. |
static CompilationUnit |
parseCompilationUnit(char[] source,
java.lang.String unitName,
org.eclipse.jdt.core.IJavaProject project)
Deprecated. Use ASTParser instead. |
static CompilationUnit |
parseCompilationUnit(org.eclipse.jdt.core.IClassFile classFile,
boolean resolveBindings)
Deprecated. Use ASTParser instead. |
static CompilationUnit |
parseCompilationUnit(org.eclipse.jdt.core.ICompilationUnit unit,
boolean resolveBindings)
Deprecated. Use ASTParser instead. |
(package private) void |
postAddChildEvent(ASTNode node,
ASTNode child,
StructuralPropertyDescriptor property)
Reports that the given node has just gained a child. |
(package private) void |
postCloneNodeEvent(ASTNode node,
ASTNode clone)
Reports that the given node has just been cloned. |
(package private) void |
postRemoveChildEvent(ASTNode node,
ASTNode child,
StructuralPropertyDescriptor property)
Reports that the given node jsut lost a child. |
(package private) void |
postReplaceChildEvent(ASTNode node,
ASTNode child,
ASTNode newChild,
StructuralPropertyDescriptor property)
Reports that the given node has just had a child replaced. |
(package private) void |
postValueChangeEvent(ASTNode node,
SimplePropertyDescriptor property)
Reports that the given node has just changed the value of a non-child property. |
(package private) void |
preAddChildEvent(ASTNode node,
ASTNode child,
StructuralPropertyDescriptor property)
Reports that the given node is about to gain a child. |
(package private) void |
preCloneNodeEvent(ASTNode node)
Reports that the given node is about to be cloned. |
(package private) void |
preRemoveChildEvent(ASTNode node,
ASTNode child,
StructuralPropertyDescriptor property)
Reports that the given node is about to lose a child. |
(package private) void |
preReplaceChildEvent(ASTNode node,
ASTNode child,
ASTNode newChild,
StructuralPropertyDescriptor property)
Reports that the given node is about have a child replaced. |
(package private) void |
preValueChangeEvent(ASTNode node,
SimplePropertyDescriptor property)
Reports that the given node is about to change the value of a non-child property. |
(package private) void |
recordModifications(CompilationUnit root)
Enables the recording of changes to the given compilation unit and its descendents. |
(package private) void |
reenableEvents()
Reenable events. |
ITypeBinding |
resolveWellKnownType(java.lang.String name)
Returns the type binding for a "well known" type. |
(package private) org.eclipse.text.edits.TextEdit |
rewrite(org.eclipse.jface.text.IDocument document,
java.util.Map options)
Converts all modifications recorded into an object representing the corresponding text edits to the given document containing the original source code for the compilation unit that gave rise to this AST. |
(package private) void |
setBindingResolver(BindingResolver resolver)
Sets the binding resolver for this AST. |
(package private) void |
setDefaultNodeFlag(int flag)
Sets default node flags of new nodes of this AST. |
(package private) void |
setEventHandler(NodeEventHandler eventHandler)
Sets the event handler for this AST. |
(package private) void |
setOriginalModificationCount(long count)
Set originalModificationCount to the current modification count |
(package private) void |
supportedOnlyIn2()
Checks that this AST operation is only used when building level JLS2 ASTs. |
(package private) void |
unsupportedIn2()
Checks that this AST operation is not used when building level JLS2 ASTs. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
JLS2
public static final int JLS2
- Constant for indicating the AST API that handles JLS2.
This API is capable of handling all constructs
in the Java language as described in the Java Language
Specification, Second Edition (JLS2).
JLS2 is a superset of all earlier versions of the
Java language, and the JLS2 API can be used to manipulate
programs written in all versions of the Java language
up to and including J2SE 1.4.
- Since:
- 3.0
- See Also:
- Constant Field Values
JLS3
public static final int JLS3
- Constant for indicating the AST API that handles JLS3.
This API is capable of handling all constructs in the
Java language as described in the Java Language
Specification, Third Edition (JLS3).
JLS3 is a superset of all earlier versions of the
Java language, and the JLS3 API can be used to manipulate
programs written in all versions of the Java language
up to and including J2SE 1.5.
NOTE:In Eclipse 3.0, there is no underlying parser support for JLS3 ASTs. This support is planned for the follow-on release of Eclipse which includes support for J2SE 1.5. Without a parser to create JLS3 ASTs, they are not much use. Use JLS2 ASTs instead.
- Since:
- 3.0
- See Also:
- Constant Field Values
resolver
private BindingResolver resolver
- The binding resolver for this AST. Initially a binding resolver that
does not resolve names at all.
eventHandler
private NodeEventHandler eventHandler
- The event handler for this AST.
Initially an event handler that does not nothing.
- Since:
- 3.0
apiLevel
int apiLevel
- Level of AST API supported by this AST.
- Since:
- 3.0
modificationCount
private long modificationCount
- Internal modification count; initially 0; increases monotonically
by one or more as the AST is successively modified.
originalModificationCount
private long originalModificationCount
- Internal original modification count; value is equals to
modificationCountat the end of the parse (ASTParser). If this ast is not created with a parser then value is 0.- Since:
- 3.0
disableEvents
private int disableEvents
- When disableEvents > 0, events are not reported and
the modification count stays fixed.
This mechanism is used in lazy initialization of a node to prevent events from being reported for the modification of the node as well as for the creation of the missing child.
- Since:
- 3.0
internalASTLock
private final java.lang.Object internalASTLock
- Internal object unique to the AST instance. Readers must synchronize on
this object when the modifying instance fields.
- Since:
- 3.0
scanner
org.eclipse.jdt.internal.compiler.parser.Scanner scanner
- Java Scanner used to validate preconditions for the creation of specific nodes
like CharacterLiteral, NumberLiteral, StringLiteral or SimpleName.
rewriter
InternalASTRewrite rewriter
- Internal ast rewriter used to record ast modification when record mode is enabled.
defaultNodeFlag
private int defaultNodeFlag
- Default value of
flagwhen a new node is created.
AST_CLASS
private static final java.lang.Class[] AST_CLASS
- new Class[] {AST.class}
- Since:
- 3.0
THIS_AST
private final java.lang.Object[] THIS_AST
- new Object[] {this}
- Since:
- 3.0
| Constructor Detail |
AST
private AST(int level)
- Creates a new Java abstract syntax tree
(AST) following the specified set of API rules.
- Since:
- 3.0
AST
public AST()
- Creates a new, empty abstract syntax tree using default options.
AST
public AST(java.util.Map options)
- Creates a new, empty abstract syntax tree using the given options.
Following option keys are significant:
"org.eclipse.jdt.core.compiler.source"- indicates source compatibility mode (as perJavaCore);"1.3"means the source code is as per JDK 1.3;"1.4"means the source code is as per JDK 1.4 ("assert"is now a keyword);"1.5"means the source code is as per JDK 1.5 ("enum"is now a keyword); additional legal values may be added later.
| Method Detail |
convertCompilationUnit
public static CompilationUnit convertCompilationUnit(int level, org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration compilationUnitDeclaration, char[] source, java.util.Map options, boolean isResolved, org.eclipse.core.runtime.IProgressMonitor monitor)
- Internal method.
This method converts the given internal compiler AST for the given source string into a compilation unit. This method is not intended to be called by clients.
newAST
public static AST newAST(int level)
- Creates a new Java abstract syntax tree
(AST) following the specified set of API rules.
Clients should use this method. It is provided only so that test suites can create AST instances that employ the JLS2 APIs.
- Since:
- 3.0
modificationCount
public long modificationCount()
- Returns the modification count for this AST. The modification count
is a non-negative value that increases (by 1 or perhaps by more) as
this AST or its nodes are changed. The initial value is unspecified.
The following things count as modifying an AST:
- creating a new node owned by this AST,
- adding a child to a node owned by this AST,
- removing a child from a node owned by this AST,
- setting a non-node attribute of a node owned by this AST.
N.B. This method may be called several times in the course of a single client operation. The only promise is that the modification count increases monotonically as the AST or its nodes change; there is no promise that a modifying operation increases the count by exactly 1.
apiLevel
public int apiLevel()
- Return the API level supported by this AST.
- Since:
- 3.0
modifying
void modifying()
- Indicates that this AST is about to be modified.
The following things count as modifying an AST:
- creating a new node owned by this AST
- adding a child to a node owned by this AST
- removing a child from a node owned by this AST
- setting a non-node attribute of a node owned by this AST .
N.B. This method may be called several times in the course of a single client operation.
disableEvents
final void disableEvents()
- Disable events.
This method is thread-safe for AST readers.
- Since:
- 3.0
reenableEvents
final void reenableEvents()
- Reenable events.
This method is thread-safe for AST readers.
- Since:
- 3.0
preRemoveChildEvent
void preRemoveChildEvent(ASTNode node, ASTNode child, StructuralPropertyDescriptor property)
- Reports that the given node is about to lose a child.
- Since:
- 3.0
postRemoveChildEvent
void postRemoveChildEvent(ASTNode node, ASTNode child, StructuralPropertyDescriptor property)
- Reports that the given node jsut lost a child.
- Since:
- 3.0
preReplaceChildEvent
void preReplaceChildEvent(ASTNode node, ASTNode child, ASTNode newChild, StructuralPropertyDescriptor property)
- Reports that the given node is about have a child replaced.
- Since:
- 3.0
postReplaceChildEvent
void postReplaceChildEvent(ASTNode node, ASTNode child, ASTNode newChild, StructuralPropertyDescriptor property)
- Reports that the given node has just had a child replaced.
- Since:
- 3.0
preAddChildEvent
void preAddChildEvent(ASTNode node, ASTNode child, StructuralPropertyDescriptor property)
- Reports that the given node is about to gain a child.
- Since:
- 3.0
postAddChildEvent
void postAddChildEvent(ASTNode node, ASTNode child, StructuralPropertyDescriptor property)
- Reports that the given node has just gained a child.
- Since:
- 3.0
preValueChangeEvent
void preValueChangeEvent(ASTNode node, SimplePropertyDescriptor property)
- Reports that the given node is about to change the value of a
non-child property.
- Since:
- 3.0
postValueChangeEvent
void postValueChangeEvent(ASTNode node, SimplePropertyDescriptor property)
- Reports that the given node has just changed the value of a
non-child property.
- Since:
- 3.0
preCloneNodeEvent
void preCloneNodeEvent(ASTNode node)
- Reports that the given node is about to be cloned.
- Since:
- 3.0
postCloneNodeEvent
void postCloneNodeEvent(ASTNode node, ASTNode clone)
- Reports that the given node has just been cloned.
- Since:
- 3.0
parseCompilationUnit
public static CompilationUnit parseCompilationUnit(org.eclipse.jdt.core.ICompilationUnit unit, boolean resolveBindings)
- Deprecated. Use ASTParser instead.
- Parses the source string of the given Java model compilation unit element and creates and returns a corresponding abstract syntax tree. The source string is obtained from the Java model element using
ICompilationUnit.getSource().The returned compilation unit node is the root node of a new AST. Each node in the subtree carries source range(s) information relating back to positions in the source string (the source string is not remembered with the AST). The source range usually begins at the first character of the first token corresponding to the node; leading whitespace and comments are not included. The source range usually extends through the last character of the last token corresponding to the node; trailing whitespace and comments are not included. There are a handful of exceptions (including compilation units and the various body declarations); the specification for these node type spells out the details. Source ranges nest properly: the source range for a child is always within the source range of its parent, and the source ranges of sibling nodes never overlap. If a syntax error is detected while parsing, the relevant node(s) of the tree will be flagged as
MALFORMED.If
resolveBindingsistrue, the various names and types appearing in the compilation unit can be resolved to "bindings" by calling theresolveBindingmethods. These bindings draw connections between the different parts of a program, and generally afford a more powerful vantage point for clients who wish to analyze a program's structure more deeply. These bindings come at a considerable cost in both time and space, however, and should not be requested frivolously. The additional space is not reclaimed until the AST, all its nodes, and all its bindings become garbage. So it is very important to not retain any of these objects longer than absolutely necessary. Bindings are resolved at the time the AST is created. Subsequent modifications to the AST do not affect the bindings returned byresolveBindingmethods in any way; these methods return the same binding as before the AST was modified (including modifications that rearrange subtrees by reparenting nodes). IfresolveBindingsisfalse, the analysis does not go beyond parsing and building the tree, and allresolveBindingmethods returnnullfrom the outset.- Since:
- 2.0
- Parses the source string of the given Java model compilation unit element and creates and returns a corresponding abstract syntax tree. The source string is obtained from the Java model element using
parseCompilationUnit
public static CompilationUnit parseCompilationUnit(org.eclipse.jdt.core.IClassFile classFile, boolean resolveBindings)
- Deprecated. Use ASTParser instead.
- Parses the source string corresponding to the given Java class file element and creates and returns a corresponding abstract syntax tree. The source string is obtained from the Java model element using
IClassFile.getSource(), and is only available for a class files with attached source.The returned compilation unit node is the root node of a new AST. Each node in the subtree carries source range(s) information relating back to positions in the source string (the source string is not remembered with the AST). The source range usually begins at the first character of the first token corresponding to the node; leading whitespace and comments are not included. The source range usually extends through the last character of the last token corresponding to the node; trailing whitespace and comments are not included. There are a handful of exceptions (including compilation units and the various body declarations); the specification for these node type spells out the details. Source ranges nest properly: the source range for a child is always within the source range of its parent, and the source ranges of sibling nodes never overlap. If a syntax error is detected while parsing, the relevant node(s) of the tree will be flagged as
MALFORMED.If
resolveBindingsistrue, the various names and types appearing in the compilation unit can be resolved to "bindings" by calling theresolveBindingmethods. These bindings draw connections between the different parts of a program, and generally afford a more powerful vantage point for clients who wish to analyze a program's structure more deeply. These bindings come at a considerable cost in both time and space, however, and should not be requested frivolously. The additional space is not reclaimed until the AST, all its nodes, and all its bindings become garbage. So it is very important to not retain any of these objects longer than absolutely necessary. Bindings are resolved at the time the AST is created. Subsequent modifications to the AST do not affect the bindings returned byresolveBindingmethods in any way; these methods return the same binding as before the AST was modified (including modifications that rearrange subtrees by reparenting nodes). IfresolveBindingsisfalse, the analysis does not go beyond parsing and building the tree, and allresolveBindingmethods returnnullfrom the outset.- Since:
- 2.1
- Parses the source string corresponding to the given Java class file element and creates and returns a corresponding abstract syntax tree. The source string is obtained from the Java model element using
parseCompilationUnit
public static CompilationUnit parseCompilationUnit(char[] source, java.lang.String unitName, org.eclipse.jdt.core.IJavaProject project)
- Deprecated. Use ASTParser instead.
- Parses the given string as the hypothetical contents of the named compilation unit and creates and returns a corresponding abstract syntax tree.
The returned compilation unit node is the root node of a new AST. Each node in the subtree carries source range(s) information relating back to positions in the given source string (the given source string itself is not remembered with the AST). The source range usually begins at the first character of the first token corresponding to the node; leading whitespace and comments are not included. The source range usually extends through the last character of the last token corresponding to the node; trailing whitespace and comments are not included. There are a handful of exceptions (including compilation units and the various body declarations); the specification for these node type spells out the details. Source ranges nest properly: the source range for a child is always within the source range of its parent, and the source ranges of sibling nodes never overlap. If a syntax error is detected while parsing, the relevant node(s) of the tree will be flagged as
MALFORMED.If the given project is not
null, the various names and types appearing in the compilation unit can be resolved to "bindings" by calling theresolveBindingmethods. These bindings draw connections between the different parts of a program, and generally afford a more powerful vantage point for clients who wish to analyze a program's structure more deeply. These bindings come at a considerable cost in both time and space, however, and should not be requested frivolously. The additional space is not reclaimed until the AST, all its nodes, and all its bindings become garbage. So it is very important to not retain any of these objects longer than absolutely necessary. Bindings are resolved at the time the AST is created. Subsequent modifications to the AST do not affect the bindings returned byresolveBindingmethods in any way; these methods return the same binding as before the AST was modified (including modifications that rearrange subtrees by reparenting nodes). If the given project isnull, the analysis does not go beyond parsing and building the tree, and allresolveBindingmethods returnnullfrom the outset.The name of the compilation unit must be supplied for resolving bindings. This name should include the ".java" suffix and match the name of the main (public) class or interface declared in the source. For example, if the source declares a public class named "Foo", the name of the compilation should be "Foo.java". For the purposes of resolving bindings, types declared in the source string hide types by the same name available through the classpath of the given project.
- Since:
- 2.0
- Parses the given string as the hypothetical contents of the named compilation unit and creates and returns a corresponding abstract syntax tree.
parseCompilationUnit
public static CompilationUnit parseCompilationUnit(char[] source)
- Deprecated. Use ASTParser instead.
- Parses the given string as a Java compilation unit and creates and returns a corresponding abstract syntax tree.
The returned compilation unit node is the root node of a new AST. Each node in the subtree carries source range(s) information relating back to positions in the given source string (the given source string itself is not remembered with the AST). The source range usually begins at the first character of the first token corresponding to the node; leading whitespace and comments are not included. The source range usually extends through the last character of the last token corresponding to the node; trailing whitespace and comments are not included. There are a handful of exceptions (including compilation units and the various body declarations); the specification for these node type spells out the details. Source ranges nest properly: the source range for a child is always within the source range of its parent, and the source ranges of sibling nodes never overlap. If a syntax error is detected while parsing, the relevant node(s) of the tree will be flagged as
MALFORMED.This method does not compute binding information; all
resolveBindingmethods applied to nodes of the resulting AST returnnull.- Since:
- 2.0
- Parses the given string as a Java compilation unit and creates and returns a corresponding abstract syntax tree.
getBindingResolver
BindingResolver getBindingResolver()
- Returns the binding resolver for this AST.
getEventHandler
NodeEventHandler getEventHandler()
- Returns the event handler for this AST.
- Since:
- 3.0
setEventHandler
void setEventHandler(NodeEventHandler eventHandler)
- Sets the event handler for this AST.
- Since:
- 3.0
getDefaultNodeFlag
int getDefaultNodeFlag()
- Returns default node flags of new nodes of this AST.
- Since:
- 3.0
setDefaultNodeFlag
void setDefaultNodeFlag(int flag)
- Sets default node flags of new nodes of this AST.
- Since:
- 3.0
setOriginalModificationCount
void setOriginalModificationCount(long count)
- Set
originalModificationCountto the current modification count- Since:
- 3.0
resolveWellKnownType
public ITypeBinding resolveWellKnownType(java.lang.String name)
- Returns the type binding for a "well known" type.
Note that bindings are generally unavailable unless requested when the AST is being built.
The following type names are supported:
"boolean""char""byte""short""int""long""float""double""void""java.lang.Class""java.lang.Cloneable""java.lang.Error""java.lang.Exception""java.lang.Object""java.lang.RuntimeException""java.lang.String""java.lang.StringBuffer""java.lang.Throwable""java.io.Serializable"
setBindingResolver
void setBindingResolver(BindingResolver resolver)
- Sets the binding resolver for this AST.
unsupportedIn2
void unsupportedIn2()
- Checks that this AST operation is not used when
building level JLS2 ASTs.
- Since:
- 3.0
supportedOnlyIn2
void supportedOnlyIn2()
- Checks that this AST operation is only used when
building level JLS2 ASTs.
- Since:
- 3.0
createInstance
public ASTNode createInstance(java.lang.Class nodeClass)
- Creates an unparented node of the given node class
(non-abstract subclass of ASTNode).
- Since:
- 3.0
createInstance
public ASTNode createInstance(int nodeType)
- Creates an unparented node of the given node type.
This convenience method is equivalent to:
createInstance(ASTNode.nodeClassForType(nodeType))
- Since:
- 3.0
newSimpleName
public SimpleName newSimpleName(java.lang.String identifier)
- Creates and returns a new unparented simple name node for the given
identifier. The identifier should be a legal Java identifier, but not
a keyword, boolean literal ("true", "false") or null literal ("null").
newQualifiedName
public QualifiedName newQualifiedName(Name qualifier, SimpleName name)
- Creates and returns a new unparented qualified name node for the given
qualifier and simple name child node.
newName
public Name newName(java.lang.String[] identifiers)
- Creates and returns a new unparented name node for the given name
segments. Returns a simple name if there is only one name segment, and
a qualified name if there are multiple name segments. Each of the name
segments should be legal Java identifiers (this constraint may or may
not be enforced), and there must be at least one name segment.
newSimpleType
public SimpleType newSimpleType(Name typeName)
- Creates and returns a new unparented simple type node with the given
type name.
This method can be used to convert a name (
Name) into a type (Type) by wrapping it.
JAVADOC
org.eclipse.jdt.core.dom.AST