use of com.github.javaparser.ast.expr.ObjectCreationExpr in project drools by kiegroup.
the class KiePMMLFactoryFactoryTest method validateCodegen.
private void validateCodegen(Expression toValidate, String kiePMMLModelClass) {
assertNotNull(toValidate);
assertTrue(toValidate instanceof ObjectCreationExpr);
ObjectCreationExpr objectCreationExpr = (ObjectCreationExpr) toValidate;
assertEquals(kiePMMLModelClass, objectCreationExpr.getType().asString());
}
use of com.github.javaparser.ast.expr.ObjectCreationExpr in project drools by kiegroup.
the class TargetValueFactoryTest method getTargetValueVariableInitializer.
@Test
public void getTargetValueVariableInitializer() throws IOException {
TargetValue targetValue = convertToKieTargetValue(getRandomTargetValue());
ObjectCreationExpr retrieved = TargetValueFactory.getTargetValueVariableInitializer(targetValue);
String text = getFileContent(TEST_01_SOURCE);
Expression expected = JavaParserUtils.parseExpression(String.format(text, targetValue.getValue(), targetValue.getDisplayValue(), targetValue.getPriorProbability(), targetValue.getDefaultValue()));
assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
List<Class<?>> imports = Arrays.asList(Arrays.class, Collections.class, KiePMMLTargetValue.class, TargetValue.class);
commonValidateCompilationWithImports(retrieved, imports);
}
use of com.github.javaparser.ast.expr.ObjectCreationExpr in project drools by kiegroup.
the class KiePMMLClusteringModelFactory method comparisonMeasureCreationExprFrom.
private static ObjectCreationExpr comparisonMeasureCreationExprFrom(ComparisonMeasure comparisonMeasure) {
NodeList<Expression> arguments = new NodeList<>();
arguments.add(literalExprFrom(comparisonMeasureKindFrom(comparisonMeasure.getKind())));
arguments.add(literalExprFrom(aggregateFunctionFrom(comparisonMeasure.getMeasure())));
arguments.add(literalExprFrom(compareFunctionFrom(comparisonMeasure.getCompareFunction())));
return new ObjectCreationExpr(null, new ClassOrInterfaceType(null, KiePMMLComparisonMeasure.class.getCanonicalName()), arguments);
}
use of com.github.javaparser.ast.expr.ObjectCreationExpr in project drools by kiegroup.
the class KiePMMLDroolsModelFactoryUtils method addFieldTypeMapPopulation.
/**
* Populate the <b>fieldTypeMap</b> <code>Map<String, KiePMMLOriginalTypeGeneratedType></code>
* @param body
* @param fieldTypeMap
*/
static void addFieldTypeMapPopulation(BlockStmt body, Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap) {
for (Map.Entry<String, KiePMMLOriginalTypeGeneratedType> entry : fieldTypeMap.entrySet()) {
KiePMMLOriginalTypeGeneratedType kiePMMLOriginalTypeGeneratedType = entry.getValue();
NodeList<Expression> expressions = NodeList.nodeList(new StringLiteralExpr(kiePMMLOriginalTypeGeneratedType.getOriginalType()), new StringLiteralExpr(kiePMMLOriginalTypeGeneratedType.getGeneratedType()));
ObjectCreationExpr objectCreationExpr = new ObjectCreationExpr();
objectCreationExpr.setType(KiePMMLOriginalTypeGeneratedType.class.getName());
objectCreationExpr.setArguments(expressions);
expressions = NodeList.nodeList(new StringLiteralExpr(entry.getKey()), objectCreationExpr);
body.addStatement(new MethodCallExpr(new NameExpr("fieldTypeMap"), "put", expressions));
}
}
use of com.github.javaparser.ast.expr.ObjectCreationExpr in project drools by kiegroup.
the class KiePMMLDroolsModelFactoryUtilsTest method evaluateFieldTypeMapPopulation.
private boolean evaluateFieldTypeMapPopulation(Map.Entry<String, KiePMMLOriginalTypeGeneratedType> entry, NodeList<Expression> arguments) {
boolean toReturn = arguments.size() == 2;
Expression firstArgument = arguments.get(0);
Expression secondArgument = arguments.get(1);
toReturn &= firstArgument.isStringLiteralExpr() && ((StringLiteralExpr) firstArgument).getValue().equals(entry.getKey());
toReturn &= secondArgument.isObjectCreationExpr() && ((ObjectCreationExpr) secondArgument).getArgument(0).isStringLiteralExpr() && ((StringLiteralExpr) ((ObjectCreationExpr) secondArgument).getArgument(0)).getValue().equals(entry.getValue().getOriginalType()) && ((ObjectCreationExpr) secondArgument).getArgument(1).isStringLiteralExpr() && ((StringLiteralExpr) ((ObjectCreationExpr) secondArgument).getArgument(1)).getValue().equals(entry.getValue().getGeneratedType());
return toReturn;
}
Aggregations