use of org.drools.javaparser.printer.PrettyPrinter in project drools by kiegroup.
the class ModelWriter method writeModel.
public Result writeModel(MemoryFileSystem srcMfs, Collection<PackageModel> packageModels) {
List<String> sourceFiles = new ArrayList<>();
List<String> modelFiles = new ArrayList<>();
PrettyPrinter prettyPrinter = getPrettyPrinter();
for (PackageModel pkgModel : packageModels) {
String pkgName = pkgModel.getName();
String folderName = pkgName.replace('.', '/');
for (ClassOrInterfaceDeclaration generatedPojo : pkgModel.getGeneratedPOJOsSource()) {
final String source = JavaParserCompiler.toPojoSource(pkgModel.getName(), pkgModel.getImports(), generatedPojo);
pkgModel.logRule(source);
String pojoSourceName = "src/main/java/" + folderName + "/" + generatedPojo.getName() + ".java";
srcMfs.write(pojoSourceName, source.getBytes());
sourceFiles.add(pojoSourceName);
}
for (GeneratedClassWithPackage generatedPojo : pkgModel.getGeneratedAccumulateClasses()) {
final String source = JavaParserCompiler.toPojoSource(pkgModel.getName(), generatedPojo.getImports(), generatedPojo.getGeneratedClass());
pkgModel.logRule(source);
String pojoSourceName = "src/main/java/" + folderName + "/" + generatedPojo.getGeneratedClass().getName() + ".java";
srcMfs.write(pojoSourceName, source.getBytes());
sourceFiles.add(pojoSourceName);
}
RuleSourceResult rulesSourceResult = pkgModel.getRulesSource();
// main rules file:
String rulesFileName = pkgModel.getRulesFileName();
String rulesSourceName = "src/main/java/" + folderName + "/" + rulesFileName + ".java";
String rulesSource = prettyPrinter.print(rulesSourceResult.getMainRuleClass());
pkgModel.logRule(rulesSource);
byte[] rulesBytes = rulesSource.getBytes();
srcMfs.write(rulesSourceName, rulesBytes);
modelFiles.add(pkgName + "." + rulesFileName);
sourceFiles.add(rulesSourceName);
// manage additional classes, please notice to not add to modelFiles.
for (CompilationUnit cu : rulesSourceResult.getSplitted()) {
String addFileName = cu.findFirst(ClassOrInterfaceDeclaration.class).get().getNameAsString();
String addSourceName = "src/main/java/" + folderName + "/" + addFileName + ".java";
String addSource = prettyPrinter.print(cu);
pkgModel.logRule(addSource);
byte[] addBytes = addSource.getBytes();
srcMfs.write(addSourceName, addBytes);
sourceFiles.add(addSourceName);
}
}
return new Result(sourceFiles, modelFiles);
}
use of org.drools.javaparser.printer.PrettyPrinter in project drools by kiegroup.
the class JavaParserCompiler method createPrettyPrinter.
private static PrettyPrinter createPrettyPrinter() {
PrettyPrinterConfiguration config = new PrettyPrinterConfiguration();
config.setColumnAlignParameters(true);
config.setColumnAlignFirstMethodChain(true);
return new PrettyPrinter(config);
}
Aggregations