use of com.github.javaparser.ast.stmt.SwitchStmt in project drools by kiegroup.
the class AccessibleMethod method setterSwitchStatement.
private Statement setterSwitchStatement() {
SwitchStmt switchStmt = switchOnFieldName();
NodeList<SwitchEntry> entries = switchStmt.getEntries();
for (DescrFieldDefinition field : fields) {
if (!field.isOverride()) {
entries.add(setValueFromField(field));
}
}
Optional<Class<?>> abstractResolvedClass = descrTypeDefinition.getAbstractResolvedClass();
if (abstractResolvedClass.isPresent()) {
entries.addAll(superClassSetterEntries(abstractResolvedClass.get()).collect(toList()));
} else if (descrTypeDefinition.getDeclaredAbstractClass().isPresent()) {
entries.add(switchEntry(SUPER_SET_VALUE));
}
return new BlockStmt(nodeList(switchStmt));
}
use of com.github.javaparser.ast.stmt.SwitchStmt 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