Search in sources :

Example 1 with CLOSURE

use of org.kie.pmml.api.enums.CLOSURE in project drools by kiegroup.

the class KiePMMLIntervalFactory method getIntervalVariableDeclaration.

static BlockStmt getIntervalVariableDeclaration(final String variableName, final Interval interval) {
    final MethodDeclaration methodDeclaration = INTERVAL_TEMPLATE.getMethodsByName(GETKIEPMMLINTERVAL).get(0).clone();
    final BlockStmt toReturn = methodDeclaration.getBody().orElseThrow(() -> new KiePMMLException(String.format(MISSING_BODY_TEMPLATE, methodDeclaration)));
    final VariableDeclarator variableDeclarator = getVariableDeclarator(toReturn, INTERVAL).orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_IN_BODY, INTERVAL, toReturn)));
    variableDeclarator.setName(variableName);
    final ObjectCreationExpr objectCreationExpr = variableDeclarator.getInitializer().orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_INITIALIZER_TEMPLATE, INTERVAL, toReturn))).asObjectCreationExpr();
    final Expression leftMarginExpr = getExpressionForObject(interval.getLeftMargin());
    final Expression rightMarginExpr = getExpressionForObject(interval.getRightMargin());
    final CLOSURE closure = CLOSURE.byName(interval.getClosure().value());
    final NameExpr closureExpr = new NameExpr(CLOSURE.class.getName() + "." + closure.name());
    objectCreationExpr.getArguments().set(0, leftMarginExpr);
    objectCreationExpr.getArguments().set(1, rightMarginExpr);
    objectCreationExpr.getArguments().set(2, closureExpr);
    return toReturn;
}
Also used : ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) Expression(com.github.javaparser.ast.expr.Expression) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) NameExpr(com.github.javaparser.ast.expr.NameExpr) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) CLOSURE(org.kie.pmml.api.enums.CLOSURE) CommonCodegenUtils.getVariableDeclarator(org.kie.pmml.compiler.commons.utils.CommonCodegenUtils.getVariableDeclarator) VariableDeclarator(com.github.javaparser.ast.body.VariableDeclarator)

Aggregations

MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)1 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)1 Expression (com.github.javaparser.ast.expr.Expression)1 NameExpr (com.github.javaparser.ast.expr.NameExpr)1 ObjectCreationExpr (com.github.javaparser.ast.expr.ObjectCreationExpr)1 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)1 CLOSURE (org.kie.pmml.api.enums.CLOSURE)1 KiePMMLException (org.kie.pmml.api.exceptions.KiePMMLException)1 CommonCodegenUtils.getVariableDeclarator (org.kie.pmml.compiler.commons.utils.CommonCodegenUtils.getVariableDeclarator)1