use of com.github.javaparser.ast.expr.ObjectCreationExpr in project drools by kiegroup.
the class Functions method internal.
public static ObjectCreationExpr internal(Expression parameters, Expression body) {
ObjectCreationExpr functionDefExpr = new ObjectCreationExpr();
functionDefExpr.setType(TYPE_CUSTOM_FEEL_FUNCTION);
functionDefExpr.addArgument(ANONYMOUS_STRING_LITERAL);
functionDefExpr.addArgument(parameters);
functionDefExpr.addArgument(body);
functionDefExpr.addArgument(new MethodCallExpr(new NameExpr("feelExprCtx"), "current"));
return functionDefExpr;
}
use of com.github.javaparser.ast.expr.ObjectCreationExpr in project drools by kiegroup.
the class KiePMMLModelFactoryUtils method populateGetCreatedMiningFieldsMethod.
/**
* Populate the <code>getCreatedKiePMMLMiningFields</code> method
* @param modelTemplate
* @param miningFields
*/
public static void populateGetCreatedMiningFieldsMethod(final ClassOrInterfaceDeclaration modelTemplate, final List<MiningField> miningFields) {
final MethodDeclaration methodDeclaration = modelTemplate.getMethodsByName(GET_CREATED_MININGFIELDS).get(0);
final List<ObjectCreationExpr> miningFieldsObjectCreations = getMiningFieldsObjectCreations(miningFields);
populateListInListGetter(miningFieldsObjectCreations, methodDeclaration, TO_RETURN);
}
use of com.github.javaparser.ast.expr.ObjectCreationExpr in project drools by kiegroup.
the class KiePMMLConstantFactory method getConstantVariableDeclaration.
static BlockStmt getConstantVariableDeclaration(final String variableName, final Constant constant) {
final MethodDeclaration methodDeclaration = CONSTANT_TEMPLATE.getMethodsByName(GETKIEPMMLCONSTANT).get(0).clone();
final BlockStmt toReturn = methodDeclaration.getBody().orElseThrow(() -> new KiePMMLException(String.format(MISSING_BODY_TEMPLATE, methodDeclaration)));
final VariableDeclarator variableDeclarator = getVariableDeclarator(toReturn, CONSTANT).orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_IN_BODY, CONSTANT, toReturn)));
variableDeclarator.setName(variableName);
final ObjectCreationExpr objectCreationExpr = variableDeclarator.getInitializer().orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_INITIALIZER_TEMPLATE, CONSTANT, toReturn))).asObjectCreationExpr();
final StringLiteralExpr nameExpr = new StringLiteralExpr(variableName);
final Expression valueExpr = getExpressionForObject(constant.getValue());
final Expression dataTypeExpression = getExpressionForDataType(constant.getDataType());
objectCreationExpr.getArguments().set(0, nameExpr);
objectCreationExpr.getArguments().set(2, valueExpr);
objectCreationExpr.getArguments().set(3, dataTypeExpression);
return toReturn;
}
use of com.github.javaparser.ast.expr.ObjectCreationExpr in project drools by kiegroup.
the class KiePMMLDiscretizeFactory method getDiscretizeVariableDeclaration.
static BlockStmt getDiscretizeVariableDeclaration(final String variableName, final Discretize discretize) {
final MethodDeclaration methodDeclaration = DISCRETIZE_TEMPLATE.getMethodsByName(GETKIEPMMLDISCRETIZE).get(0).clone();
final BlockStmt discretizeBody = methodDeclaration.getBody().orElseThrow(() -> new KiePMMLException(String.format(MISSING_BODY_TEMPLATE, methodDeclaration)));
final VariableDeclarator variableDeclarator = getVariableDeclarator(discretizeBody, DISCRETIZE).orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_IN_BODY, DISCRETIZE, discretizeBody)));
variableDeclarator.setName(variableName);
final BlockStmt toReturn = new BlockStmt();
int counter = 0;
final NodeList<Expression> arguments = new NodeList<>();
for (DiscretizeBin discretizeBin : discretize.getDiscretizeBins()) {
String nestedVariableName = String.format(VARIABLE_NAME_TEMPLATE, variableName, counter);
arguments.add(new NameExpr(nestedVariableName));
BlockStmt toAdd = getDiscretizeBinVariableDeclaration(nestedVariableName, discretizeBin);
toAdd.getStatements().forEach(toReturn::addStatement);
counter++;
}
final ObjectCreationExpr objectCreationExpr = variableDeclarator.getInitializer().orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_INITIALIZER_TEMPLATE, DISCRETIZE, toReturn))).asObjectCreationExpr();
final Expression nameExpr = new StringLiteralExpr(discretize.getField().getValue());
final Expression mapMissingToExpr = getExpressionForObject(discretize.getMapMissingTo());
final Expression defaultValueExpr = getExpressionForObject(discretize.getDefaultValue());
final Expression dataTypeExpression = getExpressionForDataType(discretize.getDataType());
objectCreationExpr.getArguments().set(0, nameExpr);
objectCreationExpr.getArguments().get(2).asMethodCallExpr().setArguments(arguments);
objectCreationExpr.getArguments().set(3, mapMissingToExpr);
objectCreationExpr.getArguments().set(4, defaultValueExpr);
objectCreationExpr.getArguments().set(5, dataTypeExpression);
discretizeBody.getStatements().forEach(toReturn::addStatement);
return toReturn;
}
use of com.github.javaparser.ast.expr.ObjectCreationExpr in project drools by kiegroup.
the class KiePMMLFalsePredicateFactory method getFalsePredicateVariableDeclaration.
static BlockStmt getFalsePredicateVariableDeclaration(final String variableName, final False falsePredicate) {
final MethodDeclaration methodDeclaration = FALSEPREDICATE_TEMPLATE.getMethodsByName(GETKIEPMMLFALSEPREDICATE).get(0).clone();
final BlockStmt toReturn = methodDeclaration.getBody().orElseThrow(() -> new KiePMMLException(String.format(MISSING_BODY_TEMPLATE, methodDeclaration)));
final VariableDeclarator variableDeclarator = getVariableDeclarator(toReturn, FALSEPREDICATE).orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_IN_BODY, FALSEPREDICATE, toReturn)));
variableDeclarator.setName(variableName);
final ObjectCreationExpr objectCreationExpr = variableDeclarator.getInitializer().orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_INITIALIZER_TEMPLATE, FALSEPREDICATE, toReturn))).asObjectCreationExpr();
final StringLiteralExpr nameExpr = new StringLiteralExpr(variableName);
objectCreationExpr.getArguments().set(0, nameExpr);
return toReturn;
}
Aggregations