use of com.github.javaparser.ast.stmt.SwitchEntry 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 com.github.javaparser.ast.stmt.SwitchEntry in project drools by kiegroup.
the class PropagatorCompilerHandler method startRangeIndexedAlphaNode.
@Override
public void startRangeIndexedAlphaNode(AlphaNode alphaNode) {
SwitchEntry switchEntry = new SwitchEntry().setLabels(nodeList(new IntegerLiteralExpr(alphaNode.getId())));
addNewSwitchEntryToStack(switchEntry);
}
use of com.github.javaparser.ast.stmt.SwitchEntry in project drools by kiegroup.
the class SetNodeReferenceHandler method generateSwitchBody.
private void generateSwitchBody(BlockStmt switchBodyStatements, List<NetworkNode> subNodes) {
SwitchStmt switchStmt = new SwitchStmt();
switchStmt.setSelector(parseExpression("node.getId()"));
NodeList<SwitchEntry> entries = new NodeList<>();
for (NetworkNode n : subNodes) {
String assignStatementString;
if (n instanceof AlphaNode) {
assignStatementString = getVariableAssignmentStatementAlphaNode((AlphaNode) n);
} else {
assignStatementString = getVariableAssignmentStatement(n);
}
Statement assignStmt = parseStatement(assignStatementString);
SwitchEntry se = new SwitchEntry(nodeList(new IntegerLiteralExpr(n.getId())), SwitchEntry.Type.STATEMENT_GROUP, nodeList(assignStmt, new ReturnStmt(new BooleanLiteralExpr(true))));
entries.add(se);
}
switchStmt.setEntries(entries);
switchBodyStatements.addStatement(switchStmt);
switchBodyStatements.addStatement(new ReturnStmt(new BooleanLiteralExpr(false)));
}
use of com.github.javaparser.ast.stmt.SwitchEntry in project drools by kiegroup.
the class SwitchEntryT method toJavaExpression.
@Override
public Node toJavaExpression() {
SwitchEntry entry = new SwitchEntry();
entry.setLabels(labels);
entry.setStatements(NodeList.nodeList(statements.stream().map(TypedExpression::toJavaExpression).map(Statement.class::cast).collect(Collectors.toList())));
return entry;
}
use of com.github.javaparser.ast.stmt.SwitchEntry in project drools by kiegroup.
the class AccessibleMethod method getterSwitchStatement.
private Statement getterSwitchStatement() {
SwitchStmt switchStmt = switchOnFieldName();
NodeList<SwitchEntry> switchEntries = switchStmt.getEntries();
for (DescrFieldDefinition field : fields) {
if (!field.isOverride()) {
switchEntries.add(getValueFromField(field));
}
}
Optional<Class<?>> abstractResolvedClass = descrTypeDefinition.getAbstractResolvedClass();
if (abstractResolvedClass.isPresent()) {
switchEntries.addAll(superClassGetterEntries(abstractResolvedClass.get()).collect(toList()));
} else if (descrTypeDefinition.getDeclaredAbstractClass().isPresent()) {
switchEntries.add(switchEntry(SUPER_GET_VALUE));
} else {
switchEntries.add(switchEntry(RETURN_NULL));
}
return new BlockStmt(nodeList(switchStmt));
}
Aggregations