public final class JavaParser extends Object
| Constructor and Description |
|---|
JavaParser(ParserConfiguration configuration)
Instantiate the parser.
|
| Modifier and Type | Method and Description |
|---|---|
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(Path path)
Parses the Java code contained in a file and returns a
CompilationUnit that represents it.Note: Uses UTF-8 encoding |
static CompilationUnit |
parse(Path path,
Charset encoding) |
static CompilationUnit |
parse(Path path,
Charset encoding,
boolean considerComments)
Parses the Java code contained in a file 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. |
static AnnotationExpr |
parseAnnotation(String annotation)
Parses the Java annotation contained in a
String and returns a
AnnotationExpr that represents it. |
static BodyDeclaration<?> |
parseAnnotationBodyDeclaration(String body)
Parses the Java annotation body declaration(e.g fields or methods) contained in a
String and returns a BodyDeclaration that represents it. |
static BlockStmt |
parseBlock(String blockStatement)
|
static BodyDeclaration<?> |
parseClassBodyDeclaration(String body)
Parses a Java class body declaration(e.g fields or methods) and returns a
BodyDeclaration that represents it. |
static Expression |
parseExpression(String expression)
Parses the Java expression contained in a
String and returns a
Expression that represents it. |
ParseResult<CompilationUnit> |
parseFull(Provider provider)
Parses a compilation unit and its comments.
|
static ImportDeclaration |
parseImport(String importDeclaration)
Parses the Java import contained in a
String and returns a
ImportDeclaration 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. |
static Statement |
parseStatement(String statement)
|
static List<Statement> |
parseStatements(String statements)
|
<N> ParseResult<N> |
parseStructure(ParseContext<N> context,
Provider provider)
Parses source code without comments.
|
public JavaParser(ParserConfiguration configuration)
public <N> ParseResult<N> parseStructure(ParseContext<N> context, Provider provider)
N - the subclass of Node that is the result of parsing in the context.context - refer to the constants in ParseContext to see what can be parsed.provider - refer to Providers to see how you can read sourcepublic ParseResult<CompilationUnit> parseFull(Provider provider)
provider - refer to Providers to see how you can read sourcepublic static CompilationUnit parse(InputStream in, Charset encoding)
public static CompilationUnit parse(InputStream in, Charset encoding, boolean considerComments)
InputStream and returns a
CompilationUnit that represents it.in - InputStream containing Java source codeencoding - encoding of the source codeParseProblemException - if the source code has parser errorspublic static CompilationUnit parse(InputStream in)
InputStream and returns a
CompilationUnit that represents it.in - InputStream containing Java source codeParseProblemException - if the source code has parser errorspublic static CompilationUnit parse(File file, Charset encoding) throws FileNotFoundException
FileNotFoundExceptionpublic static CompilationUnit parse(File file, Charset encoding, boolean considerComments) throws FileNotFoundException
File and returns a
CompilationUnit that represents it.file - File containing Java source codeencoding - encoding of the source codeParseProblemException - if the source code has parser errorsFileNotFoundExceptionpublic static CompilationUnit parse(File file) throws FileNotFoundException
File and returns a
CompilationUnit that represents it.file - File containing Java source codeParseProblemException - if the source code has parser errorsFileNotFoundException - the file was not foundpublic static CompilationUnit parse(Path path, Charset encoding) throws IOException
IOExceptionpublic static CompilationUnit parse(Path path, Charset encoding, boolean considerComments) throws IOException
CompilationUnit that represents it.path - path to a file containing Java source codeencoding - encoding of the source codeIOException - the path could not be accessedParseProblemException - if the source code has parser errorspublic static CompilationUnit parse(Path path) throws IOException
CompilationUnit that represents it.path - path to a file containing Java source codeParseProblemException - if the source code has parser errorsIOException - the path could not be accessedpublic static CompilationUnit parse(Reader reader)
public static CompilationUnit parse(Reader reader, boolean considerComments)
public static CompilationUnit parse(String code, boolean considerComments)
CompilationUnit that represents it.code - Java source codeconsiderComments - parse or ignore commentsParseProblemException - if the source code has parser errorspublic static CompilationUnit parse(String code)
CompilationUnit that represents it.code - Java source codeParseProblemException - if the source code has parser errorspublic static BlockStmt parseBlock(String blockStatement)
blockStatement - String containing Java block codeParseProblemException - if the source code has parser errorspublic static Statement parseStatement(String statement)
statement - String containing Java statement codeParseProblemException - if the source code has parser errorspublic static List<Statement> parseStatements(String statements)
String and returns a
list of Statement that represents it.statements - String containing Java statementsParseProblemException - if the source code has parser errorspublic static ImportDeclaration parseImport(String importDeclaration)
String and returns a
ImportDeclaration that represents it.importDeclaration - String containing Java import codeParseProblemException - if the source code has parser errorspublic static Expression parseExpression(String expression)
String and returns a
Expression that represents it.expression - String containing Java expressionParseProblemException - if the source code has parser errorspublic static AnnotationExpr parseAnnotation(String annotation)
String and returns a
AnnotationExpr that represents it.annotation - String containing Java annotationParseProblemException - if the source code has parser errorspublic static BodyDeclaration<?> parseAnnotationBodyDeclaration(String body)
String and returns a BodyDeclaration that represents it.body - String containing Java body declarationParseProblemException - if the source code has parser errorspublic static BodyDeclaration<?> parseClassBodyDeclaration(String body)
BodyDeclaration that represents it.body - the body of a classParseProblemException - if the source code has parser errorspublic static BodyDeclaration parseInterfaceBodyDeclaration(String body)
BodyDeclaration that represents it.body - the body of an interfaceParseProblemException - if the source code has parser errorsCopyright © 2007–2016. All rights reserved.