use of org.drools.modelcompiler.builder.generator.declaredtype.api.MethodWithStringBody in project drools by kiegroup.
the class FEELPropertyAccessibleImplementation method processCompositeCollection.
private MethodDefinition processCompositeCollection() {
MethodDeclaration processCompositeCollection = cloneMethodTemplate("processCompositeCollection");
BlockStmt body = processCompositeCollection.getBody().orElseThrow(() -> new InvalidTemplateException("Missing body in generated method"));
MethodWithStringBody processCompositeCollectionDefinition = new MethodWithStringBody("processCompositeCollection", "void", body.toString());
processCompositeCollectionDefinition.addParameter("java.util.Collection", "destCol");
processCompositeCollectionDefinition.addParameter("java.util.Collection", "srcCol");
processCompositeCollectionDefinition.addParameter("Class<?>", "baseClass");
return processCompositeCollectionDefinition;
}
use of org.drools.modelcompiler.builder.generator.declaredtype.api.MethodWithStringBody in project drools by kiegroup.
the class FEELPropertyAccessibleImplementation method getFeelPropertyDefinition.
private MethodDefinition getFeelPropertyDefinition() {
MethodDeclaration getFEELProperty = cloneMethodTemplate("getFEELProperty");
SwitchStmt firstSwitch = getFEELProperty.findFirst(SwitchStmt.class).orElseThrow(() -> new InvalidTemplateException("Missing Switch Statement in getFEELProperty template"));
firstSwitch.setComment(null);
List<SwitchEntry> collect = fields.stream().map(this::toGetPropertySwitchEntry).collect(Collectors.toList());
SwitchEntry defaultSwitchStmt = firstSwitch.findFirst(SwitchEntry.class, sw -> sw.getLabels().isEmpty()).orElseThrow(() -> new InvalidTemplateException("Missing Default Switch Statement in getFEELProperty template"));
collect.add(defaultSwitchStmt);
firstSwitch.setEntries(nodeList(collect));
String body = getFEELProperty.getBody().orElseThrow(() -> new InvalidTemplateException("Empty body in getFeelProperty clone")).toString();
MethodWithStringBody getFeelPropertyDefinition = new MethodWithStringBody("getFEELProperty", EvalHelper.PropertyValueResult.class.getCanonicalName(), body).addParameter(String.class.getCanonicalName(), "property");
addOverrideAnnotation(getFeelPropertyDefinition);
return getFeelPropertyDefinition;
}
use of org.drools.modelcompiler.builder.generator.declaredtype.api.MethodWithStringBody 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.MethodWithStringBody 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;
}
use of org.drools.modelcompiler.builder.generator.declaredtype.api.MethodWithStringBody in project drools by kiegroup.
the class FEELPropertyAccessibleImplementation method setFeelPropertyDefinition.
private MethodDefinition setFeelPropertyDefinition() {
MethodDeclaration setFEELProperty = cloneMethodTemplate("setFEELProperty");
SwitchStmt firstSwitch = setFEELProperty.findFirst(SwitchStmt.class).orElseThrow(() -> new InvalidTemplateException("Missing switch statement in setFEELProperty"));
firstSwitch.setComment(null);
List<SwitchEntry> collect = fields.stream().map(this::toSetPropertySwitchEntry).collect(Collectors.toList());
firstSwitch.setEntries(nodeList(collect));
BlockStmt body = setFEELProperty.getBody().orElseThrow(() -> new InvalidTemplateException("Empty body in setFEELProperty"));
if (typeDefinition instanceof AbstractDMNSetType) {
body.addStatement(0, new ExpressionStmt(StaticJavaParser.parseExpression("definedKeySet.add(property)")));
}
MethodWithStringBody setFeelPropertyDefinition = new MethodWithStringBody("setFEELProperty", "void", body.toString()).addParameter(String.class.getCanonicalName(), "property").addParameter(Object.class.getCanonicalName(), "value");
addOverrideAnnotation(setFeelPropertyDefinition);
return setFeelPropertyDefinition;
}
Aggregations