use of org.drools.modelcompiler.builder.generator.declaredtype.api.TypeDefinition in project drools by kiegroup.
the class FEELPropertyAccessibleImplementation method allFeelProperties.
private MethodWithStringBody allFeelProperties() {
MethodDeclaration allFeelProperties = cloneMethodTemplate("allFEELProperties");
MethodCallExpr putExpression = allFeelProperties.findFirst(MethodCallExpr.class, mc -> mc.getNameAsString().equals("put")).orElseThrow(() -> new InvalidTemplateException("Missing put method in allFEELProperties"));
List<Statement> collect = fields.stream().map(fieldDefinition -> toResultPut(putExpression, fieldDefinition)).collect(Collectors.toList());
if (typeDefinition instanceof AbstractDMNSetType) {
collect.add(new ExpressionStmt(StaticJavaParser.parseExpression("result.entrySet().removeIf(entry -> java.util.Objects.isNull(entry.getValue()) && !definedKeySet.contains(entry.getKey()))")));
}
BlockStmt newBlockStatement = new BlockStmt(nodeList(collect));
putExpression.getParentNode().ifPresent(p -> p.replace(newBlockStatement));
BlockStmt body = allFeelProperties.getBody().orElseThrow(() -> new InvalidTemplateException("Missing body in generated method"));
MethodWithStringBody allFEELProperties = new MethodWithStringBody("allFEELProperties", "java.util.Map<String, Object>", body.toString());
addOverrideAnnotation(allFEELProperties);
return allFEELProperties;
}
use of org.drools.modelcompiler.builder.generator.declaredtype.api.TypeDefinition in project drools by kiegroup.
the class DMNTypeSafeTypeGenerator method generateSourceCodeOfAllTypes.
public Map<String, String> generateSourceCodeOfAllTypes() {
Map<String, String> allSources = new HashMap<>();
DMNTypeSafePackageName packageDeclaration = this.packageName.create(dmnModel);
for (TypeDefinition typeDefinition : types) {
ClassOrInterfaceDeclaration generatedClass = new GeneratedClassDeclaration(typeDefinition, Collections.emptyList()).toClassDeclaration();
CompilationUnit cu = new CompilationUnit(packageDeclaration.packageName());
cu.getPackageDeclaration().ifPresent(pd -> pd.setBlockComment(this.disclaimerMarker));
cu.addType(generatedClass);
LOG.debug("\n{}", cu);
allSources.put(packageDeclaration.appendPackage(typeDefinition.getTypeName()), cu.toString());
}
return allSources;
}
use of org.drools.modelcompiler.builder.generator.declaredtype.api.TypeDefinition in project drools by kiegroup.
the class FEELPropertyAccessibleImplementation method fromMap.
private MethodDefinition fromMap() {
MethodDeclaration allFeelProperties = cloneMethodTemplate("fromMap");
BlockStmt originalStatements = allFeelProperties.getBody().orElseThrow(() -> new InvalidTemplateException("Missing body in allFeelProperties"));
BlockStmt simplePropertyBLock = (BlockStmt) originalStatements.getStatement(0);
BlockStmt pojoPropertyBlock = (BlockStmt) originalStatements.getStatement(1);
BlockStmt collectionsCompositePropertyBlock = (BlockStmt) originalStatements.getStatement(2);
BlockStmt collectionsBasic = (BlockStmt) originalStatements.getStatement(3);
List<Statement> allStatements = fields.stream().map(f -> f.createFromMapEntry(simplePropertyBLock, pojoPropertyBlock, collectionsCompositePropertyBlock, collectionsBasic)).collect(Collectors.toList());
BlockStmt body = new BlockStmt(nodeList(allStatements));
if (typeDefinition instanceof AbstractDMNSetType) {
body.addStatement("values.keySet().stream().forEach(key -> definedKeySet.add(key));");
}
MethodWithStringBody setFeelProperty = new MethodWithStringBody("fromMap", "void", body.toString());
setFeelProperty.addParameter("java.util.Map<String, Object>", "values");
addOverrideAnnotation(setFeelProperty);
return setFeelProperty;
}
Aggregations