Search in sources :

Example 21 with ObjectCreationExpr

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());
}
Also used : ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr)

Example 22 with ObjectCreationExpr

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);
}
Also used : ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) KiePMMLTargetValue(org.kie.pmml.commons.model.KiePMMLTargetValue) ModelUtils.convertToKieTargetValue(org.kie.pmml.compiler.api.utils.ModelUtils.convertToKieTargetValue) PMMLModelTestUtils.getRandomTargetValue(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomTargetValue) TargetValue(org.kie.pmml.api.models.TargetValue) Expression(com.github.javaparser.ast.expr.Expression) Test(org.junit.Test)

Example 23 with ObjectCreationExpr

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);
}
Also used : ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) Expression(com.github.javaparser.ast.expr.Expression) NodeList(com.github.javaparser.ast.NodeList) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType)

Example 24 with ObjectCreationExpr

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&lt;String, KiePMMLOriginalTypeGeneratedType&gt;</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));
    }
}
Also used : ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) Expression(com.github.javaparser.ast.expr.Expression) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) NameExpr(com.github.javaparser.ast.expr.NameExpr) Map(java.util.Map) KiePMMLOriginalTypeGeneratedType(org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Example 25 with ObjectCreationExpr

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;
}
Also used : ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) Expression(com.github.javaparser.ast.expr.Expression)

Aggregations

ObjectCreationExpr (com.github.javaparser.ast.expr.ObjectCreationExpr)83 Expression (com.github.javaparser.ast.expr.Expression)59 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)44 NameExpr (com.github.javaparser.ast.expr.NameExpr)41 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)38 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)31 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)30 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)30 NodeList (com.github.javaparser.ast.NodeList)24 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)24 KiePMMLException (org.kie.pmml.api.exceptions.KiePMMLException)21 CommonCodegenUtils.getVariableDeclarator (org.kie.pmml.compiler.commons.utils.CommonCodegenUtils.getVariableDeclarator)19 NullLiteralExpr (com.github.javaparser.ast.expr.NullLiteralExpr)14 List (java.util.List)13 ReturnStmt (com.github.javaparser.ast.stmt.ReturnStmt)12 Type (com.github.javaparser.ast.type.Type)12 Test (org.junit.Test)12 StaticJavaParser.parseClassOrInterfaceType (com.github.javaparser.StaticJavaParser.parseClassOrInterfaceType)11 DrlxParseUtil.toClassOrInterfaceType (org.drools.modelcompiler.builder.generator.DrlxParseUtil.toClassOrInterfaceType)11 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)10