public class ASTManager extends Object
Facade class to parse Java source files.
| Modifier and Type | Field and Description |
|---|---|
static PrimitiveType |
BOOLEAN_TYPE |
static PrimitiveType |
BYTE_TYPE |
static PrimitiveType |
CHAR_TYPE |
static PrimitiveType |
DOUBLE_TYPE |
static PrimitiveType |
FLOAT_TYPE |
static PrimitiveType |
INT_TYPE |
static PrimitiveType |
LONG_TYPE |
static PrimitiveType |
SHORT_TYPE |
static ThisExpr |
THIS |
static VoidType |
VOID_TYPE |
| Constructor and Description |
|---|
ASTManager() |
| Modifier and Type | Method and Description |
|---|---|
static Node |
parse(Class<?> clazz,
String text)
Parses any fragment of code and store the result into the subclass of
Node defined. |
static Node |
parse(Class<?> clazz,
String text,
boolean withoutLocation)
Parses any fragment of code and store the result into the subclass of
Node defined. |
static CompilationUnit |
parse(File file)
Parses a Java source file and store the AST into a
CompilationUnit object. |
static CompilationUnit |
parse(File file,
String encoding)
Parses a Java source file with a given encoding and store the AST into a
CompilationUnit object. |
static CompilationUnit |
parse(Reader reader)
Parses Java code and store the AST into a
CompilationUnit object. |
static CompilationUnit |
parse(String code)
Parses Java code and store the AST into a
CompilationUnit object. |
static CompilationUnit |
parse(String code,
boolean withoutLocation)
Parses Java code and store the AST into a
CompilationUnit object with or without
the nodes start & end locations (line numbers and columns). |
public static final PrimitiveType BYTE_TYPE
public static final PrimitiveType SHORT_TYPE
public static final PrimitiveType INT_TYPE
public static final PrimitiveType LONG_TYPE
public static final PrimitiveType FLOAT_TYPE
public static final PrimitiveType DOUBLE_TYPE
public static final PrimitiveType BOOLEAN_TYPE
public static final PrimitiveType CHAR_TYPE
public static final VoidType VOID_TYPE
public static final ThisExpr THIS
public static CompilationUnit parse(File file) throws ParseException, IOException
CompilationUnit object. The default
encoding is UTF-8.file - source code to parseParseException - when the code contains an invalid syntaxIOException - file can not be read.public static CompilationUnit parse(File file, String encoding) throws ParseException, IOException
CompilationUnit object.file - source code to parseencoding - ParseException - when the code contains an invalid syntaxIOException - file can not be read.public static CompilationUnit parse(Reader reader) throws ParseException, IOException
CompilationUnit object.reader - to read the source code to parseParseException - when the code contains an invalid syntaxIOException - the code can not be read.public static CompilationUnit parse(String code) throws ParseException
CompilationUnit object. All nodes has
their start and end location (line and column)code - source code to parse.ParseException - when the code contains an invalid syntax.public static CompilationUnit parse(String code, boolean withoutLocation) throws ParseException
CompilationUnit object with or without
the nodes start & end locations (line numbers and columns).code - source code to parse.withoutLocation - true does not fulfill the location information inside the AST.
Otherwise, it is defined.ParseException - when the code contains an invalid syntax.public static Node parse(Class<?> clazz, String text) throws ParseException
Node defined. For example, if you need
to parse a single method, the class must be
MethodDeclaration. The result does
NOT contain the location of the AST nodes.clazz - the subclass of Node. The
result will be instance of that class.text - the fragment of code to parse.ParseException - when the code contains an invalid syntax.public static Node parse(Class<?> clazz, String text, boolean withoutLocation) throws ParseException
Node defined. For example, if you need
to parse a single method, the class must be
MethodDeclaration. The result can
contain or not the location of all AST nodes.clazz - the subclass of Node. The
result will be instance of that class.text - the fragment of code to parse.withoutLocation - true does not fulfill the location information inside the AST.
Otherwise, it is defined.ParseExceptionCopyright © 2015. All rights reserved.