Class ASTParser

java.lang.Object
org.aspectj.org.eclipse.jdt.core.dom.ASTParser

public class ASTParser extends Object
A Java language parser for creating abstract syntax trees (ASTs).

Example: Create basic AST from source string

 char[] source = ...;
 ASTParser parser = ASTParser.newParser(AST.JLS3);  // handles JDK 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6
 parser.setSource(source);
 // In order to parse 1.5 code, some compiler options need to be set to 1.5
 Map options = JavaCore.getOptions();
 JavaCore.setComplianceOptions(JavaCore.VERSION_1_5, options);
 parser.setCompilerOptions(options);
 CompilationUnit result = (CompilationUnit) parser.createAST(null);
 

Once a configured parser instance has been used to create an AST, the settings are automatically reset to their defaults, ready for the parser instance to be reused.

There are a number of configurable features:

Since:
3.0