Search in sources :

Example 6 with ParseResult

use of com.github.javaparser.ParseResult in project javaparser by javaparser.

the class SourceRoot method saveAll.

/**
 * Save all previously parsed files back to a new path.
 */
public SourceRoot saveAll(Path root) {
    assertNotNull(root);
    Log.info("Saving all files (%s) to %s", cache.size(), root);
    for (Map.Entry<Path, ParseResult<CompilationUnit>> cu : cache.entrySet()) {
        final Path path = root.resolve(cu.getKey());
        if (cu.getValue().getResult().isPresent()) {
            Log.trace("Saving %s", path);
            save(cu.getValue().getResult().get(), path);
        }
    }
    return this;
}
Also used : CodeGenerationUtils.fileInPackageRelativePath(com.github.javaparser.utils.CodeGenerationUtils.fileInPackageRelativePath) Path(java.nio.file.Path) CodeGenerationUtils.packageAbsolutePath(com.github.javaparser.utils.CodeGenerationUtils.packageAbsolutePath) ParseResult(com.github.javaparser.ParseResult) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 7 with ParseResult

use of com.github.javaparser.ParseResult in project scheduler by btrplace.

the class DSN method specLength.

// @Test
public void specLength() throws Exception {
    SpecScanner sc = new SpecScanner();
    List<Constraint> l = sc.scan();
    System.out.println(l.stream().map(Constraint::pretty).collect(Collectors.joining("\n")));
    Path path = Paths.get(root, "inv.csv");
    String out = l.stream().map(c -> Integer.toString(c.proposition().toString().length())).collect(Collectors.joining("\n"));
    Files.write(path, out.getBytes());
    List<Integer> funcs = new ArrayList<>();
    List<Path> paths = Files.list(Paths.get("safeplace/src/main/java/org/btrplace/safeplace/spec/term/func")).filter(Files::isRegularFile).collect(Collectors.toList());
    for (Path p : paths) {
        try (InputStream in = Files.newInputStream(p)) {
            ParseResult<CompilationUnit> cu = new JavaParser().parse(in);
            new FunctionVisitor(funcs).visit(cu.getResult().get(), null);
        }
    }
    path = Paths.get(root, "func.csv");
    out = funcs.stream().map(c -> Integer.toString(c)).collect(Collectors.joining("\n"));
    Files.write(path, out.getBytes());
}
Also used : Path(java.nio.file.Path) CSVReport(org.btrplace.safeplace.testing.reporting.CSVReport) PrettyPrinterConfiguration(com.github.javaparser.printer.configuration.PrettyPrinterConfiguration) ParseResult(com.github.javaparser.ParseResult) VoidVisitorAdapter(com.github.javaparser.ast.visitor.VoidVisitorAdapter) AnnotationExpr(com.github.javaparser.ast.expr.AnnotationExpr) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Restriction(org.btrplace.safeplace.testing.fuzzer.Restriction) Constraint(org.btrplace.safeplace.spec.Constraint) Matcher(java.util.regex.Matcher) Assert(org.testng.Assert) Map(java.util.Map) CompilationUnit(com.github.javaparser.ast.CompilationUnit) SpecScanner(org.btrplace.safeplace.spec.SpecScanner) Path(java.nio.file.Path) EnumSet(java.util.EnumSet) SpecVerifier(org.btrplace.safeplace.testing.verification.spec.SpecVerifier) TestScanner(org.btrplace.safeplace.testing.TestScanner) Files(java.nio.file.Files) Verifier(org.btrplace.safeplace.testing.verification.Verifier) Collectors(java.util.stream.Collectors) Bench(org.btrplace.safeplace.testing.Bench) List(java.util.List) StoredReport(org.btrplace.safeplace.testing.reporting.StoredReport) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) Paths(java.nio.file.Paths) Result(org.btrplace.safeplace.testing.Result) TestCampaign(org.btrplace.safeplace.testing.TestCampaign) Pattern(java.util.regex.Pattern) CheckerVerifier(org.btrplace.safeplace.testing.verification.btrplace.CheckerVerifier) JavaParser(com.github.javaparser.JavaParser) InputStream(java.io.InputStream) CompilationUnit(com.github.javaparser.ast.CompilationUnit) JavaParser(com.github.javaparser.JavaParser) Constraint(org.btrplace.safeplace.spec.Constraint) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) SpecScanner(org.btrplace.safeplace.spec.SpecScanner)

Aggregations

ParseResult (com.github.javaparser.ParseResult)7 Path (java.nio.file.Path)6 CompilationUnit (com.github.javaparser.ast.CompilationUnit)5 CodeGenerationUtils.fileInPackageRelativePath (com.github.javaparser.utils.CodeGenerationUtils.fileInPackageRelativePath)4 CodeGenerationUtils.packageAbsolutePath (com.github.javaparser.utils.CodeGenerationUtils.packageAbsolutePath)4 Map (java.util.Map)4 JavaParser (com.github.javaparser.JavaParser)3 Files (java.nio.file.Files)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Pattern (java.util.regex.Pattern)3 Collectors (java.util.stream.Collectors)3 ParseProblemException (com.github.javaparser.ParseProblemException)2 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)2 AnnotationExpr (com.github.javaparser.ast.expr.AnnotationExpr)2 VoidVisitorAdapter (com.github.javaparser.ast.visitor.VoidVisitorAdapter)2 PrettyPrinterConfiguration (com.github.javaparser.printer.configuration.PrettyPrinterConfiguration)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Paths (java.nio.file.Paths)2