KiePMMLSegmentFactory { static void setConstructor(final String segmentName, final String generatedClassName, final ConstructorDeclaration constructorDeclaration, final String predicateClassName, final String kiePMMLModelClass, final double weight) { setConstructorSuperNameInvocation(generatedClassName, constructorDeclaration, segmentName); final BlockStmt body = constructorDeclaration.getBody(); final ExplicitConstructorInvocationStmt superStatement = CommonCodegenUtils.getExplicitConstructorInvocationStmt(body) .orElseThrow(() -> new KiePMMLException(String.format(MISSING_CONSTRUCTOR_IN_BODY, body))); ClassOrInterfaceType classOrInterfaceType = parseClassOrInterfaceType(predicateClassName); ObjectCreationExpr objectCreationExpr = new ObjectCreationExpr(); objectCreationExpr.setType(classOrInterfaceType); CommonCodegenUtils.setExplicitConstructorInvocationArgument(superStatement, "kiePMMLPredicate", objectCreationExpr.toString()); classOrInterfaceType = parseClassOrInterfaceType(kiePMMLModelClass); objectCreationExpr = new ObjectCreationExpr(); objectCreationExpr.setType(classOrInterfaceType); CommonCodegenUtils.setExplicitConstructorInvocationArgument(superStatement, "model", objectCreationExpr.toString()); CommonCodegenUtils.setAssignExpressionValue(body, "weight", new DoubleLiteralExpr(weight)); CommonCodegenUtils.setAssignExpressionValue(body, "id", new StringLiteralExpr(segmentName)); } private  KiePMMLSegmentFactory(); static List<KiePMMLSegment> getSegments(final DataDictionary dataDictionary,
                                                   final TransformationDictionary transformationDictionary,
                                                   final List<Segment> segments,
                                                   final KnowledgeBuilder kBuilder); static KiePMMLSegment getSegment(final DataDictionary dataDictionary,
                                            final TransformationDictionary transformationDictionary,
                                            final Segment segment,
                                            final KnowledgeBuilder kBuilder); static Map<String, String> getSegmentsSourcesMap(final String parentPackageName,
                                                            final DataDictionary dataDictionary,
                                                            final TransformationDictionary transformationDictionary,
                                                            final List<Segment> segments,
                                                            final KnowledgeBuilder kBuilder,
                                                            final List<KiePMMLModel> nestedModels); static Map<String, String> getSegmentSourcesMap(
            final String parentPackageName,
            final DataDictionary dataDictionary,
            final TransformationDictionary transformationDictionary,
            final Segment segment,
            final KnowledgeBuilder kBuilder,
            final List<KiePMMLModel> nestedModels); static Map<String, String> getSegmentSourcesMap(
            final String packageName,
            final DataDictionary dataDictionary,
            final Segment segment);  }
@Test public void setConstructor() { ConstructorDeclaration constructorDeclaration = MODEL_TEMPLATE.getDefaultConstructor().get(); String segmentName = "SEGMENTNAME"; String generatedClassName = "GENERATEDCLASSNAME"; String predicateClassName = "PREDICATECLASSNAME"; String kiePMMLModelClass = "KIEPMMLMODELCLASS"; double weight = 12.22; KiePMMLSegmentFactory.setConstructor(segmentName, generatedClassName, constructorDeclaration, predicateClassName, kiePMMLModelClass, weight); Map<Integer, Expression> superInvocationExpressionsMap = new HashMap<>(); superInvocationExpressionsMap.put(0, new NameExpr(String.format("\"%s\"", segmentName))); ClassOrInterfaceType classOrInterfaceType = parseClassOrInterfaceType(predicateClassName); ObjectCreationExpr objectCreationExpr = new ObjectCreationExpr(); objectCreationExpr.setType(classOrInterfaceType); superInvocationExpressionsMap.put(2, new NameExpr(objectCreationExpr.toString())); classOrInterfaceType = parseClassOrInterfaceType(kiePMMLModelClass); objectCreationExpr = new ObjectCreationExpr(); objectCreationExpr.setType(classOrInterfaceType); superInvocationExpressionsMap.put(3, new NameExpr(objectCreationExpr.toString())); Map<String, Expression> assignExpressionMap = new HashMap<>(); assignExpressionMap.put("weight", new DoubleLiteralExpr(weight)); assignExpressionMap.put("id", new StringLiteralExpr(segmentName)); assertTrue(commonEvaluateConstructor(constructorDeclaration, generatedClassName, superInvocationExpressionsMap, assignExpressionMap)); }