use of com.github.javaparser.ast.expr.ObjectCreationExpr in project drools by kiegroup.
the class KiePMMLModelFactoryUtils method setKiePMMLModelConstructor.
/**
* Set the <b>name</b> parameter on <b>super</b> invocation and populate the <b>miningFields/outputFields</b>
* @param generatedClassName
* @param constructorDeclaration
* @param name
* @param miningFields
* @param outputFields
* @param targetFields
*/
public static void setKiePMMLModelConstructor(final String generatedClassName, final ConstructorDeclaration constructorDeclaration, final String name, final List<MiningField> miningFields, final List<OutputField> outputFields, final List<TargetField> targetFields) {
setConstructorSuperNameInvocation(generatedClassName, constructorDeclaration, name);
final BlockStmt body = constructorDeclaration.getBody();
final List<ObjectCreationExpr> miningFieldsObjectCreations = getMiningFieldsObjectCreations(miningFields);
addListPopulationByObjectCreationExpr(miningFieldsObjectCreations, body, "miningFields");
final List<ObjectCreationExpr> outputFieldsObjectCreations = getOutputFieldsObjectCreations(outputFields);
addListPopulationByObjectCreationExpr(outputFieldsObjectCreations, body, "outputFields");
final List<MethodCallExpr> kiePMMLTargetFieldsObjectCreations = getKiePMMLTargetFieldsObjectCreations(targetFields);
addListPopulationByMethodCallExpr(kiePMMLTargetFieldsObjectCreations, body, "kiePMMLTargets");
}
use of com.github.javaparser.ast.expr.ObjectCreationExpr in project drools by kiegroup.
the class KiePMMLModelFactoryUtils method getObjectCreationExprFromInterval.
static ObjectCreationExpr getObjectCreationExprFromInterval(Interval source) {
ObjectCreationExpr toReturn = new ObjectCreationExpr();
toReturn.setType(Interval.class.getCanonicalName());
NodeList<Expression> arguments = new NodeList<>();
if (source.getLeftMargin() != null) {
arguments.add(new NameExpr(source.getLeftMargin().toString()));
} else {
arguments.add(new NullLiteralExpr());
}
if (source.getRightMargin() != null) {
arguments.add(new NameExpr(source.getRightMargin().toString()));
} else {
arguments.add(new NullLiteralExpr());
}
toReturn.setArguments(arguments);
return toReturn;
}
use of com.github.javaparser.ast.expr.ObjectCreationExpr in project drools by kiegroup.
the class KiePMMLFieldRefFactory method getFieldRefVariableDeclaration.
static BlockStmt getFieldRefVariableDeclaration(final String variableName, final FieldRef fieldRef) {
final MethodDeclaration methodDeclaration = FIELDREF_TEMPLATE.getMethodsByName(GETKIEPMMLFIELDREF).get(0).clone();
final BlockStmt toReturn = methodDeclaration.getBody().orElseThrow(() -> new KiePMMLException(String.format(MISSING_BODY_TEMPLATE, methodDeclaration)));
final VariableDeclarator variableDeclarator = getVariableDeclarator(toReturn, FIELD_REF).orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_IN_BODY, FIELD_REF, toReturn)));
variableDeclarator.setName(variableName);
final ObjectCreationExpr objectCreationExpr = variableDeclarator.getInitializer().orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_INITIALIZER_TEMPLATE, FIELD_REF, toReturn))).asObjectCreationExpr();
final StringLiteralExpr nameExpr = new StringLiteralExpr(fieldRef.getField().getValue());
final Expression mapMissingToExpr = getExpressionForObject(fieldRef.getMapMissingTo());
objectCreationExpr.getArguments().set(0, nameExpr);
objectCreationExpr.getArguments().set(2, mapMissingToExpr);
return toReturn;
}
use of com.github.javaparser.ast.expr.ObjectCreationExpr 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;
}
use of com.github.javaparser.ast.expr.ObjectCreationExpr in project drools by kiegroup.
the class TargetValueFactory method getTargetValueVariableInitializer.
static ObjectCreationExpr getTargetValueVariableInitializer(final TargetValue targetValueField) {
final MethodDeclaration methodDeclaration = TARGETVALUE_TEMPLATE.getMethodsByName(GETTARGETVALUE).get(0).clone();
final BlockStmt targetValueBody = methodDeclaration.getBody().orElseThrow(() -> new KiePMMLException(String.format(MISSING_BODY_TEMPLATE, methodDeclaration)));
final VariableDeclarator variableDeclarator = getVariableDeclarator(targetValueBody, TARGETVALUE).orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_IN_BODY, TARGETVALUE, targetValueBody)));
final ObjectCreationExpr toReturn = variableDeclarator.getInitializer().orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_INITIALIZER_TEMPLATE, TARGETVALUE, targetValueBody))).asObjectCreationExpr();
toReturn.setArgument(0, getExpressionForObject(targetValueField.getValue()));
toReturn.setArgument(1, getExpressionForObject(targetValueField.getDisplayValue()));
toReturn.setArgument(2, getExpressionForObject(targetValueField.getPriorProbability()));
toReturn.setArgument(3, getExpressionForObject(targetValueField.getDefaultValue()));
return toReturn;
}
Aggregations