Search in sources :

Example 1 with SourceFileInfoExtractor

use of com.github.javaparser.symbolsolver.SourceFileInfoExtractor in project javaparser by javaparser.

the class AnalyseJavaSymbolSolver060Test method getSourceFileInfoExtractor.

private static SourceFileInfoExtractor getSourceFileInfoExtractor() {
    CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver();
    combinedTypeSolver.add(new ReflectionTypeSolver());
    combinedTypeSolver.add(new JavaParserTypeSolver(new File(src + "/java-symbol-solver-core")));
    combinedTypeSolver.add(new JavaParserTypeSolver(new File(src + "/java-symbol-solver-logic")));
    combinedTypeSolver.add(new JavaParserTypeSolver(new File(src + "/java-symbol-solver-model")));
    try {
        combinedTypeSolver.add(new JarTypeSolver(lib + "/guava-21.0.jar"));
        combinedTypeSolver.add(new JarTypeSolver(lib + "/javaparser-core-3.3.0.jar"));
        combinedTypeSolver.add(new JarTypeSolver(lib + "/javaslang-2.0.3.jar"));
        combinedTypeSolver.add(new JarTypeSolver(lib + "/javassist-3.19.0-GA.jar"));
    } catch (IOException e) {
        Assert.fail("one or more jar dependencies could not be found.");
        e.printStackTrace();
    }
    SourceFileInfoExtractor sourceFileInfoExtractor = new SourceFileInfoExtractor();
    sourceFileInfoExtractor.setTypeSolver(combinedTypeSolver);
    sourceFileInfoExtractor.setPrintFileName(false);
    sourceFileInfoExtractor.setVerbose(true);
    return sourceFileInfoExtractor;
}
Also used : SourceFileInfoExtractor(com.github.javaparser.symbolsolver.SourceFileInfoExtractor) JavaParserTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver) JarTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver)

Example 2 with SourceFileInfoExtractor

use of com.github.javaparser.symbolsolver.SourceFileInfoExtractor in project javaparser by javaparser.

the class AnalyseNewJavaParserTest method getSourceFileInfoExtractor.

private static SourceFileInfoExtractor getSourceFileInfoExtractor() {
    CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver();
    combinedTypeSolver.add(new ReflectionTypeSolver());
    combinedTypeSolver.add(new JavaParserTypeSolver(src));
    combinedTypeSolver.add(new JavaParserTypeSolver(adaptPath(new File("src/test/test_sourcecode/javaparser_new_src/javaparser-generated-sources"))));
    SourceFileInfoExtractor sourceFileInfoExtractor = new SourceFileInfoExtractor();
    sourceFileInfoExtractor.setTypeSolver(combinedTypeSolver);
    sourceFileInfoExtractor.setPrintFileName(false);
    sourceFileInfoExtractor.setVerbose(true);
    return sourceFileInfoExtractor;
}
Also used : SourceFileInfoExtractor(com.github.javaparser.symbolsolver.SourceFileInfoExtractor) JavaParserTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver)

Example 3 with SourceFileInfoExtractor

use of com.github.javaparser.symbolsolver.SourceFileInfoExtractor in project javaparser by javaparser.

the class AnalyseJavaParserTest method getSourceFileInfoExtractor.

private SourceFileInfoExtractor getSourceFileInfoExtractor() {
    CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver();
    combinedTypeSolver.add(new ReflectionTypeSolver());
    combinedTypeSolver.add(new JavaParserTypeSolver(src));
    combinedTypeSolver.add(new JavaParserTypeSolver(adaptPath(new File("src/test/test_sourcecode/javaparser_src/generated"))));
    SourceFileInfoExtractor sourceFileInfoExtractor = new SourceFileInfoExtractor();
    sourceFileInfoExtractor.setTypeSolver(combinedTypeSolver);
    sourceFileInfoExtractor.setPrintFileName(false);
    return sourceFileInfoExtractor;
}
Also used : SourceFileInfoExtractor(com.github.javaparser.symbolsolver.SourceFileInfoExtractor) JavaParserTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver) ReflectionTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver) CombinedTypeSolver(com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver)

Example 4 with SourceFileInfoExtractor

use of com.github.javaparser.symbolsolver.SourceFileInfoExtractor in project javaparser by javaparser.

the class AnalyseJavaParserTest method parse.

private void parse(String fileName) throws IOException, ParseException {
    File sourceFile = new File(src.getAbsolutePath() + "/" + fileName + ".java");
    SourceFileInfoExtractor sourceFileInfoExtractor = getSourceFileInfoExtractor();
    OutputStream outErrStream = new ByteArrayOutputStream();
    PrintStream outErr = new PrintStream(outErrStream);
    sourceFileInfoExtractor.setOut(outErr);
    sourceFileInfoExtractor.setErr(outErr);
    sourceFileInfoExtractor.solve(sourceFile);
    String output = outErrStream.toString();
    String path = "src/test/resources/javaparser_expected_output/" + fileName.replaceAll("/", "_") + ".txt";
    File dstFile = adaptPath(new File(path));
    if (DEBUG && (sourceFileInfoExtractor.getKo() != 0 || sourceFileInfoExtractor.getUnsupported() != 0)) {
        System.err.println(output);
    }
    assertTrue("No failures expected when analyzing " + path, 0 == sourceFileInfoExtractor.getKo());
    assertTrue("No UnsupportedOperationException expected when analyzing " + path, 0 == sourceFileInfoExtractor.getUnsupported());
    String expected = readFile(dstFile);
    String[] outputLines = output.split("\n");
    String[] expectedLines = expected.split("\n");
    for (int i = 0; i < Math.min(outputLines.length, expectedLines.length); i++) {
        assertEquals("Line " + (i + 1) + " of " + path + " is different from what is expected", expectedLines[i].trim(), outputLines[i].trim());
    }
    assertEquals(expectedLines.length, outputLines.length);
    JavaParserFacade.clearInstances();
// If we need to update the file uncomment these lines
// PrintWriter writer = new PrintWriter(dstFile.getAbsoluteFile(), "UTF-8");
// writer.print(output);
// writer.close();
}
Also used : SourceFileInfoExtractor(com.github.javaparser.symbolsolver.SourceFileInfoExtractor)

Aggregations

SourceFileInfoExtractor (com.github.javaparser.symbolsolver.SourceFileInfoExtractor)4 CombinedTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver)3 JavaParserTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver)3 ReflectionTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver)3 JarTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver)1