public final class JavaParser extends Object
| Constructor and Description |
|---|
JavaParser()
Instantiate the parser.
|
| Modifier and Type | Method and Description |
|---|---|
static boolean |
getDoNotAssignCommentsPreceedingEmptyLines() |
static boolean |
getDoNotConsiderAnnotationsAsNodeStartForCodeAttribution() |
List<Token> |
getTokens()
Return the list of tokens that have been encountered while parsing code
using this parser.
|
CompilationUnit |
parse()
Parses the Java code and returns a
CompilationUnit that
represents it. |
static CompilationUnit |
parse(File file)
Parses the Java code contained in a
File and returns a
CompilationUnit that represents it.Note: Uses UTF-8 encoding |
static CompilationUnit |
parse(File file,
Charset encoding) |
static CompilationUnit |
parse(File file,
Charset encoding,
boolean considerComments)
Parses the Java code contained in a
File and returns a
CompilationUnit that represents it. |
static CompilationUnit |
parse(InputStream in)
Parses the Java code contained in the
InputStream and returns a
CompilationUnit that represents it.Note: Uses UTF-8 encoding |
static CompilationUnit |
parse(InputStream in,
Charset encoding) |
static CompilationUnit |
parse(InputStream in,
Charset encoding,
boolean considerComments)
Parses the Java code contained in the
InputStream and returns a
CompilationUnit that represents it. |
static CompilationUnit |
parse(Reader reader) |
static CompilationUnit |
parse(Reader reader,
boolean considerComments) |
static CompilationUnit |
parse(String code)
Parses the Java code contained in code and returns a
CompilationUnit that represents it. |
static CompilationUnit |
parse(String code,
boolean considerComments)
Parses the Java code contained in code and returns a
CompilationUnit that represents it. |
AnnotationExpr |
parseAnnotation()
Parses the Java annotation and returns a
AnnotationExpr that
represents it. |
static AnnotationExpr |
parseAnnotation(String annotation)
Parses the Java annotation contained in a
String and returns a
AnnotationExpr that represents it. |
BlockStmt |
parseBlock()
Parses the Java block and returns a
BlockStmt that represents it. |
static BlockStmt |
parseBlock(String blockStatement)
|
BodyDeclaration<?> |
parseBodyDeclaration()
Parses the Java body declaration(e.g fields or methods) and returns a
BodyDeclaration that represents it. |
static BodyDeclaration<?> |
parseBodyDeclaration(String body)
Parses the Java body declaration(e.g fields or methods) contained in a
String and returns a BodyDeclaration that represents it. |
BodyDeclaration<?> |
parseClassBodyDeclaration()
Parses a Java class body declaration(e.g fields or methods) and returns a
BodyDeclaration that represents it. |
static BodyDeclaration<?> |
parseClassBodyDeclaration(String body)
Parses a Java class body declaration(e.g fields or methods) and returns a
BodyDeclaration that represents it. |
Expression |
parseExpression()
Parses the Java expression and returns a
Expression that
represents it. |
static Expression |
parseExpression(String expression)
Parses the Java expression contained in a
String and returns a
Expression that represents it. |
ImportDeclaration |
parseImport()
Parses the Java import and returns a
ImportDeclaration that
represents it. |
static ImportDeclaration |
parseImport(String importDeclaration)
Parses the Java import contained in a
String and returns a
ImportDeclaration that represents it. |
BodyDeclaration<?> |
parseInterfaceBodyDeclaration()
Parses a Java interface body declaration(e.g fields or methods) and returns a
BodyDeclaration that represents it. |
static BodyDeclaration |
parseInterfaceBodyDeclaration(String body)
Parses a Java interface body declaration(e.g fields or methods) and returns a
BodyDeclaration that represents it. |
Statement |
parseStatement()
Parses the Java statement and returns a
Statement that represents
it. |
static Statement |
parseStatement(String statement)
|
List<Statement> |
parseStatements()
|
static List<Statement> |
parseStatements(String statements)
|
static void |
setDoNotAssignCommentsPreceedingEmptyLines(boolean newValue) |
static void |
setDoNotConsiderAnnotationsAsNodeStartForCodeAttribution(boolean newValue) |
JavaParser |
setSource(File file) |
JavaParser |
setSource(File file,
Charset encoding) |
JavaParser |
setSource(InputStream input) |
JavaParser |
setSource(InputStream input,
Charset encoding) |
JavaParser |
setSource(Provider provider) |
JavaParser |
setSource(Reader reader) |
JavaParser |
setSource(String source) |
public JavaParser()
public JavaParser setSource(Provider provider)
public JavaParser setSource(Reader reader)
public JavaParser setSource(InputStream input) throws IOException
IOExceptionpublic JavaParser setSource(InputStream input, Charset encoding) throws IOException
IOExceptionpublic JavaParser setSource(File file) throws IOException
IOExceptionpublic JavaParser setSource(File file, Charset encoding) throws IOException
IOExceptionpublic JavaParser setSource(String source)
public List<Token> getTokens()
public CompilationUnit parse() throws ParseException
CompilationUnit that
represents it.ParseException - if the source code has parser errorspublic BlockStmt parseBlock() throws ParseException
BlockStmt that represents it.ParseException - if the source code has parser errorspublic List<Statement> parseStatements() throws ParseException
ParseException - if the source code has parser errorspublic Statement parseStatement() throws ParseException
Statement that represents
it.ParseException - if the source code has parser errorspublic ImportDeclaration parseImport() throws ParseException
ImportDeclaration that
represents it.ParseException - if the source code has parser errorspublic Expression parseExpression() throws ParseException
Expression that
represents it.ParseException - if the source code has parser errorspublic AnnotationExpr parseAnnotation() throws ParseException
AnnotationExpr that
represents it.ParseException - if the source code has parser errorspublic BodyDeclaration<?> parseBodyDeclaration() throws ParseException
BodyDeclaration that represents it.ParseException - if the source code has parser errorspublic BodyDeclaration<?> parseClassBodyDeclaration() throws ParseException
BodyDeclaration that represents it.ParseException - if the source code has parser errorspublic BodyDeclaration<?> parseInterfaceBodyDeclaration() throws ParseException
BodyDeclaration that represents it.ParseException - if the source code has parser errorspublic static boolean getDoNotConsiderAnnotationsAsNodeStartForCodeAttribution()
public static void setDoNotConsiderAnnotationsAsNodeStartForCodeAttribution(boolean newValue)
public static boolean getDoNotAssignCommentsPreceedingEmptyLines()
public static void setDoNotAssignCommentsPreceedingEmptyLines(boolean newValue)
public static CompilationUnit parse(InputStream in, Charset encoding) throws ParseException
ParseExceptionpublic static CompilationUnit parse(InputStream in, Charset encoding, boolean considerComments) throws ParseException
InputStream and returns a
CompilationUnit that represents it.in - InputStream containing Java source codeencoding - encoding of the source codeParseException - if the source code has parser errorspublic static CompilationUnit parse(InputStream in) throws ParseException
InputStream and returns a
CompilationUnit that represents it.in - InputStream containing Java source codeParseException - if the source code has parser errorspublic static CompilationUnit parse(File file, Charset encoding) throws ParseException, IOException
ParseExceptionIOExceptionpublic static CompilationUnit parse(File file, Charset encoding, boolean considerComments) throws ParseException
File and returns a
CompilationUnit that represents it.file - File containing Java source codeencoding - encoding of the source codeParseException - if the source code has parser errorspublic static CompilationUnit parse(File file) throws ParseException, IOException
File and returns a
CompilationUnit that represents it.file - File containing Java source codeParseException - if the source code has parser errorsIOExceptionpublic static CompilationUnit parse(Reader reader) throws ParseException
ParseExceptionpublic static CompilationUnit parse(Reader reader, boolean considerComments) throws ParseException
ParseExceptionpublic static CompilationUnit parse(String code, boolean considerComments) throws ParseException
CompilationUnit that represents it.code - Java source codeconsiderComments - parse or ignore commentsParseException - if the source code has parser errorspublic static CompilationUnit parse(String code) throws ParseException
CompilationUnit that represents it.code - Java source codeParseException - if the source code has parser errorspublic static BlockStmt parseBlock(String blockStatement) throws ParseException
blockStatement - String containing Java block codeParseException - if the source code has parser errorspublic static Statement parseStatement(String statement) throws ParseException
statement - String containing Java statement codeParseException - if the source code has parser errorspublic static List<Statement> parseStatements(String statements) throws ParseException
String and returns a
list of Statement that represents it.statements - String containing Java statementsParseException - if the source code has parser errorspublic static ImportDeclaration parseImport(String importDeclaration) throws ParseException
String and returns a
ImportDeclaration that represents it.importDeclaration - String containing Java import codeParseException - if the source code has parser errorspublic static Expression parseExpression(String expression) throws ParseException
String and returns a
Expression that represents it.expression - String containing Java expressionParseException - if the source code has parser errorspublic static AnnotationExpr parseAnnotation(String annotation) throws ParseException
String and returns a
AnnotationExpr that represents it.annotation - String containing Java annotationParseException - if the source code has parser errorspublic static BodyDeclaration<?> parseBodyDeclaration(String body) throws ParseException
String and returns a BodyDeclaration that represents it.body - String containing Java body declarationParseException - if the source code has parser errorspublic static BodyDeclaration<?> parseClassBodyDeclaration(String body) throws ParseException
BodyDeclaration that represents it.body - the body of a classParseException - if the source code has parser errorspublic static BodyDeclaration parseInterfaceBodyDeclaration(String body) throws ParseException
BodyDeclaration that represents it.body - the body of an interfaceParseException - if the source code has parser errorsCopyright © 2007–2016. All rights reserved.