Search in sources :

Example 1 with PrettyPrinter

use of com.github.javaparser.printer.PrettyPrinter in project javaparser by javaparser.

the class MetaModelGenerator method main.

public static void main(String[] args) throws IOException, NoSuchMethodException {
    if (args.length != 1) {
        throw new RuntimeException("Need 1 parameter: the JavaParser source checkout root directory.");
    }
    final Path root = Paths.get(args[0], "..", "javaparser-core", "src", "main", "java");
    final SourceRoot sourceRoot = new SourceRoot(root);
    sourceRoot.setPrinter(new PrettyPrinter(new PrettyPrinterConfiguration().setEndOfLineCharacter("\n"))::print);
    new MetaModelGenerator().run(sourceRoot);
    sourceRoot.saveAll();
}
Also used : Path(java.nio.file.Path) PrettyPrinter(com.github.javaparser.printer.PrettyPrinter) SourceRoot(com.github.javaparser.utils.SourceRoot) PrettyPrinterConfiguration(com.github.javaparser.printer.PrettyPrinterConfiguration)

Example 2 with PrettyPrinter

use of com.github.javaparser.printer.PrettyPrinter in project drools by kiegroup.

the class QueryGenerator method main.

public static void main(String[] args) {
    int arity = 10;
    CompilationUnit patternDSL = new CompilationUnit();
    ClassOrInterfaceDeclaration clazzPatternDSL = patternDSL.addClass("PatternDSL");
    range(arity).forEach(arity1 -> new PatternDSLQueryGenerator(clazzPatternDSL, arity1).generate());
    System.out.println(new PrettyPrinter().print(clazzPatternDSL));
    CompilationUnit flowDSL = new CompilationUnit();
    ClassOrInterfaceDeclaration clazzFlowDSL = flowDSL.addClass("FlowDSL");
    range(arity).forEach(arity1 -> new FlowDSLQueryGenerator(clazzFlowDSL, arity1).generate());
    System.out.println(new PrettyPrinter().print(clazzFlowDSL));
    range(arity).forEach(QueryGenerator::generateQueryDef);
    range(arity).forEach(QueryGenerator::generateQueryDefImpl);
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) PrettyPrinter(com.github.javaparser.printer.PrettyPrinter) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)

Example 3 with PrettyPrinter

use of com.github.javaparser.printer.PrettyPrinter in project drools by kiegroup.

the class QueryGenerator method generateQueryDef.

private static void generateQueryDef(int arity) {
    QueryDefGenerator queryDefGenerator = new QueryDefGenerator(arity);
    CompilationUnit queryDef = queryDefGenerator.generate();
    String generatedClass = new PrettyPrinter().print(queryDef);
    try {
        Path querydef = Paths.get("/tmp/", "querydef", queryDefGenerator.getClassName() + ".java");
        Files.createDirectories(querydef.getParent());
        Files.write(querydef, generatedClass.getBytes());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) Path(java.nio.file.Path) PrettyPrinter(com.github.javaparser.printer.PrettyPrinter)

Example 4 with PrettyPrinter

use of com.github.javaparser.printer.PrettyPrinter in project drools by kiegroup.

the class QueryGenerator method generateQueryDefImpl.

private static void generateQueryDefImpl(int arity) {
    QueryDefImplGenerator queryDefImplGenerator = new QueryDefImplGenerator(arity);
    CompilationUnit queryDefImpl = queryDefImplGenerator.generate();
    String generatedClass = new PrettyPrinter().print(queryDefImpl);
    try {
        Path queryimpl = Paths.get("/tmp/", "queryimpl", queryDefImplGenerator.getClassName() + ".java");
        Files.createDirectories(queryimpl.getParent());
        Files.write(queryimpl, generatedClass.getBytes());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) Path(java.nio.file.Path) PrettyPrinter(com.github.javaparser.printer.PrettyPrinter)

Aggregations

PrettyPrinter (com.github.javaparser.printer.PrettyPrinter)4 CompilationUnit (com.github.javaparser.ast.CompilationUnit)3 Path (java.nio.file.Path)3 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)1 PrettyPrinterConfiguration (com.github.javaparser.printer.PrettyPrinterConfiguration)1 SourceRoot (com.github.javaparser.utils.SourceRoot)1