use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class Issue128 method loopOnStaticallyImportedType.
@Test
public void loopOnStaticallyImportedType() {
CompilationUnit cu = parseSampleWithStandardExtension("issue128/foo/Issue128");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "JavaTest");
ExpressionStmt expressionStmt = (ExpressionStmt) clazz.getMethodsByName("test").get(0).getBody().get().getStatement(0);
MethodCallExpr methodCallExpr = (MethodCallExpr) expressionStmt.getExpression();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
assertEquals(false, javaParserFacade.solve(methodCallExpr).isSolved());
}
use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class JavaParserTypeSolver method parseDirectory.
private List<CompilationUnit> parseDirectory(File srcDirectory) {
try {
return parsedDirectories.get(srcDirectory.getAbsolutePath(), () -> {
List<CompilationUnit> units = new ArrayList<>();
File[] files = srcDirectory.listFiles();
if (files != null) {
for (File file : files) {
if (file.getName().toLowerCase().endsWith(".java")) {
Optional<CompilationUnit> unit = parse(file);
if (unit.isPresent()) {
units.add(unit.get());
}
}
}
}
return units;
});
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
}
use of com.github.javaparser.ast.CompilationUnit 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.ast.CompilationUnit 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.ast.CompilationUnit in project javaparser by javaparser.
the class ParseErrorRecoveryTest method compilationUnitRecovery.
@Test
public void compilationUnitRecovery() {
CompilationUnit cu = parser.parse(ParseStart.COMPILATION_UNIT, provider("XXX")).getResult().get();
assertEquals(UNPARSABLE, cu.getParsed());
}
Aggregations