use of com.github.javaparser.ast.stmt.SwitchEntry 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.SwitchEntry in project drools by kiegroup.
the class PropagatorCompilerHandler method startHashedAlphaNode.
@Override
public void startHashedAlphaNode(AlphaNode hashedAlpha, Object hashedValue) {
SwitchEntry newSwitchEntry = new SwitchEntry();
if (canInlineValue(fieldType)) {
final Expression quotedHashedValue;
if (hashedValue instanceof String) {
quotedHashedValue = new StringLiteralExpr((String) hashedValue);
} else if (hashedValue instanceof Long) {
quotedHashedValue = new LongLiteralExpr((Long) hashedValue);
} else {
quotedHashedValue = new IntegerLiteralExpr((Integer) hashedValue);
}
newSwitchEntry.setLabels(nodeList(quotedHashedValue));
} else {
newSwitchEntry.setLabels(nodeList(new IntegerLiteralExpr(hashedAlpha.getId())));
}
addNewSwitchEntryToStack(newSwitchEntry);
}
use of com.github.javaparser.ast.stmt.SwitchEntry 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;
}
use of com.github.javaparser.ast.stmt.SwitchEntry in project drools by kiegroup.
the class FEELPropertyAccessibleImplementation method toGetPropertySwitchEntry.
private SwitchEntry toGetPropertySwitchEntry(DMNDeclaredField fieldDefinition) {
ReturnStmt returnStmt = new ReturnStmt();
MethodCallExpr mc = StaticJavaParser.parseExpression(EvalHelper.PropertyValueResult.class.getCanonicalName() + ".ofValue()");
String accessorName = fieldDefinition.overriddenGetterName().orElse(getAccessorName(fieldDefinition, "get"));
mc.addArgument(new MethodCallExpr(new ThisExpr(), accessorName));
returnStmt.setExpression(mc);
return new SwitchEntry(nodeList(new StringLiteralExpr(fieldDefinition.getOriginalMapKey())), SwitchEntry.Type.STATEMENT_GROUP, nodeList(returnStmt));
}
use of com.github.javaparser.ast.stmt.SwitchEntry in project drools by kiegroup.
the class FEELPropertyAccessibleImplementation method toSetPropertySwitchEntry.
private SwitchEntry toSetPropertySwitchEntry(DMNDeclaredField fieldDefinition) {
String accessorName = fieldDefinition.overriddenSetterName().orElse(getAccessorName(fieldDefinition, "set"));
MethodCallExpr setMethod = new MethodCallExpr(new ThisExpr(), accessorName);
setMethod.addArgument(new CastExpr(StaticJavaParser.parseType(fieldDefinition.getObjectType()), new NameExpr("value")));
ExpressionStmt setStatement = new ExpressionStmt();
setStatement.setExpression(setMethod);
NodeList<Expression> labels = nodeList(new StringLiteralExpr(fieldDefinition.getOriginalMapKey()));
NodeList<Statement> statements = nodeList(setStatement, new ReturnStmt());
return new SwitchEntry(labels, SwitchEntry.Type.STATEMENT_GROUP, statements);
}
Aggregations