use of org.drools.modelcompiler.builder.generator.declaredtype.api.MethodDefinition 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.MethodDefinition 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