Search in sources :

Example 1 with Problem

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);
}
Also used : Path(java.nio.file.Path) List(java.util.List) Problem(com.github.javaparser.Problem) Map(java.util.Map) TreeMap(java.util.TreeMap) BufferedWriter(java.io.BufferedWriter)

Example 2 with Problem

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());
}
Also used : ArrayList(java.util.ArrayList) Problem(com.github.javaparser.Problem) ArrayCreationExpr(com.github.javaparser.ast.expr.ArrayCreationExpr) Test(org.junit.Test)

Example 3 with Problem

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.");
}
Also used : UnionType(com.github.javaparser.ast.type.UnionType) Problem(com.github.javaparser.Problem) Test(org.junit.Test)

Example 4 with Problem

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.");
}
Also used : Problem(com.github.javaparser.Problem) Test(org.junit.Test)

Example 5 with Problem

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.");
}
Also used : UnionType(com.github.javaparser.ast.type.UnionType) Problem(com.github.javaparser.Problem) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) Test(org.junit.Test)

Aggregations

Problem (com.github.javaparser.Problem)5 Test (org.junit.Test)4 UnionType (com.github.javaparser.ast.type.UnionType)2 ArrayCreationExpr (com.github.javaparser.ast.expr.ArrayCreationExpr)1 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)1 BufferedWriter (java.io.BufferedWriter)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1