use of com.github.javaparser.ASTParser in project javaparser by javaparser.
the class JavaParser method parseExpression.
/**
* Parses the Java expression contained in a {@link String} and returns a
* {@link Expression} that represents it.
*
* @param expression
* {@link String} containing Java expression
* @return Expression representing the Java expression
* @throws ParseException
* if the source code has parser errors
*/
public static Expression parseExpression(final String expression) {
StringReader sr = new StringReader(expression);
Expression e = new ASTParser(sr).Expression();
sr.close();
return e;
}
use of com.github.javaparser.ASTParser in project javaparser by javaparser.
the class JavaParser method parse.
public static CompilationUnit parse(final Reader reader, boolean considerComments) {
try {
String code = SourcesHelper.readerToString(reader);
Reader reader1 = SourcesHelper.stringToReader(code);
CompilationUnit cu = new ASTParser(reader1).CompilationUnit();
if (considerComments) {
insertComments(cu, code);
}
return cu;
} catch (IOException ioe) {
throw new ParseException(ioe.getMessage());
}
}
use of com.github.javaparser.ASTParser in project javaparser by javaparser.
the class JavaParser method parseBlock.
/**
* Parses the Java block contained in a {@link String} and returns a
* {@link BlockStmt} that represents it.
*
* @param blockStatement
* {@link String} containing Java block code
* @return BlockStmt representing the Java block
* @throws ParseException
* if the source code has parser errors
*/
public static BlockStmt parseBlock(final String blockStatement) {
StringReader sr = new StringReader(blockStatement);
BlockStmt result = new ASTParser(sr).Block();
sr.close();
return result;
}
use of com.github.javaparser.ASTParser in project javaparser by javaparser.
the class JavaParser method parse.
/**
* Parses the Java code contained in the {@link InputStream} and returns a
* {@link CompilationUnit} that represents it.
*
* @param in
* {@link InputStream} containing Java source code
* @param encoding
* encoding of the source code
* @return CompilationUnit representing the Java source code
* @throws ParseException
* if the source code has parser errors
*/
public static CompilationUnit parse(final InputStream in, final String encoding, boolean considerComments) {
try {
String code = SourcesHelper.streamToString(in, encoding);
InputStream in1 = SourcesHelper.stringToStream(code, encoding);
CompilationUnit cu = new ASTParser(in1, encoding).CompilationUnit();
if (considerComments) {
insertComments(cu, code);
}
return cu;
} catch (IOException ioe) {
throw new ParseException(ioe.getMessage());
}
}
use of com.github.javaparser.ASTParser in project javaparser by javaparser.
the class JavaParser method parseStatement.
/**
* Parses the Java statement contained in a {@link String} and returns a
* {@link Statement} that represents it.
*
* @param statement
* {@link String} containing Java statement code
* @return Statement representing the Java statement
* @throws ParseException
* if the source code has parser errors
*/
public static Statement parseStatement(final String statement) {
StringReader sr = new StringReader(statement);
Statement stmt = new ASTParser(sr).Statement();
sr.close();
return stmt;
}
Aggregations