use of org.drools.modelcompiler.builder.GeneratedClassWithPackage in project drools by kiegroup.
the class LegacyAccumulate method createAllAccumulateClass.
private GeneratedClassWithPackage createAllAccumulateClass(Set<String> imports, String packageName) {
final String allAccumulatesClass = new JavaRuleClassBuilder().buildRule(ruleBuildContext);
final CompilationUnit parsedAccumulateClass = JavaParser.parse(allAccumulatesClass);
return new GeneratedClassWithPackage((ClassOrInterfaceDeclaration) parsedAccumulateClass.getType(0), packageName, imports);
}
use of org.drools.modelcompiler.builder.GeneratedClassWithPackage in project drools by kiegroup.
the class LegacyAccumulate method build.
public void build() {
new PatternBuilder().build(ruleBuildContext, basePattern);
final Set<String> imports = ruleBuildContext.getPkg().getImports().keySet();
final String packageName = ruleBuildContext.getPkg().getName();
GeneratedClassWithPackage generatedClassWithPackage = createAllAccumulateClass(imports, packageName);
packageModel.addGeneratedAccumulateClasses(generatedClassWithPackage);
GeneratedClassWithPackage invokerGenerated = createInvokerClass(imports, packageName);
packageModel.addGeneratedAccumulateClasses(invokerGenerated);
final String typeWithPackage = String.format("%s.%s", packageName, invokerGenerated.getGeneratedClass().getName().asString());
final ClassExpr accFunctionName = new ClassExpr(JavaParser.parseType(typeWithPackage));
final MethodCallExpr accFunctionCall = new MethodCallExpr(null, "accFunction", nodeList(accFunctionName));
final NameExpr bindingVariable = new NameExpr(toVar(basePattern.getIdentifier()));
final MethodCallExpr asDSL = new MethodCallExpr(accFunctionCall, "as", nodeList(bindingVariable));
context.addExpression(asDSL);
}
use of org.drools.modelcompiler.builder.GeneratedClassWithPackage in project drools by kiegroup.
the class LegacyAccumulate method createInvokerClass.
private GeneratedClassWithPackage createInvokerClass(Set<String> imports, String packageName) {
final String invokerClass = ruleBuildContext.getInvokers().values().iterator().next();
final CompilationUnit parsedInvokedClass = JavaParser.parse(invokerClass);
Set<String> allImports = new HashSet<>();
allImports.addAll(imports);
allImports.addAll(parsedInvokedClass.getImports().stream().map(importDeclaration -> importDeclaration.getName().toString()).collect(Collectors.toList()));
return new GeneratedClassWithPackage((ClassOrInterfaceDeclaration) parsedInvokedClass.getType(0), packageName, allImports);
}
Aggregations