CommonCodegenUtils { public static MethodDeclaration getMethodDeclaration(final String methodName, final Map<String, ClassOrInterfaceType> parameterNameTypeMap) { MethodDeclaration toReturn = getMethodDeclaration(methodName); NodeList<Parameter> typeParameters = new NodeList<>(); parameterNameTypeMap.forEach((parameterName, classOrInterfaceType) -> { Parameter toAdd = new Parameter(); toAdd.setName(parameterName); toAdd.setType(classOrInterfaceType); typeParameters.add(toAdd); }); toReturn.setParameters(typeParameters); return toReturn; } private  CommonCodegenUtils(); static void populateMethodDeclarations(final ClassOrInterfaceDeclaration toPopulate,
                                                  final Collection<MethodDeclaration> methodDeclarations); static ExpressionStmt getFilteredKiePMMLNameValueExpression(final String kiePMMLNameValueListParam,
                                                                       final String fieldNameToRef,
                                                                       boolean stringLiteralComparison); static void addMapPopulation(final Map<String, MethodDeclaration> toAdd,
                                        final BlockStmt body,
                                        final String mapName); static MethodDeclaration getMethodDeclaration(final String methodName,
                                                         final Map<String, ClassOrInterfaceType> parameterNameTypeMap); static MethodDeclaration getMethodDeclaration(final String methodName); static ReturnStmt getReturnStmt(final String returnedVariableName); static ClassOrInterfaceType getTypedClassOrInterfaceType(final String className,
                                                                    final List<String> typesName ); static void setAssignExpressionValue( final BlockStmt body, final String assignExpressionName, final Expression value); static Optional<AssignExpr> getAssignExpression(final BlockStmt body, final String assignExpressionName); static Optional<ExplicitConstructorInvocationStmt> getExplicitConstructorInvocationStmt(final BlockStmt body); static void setExplicitConstructorInvocationArgument(final ExplicitConstructorInvocationStmt constructorInvocationStmt, final String parameterName, final String value); static Optional<NameExpr> getExplicitConstructorInvocationParameter(final ExplicitConstructorInvocationStmt constructorInvocationStmt, final String parameterName); static Optional<MethodDeclaration> getMethodDeclaration(final ClassOrInterfaceDeclaration classOrInterfaceDeclaration, final String methodName); static MethodDeclaration addMethod(final MethodDeclaration methodTemplate,
                                                 final ClassOrInterfaceDeclaration tableTemplate,
                                                 final String methodName); static Optional<VariableDeclarator> getVariableDeclarator(final BlockStmt body, final String variableName); static String OPTIONAL_FILTERED_KIEPMMLNAMEVALUE_NAME; }
@Test public void getParamMethodDeclaration() { String methodName = "METHOD_NAME"; final Map<String, ClassOrInterfaceType> parameterNameTypeMap = new HashMap<>(); parameterNameTypeMap.put("stringParam", parseClassOrInterfaceType(String.class.getName())); parameterNameTypeMap.put("kiePMMLNameValueParam", parseClassOrInterfaceType(KiePMMLNameValue.class.getName())); parameterNameTypeMap.put("listParam", new ClassOrInterfaceType(null, new SimpleName(List.class.getName()), NodeList.nodeList(parseClassOrInterfaceType(KiePMMLNameValue.class.getName())))); MethodDeclaration retrieved = CommonCodegenUtils.getMethodDeclaration(methodName, parameterNameTypeMap); commonValidateMethodDeclaration(retrieved, methodName); commonValidateMethodDeclarationParams(retrieved, parameterNameTypeMap); }
@Test public void getNoParamMethodDeclarationByString() { String methodName = "METHOD_NAME"; MethodDeclaration retrieved = CommonCodegenUtils.getMethodDeclaration(methodName); commonValidateMethodDeclaration(retrieved, methodName); }
@Test public void getMethodDeclaration() { final String methodName = "METHOD_NAME"; final ClassOrInterfaceDeclaration classOrInterfaceDeclaration = new ClassOrInterfaceDeclaration(); assertFalse(CommonCodegenUtils.getMethodDeclaration(classOrInterfaceDeclaration, methodName).isPresent()); classOrInterfaceDeclaration.addMethod("NOT_METHOD"); assertFalse(CommonCodegenUtils.getMethodDeclaration(classOrInterfaceDeclaration, methodName).isPresent()); classOrInterfaceDeclaration.addMethod(methodName); assertTrue(CommonCodegenUtils.getMethodDeclaration(classOrInterfaceDeclaration, methodName).isPresent()); }