use of com.github.javaparser.Problem in project javaparser by javaparser.
the class BulkParseTest method writeResults.
private void writeResults(TreeMap<Path, List<Problem>> results, String testResultsFileName) throws IOException {
Log.info("Writing results...");
Path testResults = CodeGenerationUtils.mavenModuleRoot(BulkParseTest.class).resolve(Paths.get("..", "javaparser-core-testing", "src", "test", "resources", "com", "github", "javaparser", "bulk_test_results")).normalize();
testResults.toFile().mkdirs();
testResults = testResults.resolve(testResultsFileName);
int problemTotal = 0;
try (BufferedWriter writer = Files.newBufferedWriter(testResults)) {
for (Map.Entry<Path, List<Problem>> file : results.entrySet()) {
writer.write(file.getKey().toString().replace("\\", "/"));
writer.newLine();
for (Problem problem : file.getValue()) {
writer.write(problem.getVerboseMessage());
writer.newLine();
problemTotal++;
}
writer.newLine();
}
writer.write(f("%s problems in %s files", problemTotal, results.size()));
}
Log.info("Results are in %s", testResults);
}
use of com.github.javaparser.Problem in project javaparser by javaparser.
the class Java1_0ValidatorTest method nonEmptyList.
@Test
public void nonEmptyList() {
ArrayCreationExpr expr = new ArrayCreationExpr(PrimitiveType.booleanType());
List<Problem> problems = new ArrayList<>();
new Java1_0Validator().accept(expr, new ProblemReporter(problems::add));
assertEquals("ArrayCreationExpr.levels can not be empty.", problems.get(0).getMessage());
}
use of com.github.javaparser.Problem in project javaparser by javaparser.
the class Java7ValidatorTest method multiCatchWithoutElements.
@Test
public void multiCatchWithoutElements() {
UnionType unionType = new UnionType();
List<Problem> problems = new ArrayList<>();
new Java7Validator().accept(unionType, new ProblemReporter(problems::add));
assertProblems(problems, "UnionType.elements can not be empty.");
}
use of com.github.javaparser.Problem in project javaparser by javaparser.
the class ParseResultTest method whenParsingFailsThenWeGetProblemsAndABadResult.
@Test
public void whenParsingFailsThenWeGetProblemsAndABadResult() {
ParseResult<CompilationUnit> result = javaParser.parse(COMPILATION_UNIT, provider("class {"));
assertThat(result.getResult().isPresent()).isTrue();
assertThat(result.getResult().get().getParsed()).isEqualTo(UNPARSABLE);
assertThat(result.getProblems().size()).isEqualTo(1);
Problem problem = result.getProblem(0);
assertThat(problem.getMessage()).isEqualTo("Parse error. Found \"{\", expected one of \"enum\" \"exports\" \"module\" \"open\" \"opens\" \"provides\" \"requires\" \"strictfp\" \"to\" \"transitive\" \"uses\" \"with\" <IDENTIFIER>");
assertThat(result.getTokens().isPresent()).isTrue();
assertThat(result.toString()).startsWith("Parsing failed:" + EOL + "(line 1,col 1) Parse error.");
}
use of com.github.javaparser.Problem in project javaparser by javaparser.
the class Java7ValidatorTest method multiCatchWithOneElement.
@Test
public void multiCatchWithOneElement() {
UnionType unionType = new UnionType();
unionType.getElements().add(new ClassOrInterfaceType());
List<Problem> problems = new ArrayList<>();
new Java7Validator().accept(unionType, new ProblemReporter(problems::add));
assertProblems(problems, "Union type (multi catch) must have at least two elements.");
}
Aggregations