Class CommonCodegenUtils

java.lang.Object
org.kie.pmml.compiler.commons.utils.CommonCodegenUtils

public class CommonCodegenUtils extends Object
Class meant to provide helper methods to all code-generating classes
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static String
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    addListPopulationByMethodCallExpr(List<com.github.javaparser.ast.expr.MethodCallExpr> toAdd, com.github.javaparser.ast.stmt.BlockStmt body, String listName)
    For every entry in the given list, add
    static void
    addListPopulationByObjectCreationExpr(List<com.github.javaparser.ast.expr.ObjectCreationExpr> toAdd, com.github.javaparser.ast.stmt.BlockStmt body, String listName)
    For every entry in the given list, add
    static void
    addMapPopulation(Map<String,com.github.javaparser.ast.body.MethodDeclaration> toAdd, com.github.javaparser.ast.stmt.BlockStmt body, String mapName)
    For every entry in the given map, add
    static void
    addMapPopulationExpressions(Map<String,com.github.javaparser.ast.expr.Expression> toAdd, com.github.javaparser.ast.stmt.BlockStmt body, String mapName)
    For every entry in the given map, add a "put" statement to the provided BlockStmt body.
    static com.github.javaparser.ast.body.MethodDeclaration
    addMethod(com.github.javaparser.ast.body.MethodDeclaration methodTemplate, com.github.javaparser.ast.body.ClassOrInterfaceDeclaration tableTemplate, String methodName)
    Add a MethodDeclaration to the class
    static void
    addMethodDeclarationsToClass(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration classOrInterfaceDeclaration, List<com.github.javaparser.ast.body.MethodDeclaration> toAdd)
    Add a MethodDeclarations to the given ClassOrInterfaceDeclaration
    static void
    addMethodDeclarationToClass(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration classOrInterfaceDeclaration, com.github.javaparser.ast.body.MethodDeclaration toAdd)
    Add a MethodDeclaration to the given ClassOrInterfaceDeclaration
    static com.github.javaparser.ast.expr.AssignExpr
    assignExprFrom(String target, com.github.javaparser.ast.expr.Expression value)
    Return a new AssignExpr from a target name and a generic Expression.
    static com.github.javaparser.ast.expr.AssignExpr
    assignExprFrom(String target, Enum<?> value)
    Return a new AssignExpr from a target name and an enum literal.
    static com.github.javaparser.ast.expr.AssignExpr
    assignExprFrom(String target, String value)
    Return a new AssignExpr from a target name and String literal.
    static com.github.javaparser.ast.stmt.ExpressionStmt
    Create an empty Arrays.asList() ExpressionStmt
    static com.github.javaparser.ast.stmt.ExpressionStmt
    Create a populated Arrays.asList(?...
    static void
    createHashMap(com.github.javaparser.ast.stmt.BlockStmt body, String mapName, List<String> mapTypes)
    Declare and initialize a new Map in the given BlockStmt
    static void
    createLinkedHashMap(com.github.javaparser.ast.stmt.BlockStmt body, String mapName, List<String> mapTypes)
    Declare and initialize a new LinkedHashMap in the given BlockStmt
    static void
    createPopulatedHashMap(com.github.javaparser.ast.stmt.BlockStmt body, String mapName, List<String> mapTypes, Map<String,com.github.javaparser.ast.expr.Expression> toAdd)
    Declare, initialize and populate a new HashMap in the given BlockStmt
    static void
    createPopulatedLinkedHashMap(com.github.javaparser.ast.stmt.BlockStmt body, String mapName, List<String> mapTypes, Map<String,com.github.javaparser.ast.expr.Expression> toAdd)
    Declare, initialize and populate a new LinkedHashMap in the given BlockStmt
    static com.github.javaparser.ast.NodeList<com.github.javaparser.ast.expr.Expression>
    getArraysAsListInvocation(com.github.javaparser.ast.NodeList<com.github.javaparser.ast.expr.Expression> arguments)
     
    static com.github.javaparser.ast.expr.MethodCallExpr
    getArraysAsListInvocationMethodCall(com.github.javaparser.ast.NodeList<com.github.javaparser.ast.expr.Expression> arguments)
     
    static Optional<com.github.javaparser.ast.expr.AssignExpr>
    getAssignExpression(com.github.javaparser.ast.stmt.BlockStmt body, String assignExpressionName)
    Return an Optional<AssignExpr> with the given assignExpressionName from the given BlockStmt
    static com.github.javaparser.ast.expr.MethodCallExpr
    getChainedMethodCallExprFrom(String name, com.github.javaparser.ast.expr.MethodCallExpr parent)
    Return a "chained" MethodCallExpr by name parent one.
    static Optional<com.github.javaparser.ast.expr.MethodReferenceExpr>
    getExplicitConstructorInvocationMethodReference(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt constructorInvocationStmt, String typeName)
    Return an Optional<MethodReferenceExpr> from the given ExplicitConstructorInvocationStmt
    static Optional<com.github.javaparser.ast.expr.NameExpr>
    getExplicitConstructorInvocationParameter(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt constructorInvocationStmt, String parameterName)
    Return an Optional<NameExpr> from the given ExplicitConstructorInvocationStmt
    static Optional<com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt>
    getExplicitConstructorInvocationStmt(com.github.javaparser.ast.stmt.BlockStmt body)
    Return an Optional<ExplicitConstructorInvocationStmt> from the given BlockStmt
    static com.github.javaparser.ast.expr.Expression
    getExpressionForDataType(org.dmg.pmml.DataType dataTypeParam)
     
    static com.github.javaparser.ast.expr.Expression
     
    static com.github.javaparser.ast.expr.Expression
    getExpressionForOpType(org.dmg.pmml.OpType opTypeParam)
     
    static com.github.javaparser.ast.stmt.ExpressionStmt
    getFilteredKiePMMLNameValueExpression(String kiePMMLNameValueListParam, String fieldNameToRef, boolean stringLiteralComparison)
    Returns
    static com.github.javaparser.ast.stmt.BlockStmt
    getInitializerBlockStmt(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration classOrInterfaceDeclaration)
    Return an BlockStmt from the given ClassOrInterfaceDeclaration
    static com.github.javaparser.ast.body.InitializerDeclaration
    getInitializerDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration classOrInterfaceDeclaration)
    Return an InitializerDeclaration from the given ClassOrInterfaceDeclaration
    static Optional<com.github.javaparser.ast.body.MethodDeclaration>
    getMethodDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration classOrInterfaceDeclaration, String methodName)
    Return an Optional<MethodDeclaration> with the first method methodName from the given ClassOrInterfaceDeclaration
    static com.github.javaparser.ast.body.MethodDeclaration
    Returns
    static com.github.javaparser.ast.body.MethodDeclaration
    getMethodDeclaration(String methodName, Map<String,com.github.javaparser.ast.type.ClassOrInterfaceType> parameterNameTypeMap)
    Returns
    static com.github.javaparser.ast.stmt.BlockStmt
    getMethodDeclarationBlockStmt(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration classOrInterfaceDeclaration, String methodName)
    Return an BlockStmt for the method methodName from the given ClassOrInterfaceDeclaration
    static List<com.github.javaparser.ast.expr.NameExpr>
    getNameExprsFromBlock(com.github.javaparser.ast.stmt.BlockStmt toRead, String exprName)
    Return a lit<NameExpr> with all the instances of the given exprName
    static Optional<com.github.javaparser.ast.expr.Expression>
    getOptionalVariableInitializer(com.github.javaparser.ast.body.MethodDeclaration methodDeclaration, String variableName)
    Retrieve the initializer of the given variableName from the given MethodDeclaration
    static com.github.javaparser.ast.stmt.ReturnStmt
    getReturnStmt(String returnedVariableName)
    Returns
    static com.github.javaparser.ast.type.ClassOrInterfaceType
    Returns
    static com.github.javaparser.ast.type.ClassOrInterfaceType
    getTypedClassOrInterfaceTypeByTypes(String className, List<com.github.javaparser.ast.type.Type> types)
    Returns
    static Optional<com.github.javaparser.ast.body.VariableDeclarator>
    getVariableDeclarator(com.github.javaparser.ast.body.MethodDeclaration methodDeclaration, String variableName)
    Return an Optional<VariableDeclarator> with the first variable variableName from the given MethodDeclaration
    static Optional<com.github.javaparser.ast.body.VariableDeclarator>
    getVariableDeclarator(com.github.javaparser.ast.stmt.BlockStmt body, String variableName)
    Return an Optional<VariableDeclarator> with the first variable variableName from the given BlockStmt
    static com.github.javaparser.ast.expr.Expression
    getVariableInitializer(com.github.javaparser.ast.body.MethodDeclaration methodDeclaration, String variableName)
    Retrieve the initializer of the given variableName from the given MethodDeclaration
    static Optional<com.github.javaparser.ast.expr.Expression>
    getVariableInitializer(com.github.javaparser.ast.stmt.BlockStmt blockStmt, String variableName)
    Retrieve the initializer of the given variableName from the given MethodDeclaration
    static com.github.javaparser.ast.expr.Expression
    Return a new Expression containing an enum literal.
    static com.github.javaparser.ast.expr.Expression
    Return a new Expression containing an String.
    static com.github.javaparser.ast.expr.Expression
    literalExprFrom(org.kie.pmml.api.enums.DATA_TYPE type, String value)
    Return a new Expression containing an object with a specific value of a specific DATA_TYPE.
    static com.github.javaparser.ast.expr.MethodCallExpr
    methodCallExprFrom(String scope, String name, com.github.javaparser.ast.expr.Expression... arguments)
    Return a new MethodCallExpr from scope, name and arguments.
    static void
    populateListInListGetter(List<? extends com.github.javaparser.ast.expr.Expression> toAdd, com.github.javaparser.ast.body.MethodDeclaration methodDeclaration, String listName)
    Method to be used to populate a List inside a getter method meant to return only that List
    static void
    populateMethodDeclarations(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration toPopulate, Collection<com.github.javaparser.ast.body.MethodDeclaration> methodDeclarations)
    Populate the ClassOrInterfaceDeclaration with the provided MethodDeclarations
    static void
    replaceNameExprWithNullInStatement(com.github.javaparser.ast.stmt.Statement container, List<com.github.javaparser.ast.expr.NameExpr> toReplace)
    Replace the List<NameExpr>s in the given Statement with NullLiteralExpr
    static void
    replaceNodeInStatement(com.github.javaparser.ast.stmt.Statement container, CommonCodegenUtils.ReplacementTuple replacementTuple)
    Replace Node in the given Statement
    static void
    replaceNodesInStatement(com.github.javaparser.ast.stmt.Statement container, List<CommonCodegenUtils.ReplacementTuple> replacementTuples)
    Replace Nodes in the given Statement
    static void
    replaceStringLiteralExpressionInStatement(com.github.javaparser.ast.stmt.Statement container, String toReplace, String replacement)
    Replace StringLiteralExpresions in the given Statement
    static void
    setAssignExpressionValue(com.github.javaparser.ast.stmt.BlockStmt body, String assignExpressionName, com.github.javaparser.ast.expr.Expression value)
    Set the value of the variable with the given assignExpressionName in the given BlockStmt It throws KiePMMLException if variable is not found
    static void
    setConstructorDeclarationParameterArgument(com.github.javaparser.ast.body.ConstructorDeclaration constructorDeclaration, String parameterName, String value)
    Set the value of the given parameterName in the given ConstructorDeclaration
    static void
    setConstructorDeclarationReferenceArgument(com.github.javaparser.ast.body.ConstructorDeclaration constructorDeclaration, String referenceName, String value)
    Set the value of the given parameterName in the given ConstructorDeclaration
    static void
    setExplicitConstructorInvocationStmtArgument(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt constructorInvocationStmt, String parameterName, String value)
    Set the value of the given parameterName in the given ExplicitConstructorInvocationStmt
    static void
    setVariableDeclaratorValue(com.github.javaparser.ast.stmt.BlockStmt body, String variableDeclaratorName, com.github.javaparser.ast.expr.Expression value)
    Set the value of the variable with the given variableDeclaratorName in the given BlockStmt It throws KiePMMLException if variable is not found

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • OPTIONAL_FILTERED_KIEPMMLNAMEVALUE_NAME

      public static String OPTIONAL_FILTERED_KIEPMMLNAMEVALUE_NAME
  • Method Details

    • populateMethodDeclarations

      public static void populateMethodDeclarations(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration toPopulate, Collection<com.github.javaparser.ast.body.MethodDeclaration> methodDeclarations)
      Populate the ClassOrInterfaceDeclaration with the provided MethodDeclarations
      Parameters:
      toPopulate -
      methodDeclarations -
    • getFilteredKiePMMLNameValueExpression

      public static com.github.javaparser.ast.stmt.ExpressionStmt getFilteredKiePMMLNameValueExpression(String kiePMMLNameValueListParam, String fieldNameToRef, boolean stringLiteralComparison)
      Returns
        Optional kiePMMLNameValue = (kiePMMLNameValueListParam)
            .stream()
            .filter((KiePMMLNameValue kpmmlnv) -> Objects.equals("(fieldNameToRef)", kpmmlnv.getName()))
            .findFirst();
       

      expression, where kiePMMLNameValueListParam is the name of the List<KiePMMLNameValue> parameter, and fieldNameToRef is the name of the field to find, in the containing method

      Parameters:
      kiePMMLNameValueListParam -
      fieldNameToRef -
      stringLiteralComparison - if true, equals comparison is made on the String, e.g Objects .equals("(fieldNameToRef)", kpmmlnv.getName())), otherwise, is done on object reference, e.g Objects.equals((fieldNameToRef), kpmmlnv.getName())). In this latter case, a fieldNameToRef variable is expected to exists
      Returns:
    • addMapPopulation

      public static void addMapPopulation(Map<String,com.github.javaparser.ast.body.MethodDeclaration> toAdd, com.github.javaparser.ast.stmt.BlockStmt body, String mapName)
      For every entry in the given map, add
           (mapName).put(entry_key, this::entry_value_ref>);
       
      e.g.
           MAP_NAME.put("KEY_0", this::METHOD_015);
           MAP_NAME.put("KEY_3", this::METHOD_33);
           MAP_NAME.put("KEY_2", this::METHOD_219);
           MAP_NAME.put("KEY_4", this::METHOD_46);
       
      inside the given BlockStmt
      Parameters:
      toAdd -
      body -
      mapName -
    • createHashMap

      public static void createHashMap(com.github.javaparser.ast.stmt.BlockStmt body, String mapName, List<String> mapTypes)
      Declare and initialize a new Map in the given BlockStmt
      Parameters:
      body -
      mapName -
      mapTypes -
    • createLinkedHashMap

      public static void createLinkedHashMap(com.github.javaparser.ast.stmt.BlockStmt body, String mapName, List<String> mapTypes)
      Declare and initialize a new LinkedHashMap in the given BlockStmt
      Parameters:
      body -
      mapName -
      mapTypes -
    • createPopulatedHashMap

      public static void createPopulatedHashMap(com.github.javaparser.ast.stmt.BlockStmt body, String mapName, List<String> mapTypes, Map<String,com.github.javaparser.ast.expr.Expression> toAdd)
      Declare, initialize and populate a new HashMap in the given BlockStmt
      Parameters:
      body -
      mapName -
      mapTypes -
    • createPopulatedLinkedHashMap

      public static void createPopulatedLinkedHashMap(com.github.javaparser.ast.stmt.BlockStmt body, String mapName, List<String> mapTypes, Map<String,com.github.javaparser.ast.expr.Expression> toAdd)
      Declare, initialize and populate a new LinkedHashMap in the given BlockStmt
      Parameters:
      body -
      mapName -
      mapTypes -
    • addMapPopulationExpressions

      public static void addMapPopulationExpressions(Map<String,com.github.javaparser.ast.expr.Expression> toAdd, com.github.javaparser.ast.stmt.BlockStmt body, String mapName)
      For every entry in the given map, add a "put" statement to the provided BlockStmt body.
      Parameters:
      toAdd - the map containing the input values to process
      body - the destination body
      mapName - the name of the map to populate in the codegenerated statements
    • addListPopulationByObjectCreationExpr

      public static void addListPopulationByObjectCreationExpr(List<com.github.javaparser.ast.expr.ObjectCreationExpr> toAdd, com.github.javaparser.ast.stmt.BlockStmt body, String listName)
      For every entry in the given list, add
           (listName).add(new ObjectCreationExpr>);
       
      e.g.
           LIST_NAME.add(new OBJA());
           LIST_NAME.add(new OBJB());
           LIST_NAME.add(new OBJC());
           LIST_NAME.add(new OBJD());
       
      inside the given BlockStmt
      Parameters:
      toAdd -
      body -
      listName -
    • populateListInListGetter

      public static void populateListInListGetter(List<? extends com.github.javaparser.ast.expr.Expression> toAdd, com.github.javaparser.ast.body.MethodDeclaration methodDeclaration, String listName)
      Method to be used to populate a List inside a getter method meant to return only that List
      Parameters:
      toAdd -
      methodDeclaration -
      listName -
    • addListPopulationByMethodCallExpr

      public static void addListPopulationByMethodCallExpr(List<com.github.javaparser.ast.expr.MethodCallExpr> toAdd, com.github.javaparser.ast.stmt.BlockStmt body, String listName)
      For every entry in the given list, add
           (listName).add(MethodCallExpr>);
       
      e.g.
           LIST_NAME.add(ObjectA.builder().build());
           LIST_NAME.add(ObjectB.builder().build());
           LIST_NAME.add(ObjectC.builder().build());
           LIST_NAME.add(ObjectD.builder().build());
       
      inside the given BlockStmt
      Parameters:
      toAdd -
      body -
      listName -
    • createArraysAsListExpression

      public static com.github.javaparser.ast.stmt.ExpressionStmt createArraysAsListExpression()
      Create an empty Arrays.asList() ExpressionStmt
      Returns:
    • createArraysAsListFromList

      public static com.github.javaparser.ast.stmt.ExpressionStmt createArraysAsListFromList(List<?> source)
      Create a populated Arrays.asList(?... a) ExpressionStmt
      Parameters:
      source -
      Returns:
    • getMethodDeclaration

      public static com.github.javaparser.ast.body.MethodDeclaration getMethodDeclaration(String methodName, Map<String,com.github.javaparser.ast.type.ClassOrInterfaceType> parameterNameTypeMap)
      Returns
           empty (methodName)((list of parameterType parameter name)) {
       }
       

      a multi-parameters MethodDeclaration whose names are the keys of the given Map and methodArity, and whose parameters types are the values The

      Parameters:
      methodName -
      parameterNameTypeMap - expecting an ordered map here, since parameters order matter for caller code
      Returns:
    • getMethodDeclaration

      public static com.github.javaparser.ast.body.MethodDeclaration getMethodDeclaration(String methodName)
      Returns
           empty (methodName)() {
           }
       

      A no-parameter MethodDeclaration whose name is derived from given methodName and methodArity

      Parameters:
      methodName -
      Returns:
    • getReturnStmt

      public static com.github.javaparser.ast.stmt.ReturnStmt getReturnStmt(String returnedVariableName)
      Returns
           return (returnedVariableName);
       

      e.g

           return varOne;
       
      Parameters:
      returnedVariableName -
      Returns:
    • getTypedClassOrInterfaceTypeByTypeNames

      public static com.github.javaparser.ast.type.ClassOrInterfaceType getTypedClassOrInterfaceTypeByTypeNames(String className, List<String> typesName)
      Returns
           (className)<(comma-separated list of types)>
       

      e.g

           CLASS_NAME<TypeA, TypeB>
       
      a typed ClassOrInterfaceType
      Parameters:
      className -
      typesName -
      Returns:
    • getTypedClassOrInterfaceTypeByTypes

      public static com.github.javaparser.ast.type.ClassOrInterfaceType getTypedClassOrInterfaceTypeByTypes(String className, List<com.github.javaparser.ast.type.Type> types)
      Returns
           (className)<(comma-separated list of types)>
       

      e.g

           CLASS_NAME<TypeA, TypeB>
       
      a typed ClassOrInterfaceType
      Parameters:
      className -
      types -
      Returns:
    • setAssignExpressionValue

      public static void setAssignExpressionValue(com.github.javaparser.ast.stmt.BlockStmt body, String assignExpressionName, com.github.javaparser.ast.expr.Expression value)
      Set the value of the variable with the given assignExpressionName in the given BlockStmt It throws KiePMMLException if variable is not found
      Parameters:
      body -
      assignExpressionName -
      value -
    • getAssignExpression

      public static Optional<com.github.javaparser.ast.expr.AssignExpr> getAssignExpression(com.github.javaparser.ast.stmt.BlockStmt body, String assignExpressionName)
      Return an Optional<AssignExpr> with the given assignExpressionName from the given BlockStmt
      Parameters:
      body -
      assignExpressionName -
      Returns:
      Optional<AssignExpr> with the found AssignExpr, or Optional .empty() if no match has been found
    • getExplicitConstructorInvocationStmt

      public static Optional<com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt> getExplicitConstructorInvocationStmt(com.github.javaparser.ast.stmt.BlockStmt body)
      Return an Optional<ExplicitConstructorInvocationStmt> from the given BlockStmt
      Parameters:
      body -
      Returns:
      Optional<ExplicitConstructorInvocationStmt> with the found ExplicitConstructorInvocationStmt, or Optional.empty() if none is found
    • setConstructorDeclarationParameterArgument

      public static void setConstructorDeclarationParameterArgument(com.github.javaparser.ast.body.ConstructorDeclaration constructorDeclaration, String parameterName, String value)
      Set the value of the given parameterName in the given ConstructorDeclaration
      Parameters:
      constructorDeclaration -
      parameterName -
      value -
      Throws:
      org.kie.pmml.api.exceptions.KiePMMLException - if the given parameter is not found
    • setConstructorDeclarationReferenceArgument

      public static void setConstructorDeclarationReferenceArgument(com.github.javaparser.ast.body.ConstructorDeclaration constructorDeclaration, String referenceName, String value)
      Set the value of the given parameterName in the given ConstructorDeclaration
      Parameters:
      constructorDeclaration -
      referenceName -
      value -
      Throws:
      org.kie.pmml.api.exceptions.KiePMMLException - if the given parameter is not found
    • setExplicitConstructorInvocationStmtArgument

      public static void setExplicitConstructorInvocationStmtArgument(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt constructorInvocationStmt, String parameterName, String value)
      Set the value of the given parameterName in the given ExplicitConstructorInvocationStmt
      Parameters:
      constructorInvocationStmt -
      parameterName -
      value -
      Throws:
      org.kie.pmml.api.exceptions.KiePMMLException - if the given parameter is not found
    • getInitializerBlockStmt

      public static com.github.javaparser.ast.stmt.BlockStmt getInitializerBlockStmt(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration classOrInterfaceDeclaration)
      Return an BlockStmt from the given ClassOrInterfaceDeclaration
      Parameters:
      classOrInterfaceDeclaration -
      Throws:
      org.kie.pmml.api.exceptions.KiePMMLException - if none is found
    • getInitializerDeclaration

      public static com.github.javaparser.ast.body.InitializerDeclaration getInitializerDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration classOrInterfaceDeclaration)
      Return an InitializerDeclaration from the given ClassOrInterfaceDeclaration
      Parameters:
      classOrInterfaceDeclaration -
      Throws:
      org.kie.pmml.api.exceptions.KiePMMLException - if none is found
    • getExplicitConstructorInvocationParameter

      public static Optional<com.github.javaparser.ast.expr.NameExpr> getExplicitConstructorInvocationParameter(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt constructorInvocationStmt, String parameterName)
      Return an Optional<NameExpr> from the given ExplicitConstructorInvocationStmt
      Parameters:
      constructorInvocationStmt -
      parameterName -
      Returns:
      Optional<NameExpr> with the found NameExpr, or Optional.empty() if none is found
    • getExplicitConstructorInvocationMethodReference

      public static Optional<com.github.javaparser.ast.expr.MethodReferenceExpr> getExplicitConstructorInvocationMethodReference(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt constructorInvocationStmt, String typeName)
      Return an Optional<MethodReferenceExpr> from the given ExplicitConstructorInvocationStmt
      Parameters:
      constructorInvocationStmt -
      typeName -
      Returns:
      Optional<MethodReferenceExpr> with the found MethodReferenceExpr, or Optional.empty() if none is found
    • getMethodDeclarationBlockStmt

      public static com.github.javaparser.ast.stmt.BlockStmt getMethodDeclarationBlockStmt(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration classOrInterfaceDeclaration, String methodName)
      Return an BlockStmt for the method methodName from the given ClassOrInterfaceDeclaration
      Parameters:
      classOrInterfaceDeclaration -
      methodName -
      Throws:
      org.kie.pmml.api.exceptions.KiePMMLException - if none is found
    • getMethodDeclaration

      public static Optional<com.github.javaparser.ast.body.MethodDeclaration> getMethodDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration classOrInterfaceDeclaration, String methodName)
      Return an Optional<MethodDeclaration> with the first method methodName from the given ClassOrInterfaceDeclaration
      Parameters:
      classOrInterfaceDeclaration -
      methodName -
      Returns:
      Optional<MethodDeclaration> with the first found MethodDeclaration, or Optional.empty() if no match has been found
    • addMethod

      public static com.github.javaparser.ast.body.MethodDeclaration addMethod(com.github.javaparser.ast.body.MethodDeclaration methodTemplate, com.github.javaparser.ast.body.ClassOrInterfaceDeclaration tableTemplate, String methodName)
      Add a MethodDeclaration to the class
      Parameters:
      methodTemplate -
      tableTemplate -
      methodName -
      Returns:
    • setVariableDeclaratorValue

      public static void setVariableDeclaratorValue(com.github.javaparser.ast.stmt.BlockStmt body, String variableDeclaratorName, com.github.javaparser.ast.expr.Expression value)
      Set the value of the variable with the given variableDeclaratorName in the given BlockStmt It throws KiePMMLException if variable is not found
      Parameters:
      body -
      variableDeclaratorName -
      value -
    • getVariableDeclarator

      public static Optional<com.github.javaparser.ast.body.VariableDeclarator> getVariableDeclarator(com.github.javaparser.ast.body.MethodDeclaration methodDeclaration, String variableName)
      Return an Optional<VariableDeclarator> with the first variable variableName from the given MethodDeclaration
      Parameters:
      methodDeclaration -
      variableName -
      Returns:
      Optional<VariableDeclarator> with the first found VariableDeclarator, or Optional.empty() if no match has been found
    • getVariableDeclarator

      public static Optional<com.github.javaparser.ast.body.VariableDeclarator> getVariableDeclarator(com.github.javaparser.ast.stmt.BlockStmt body, String variableName)
      Return an Optional<VariableDeclarator> with the first variable variableName from the given BlockStmt
      Parameters:
      body -
      variableName -
      Returns:
      Optional<VariableDeclarator> with the first found VariableDeclarator, or Optional.empty() if no match has been found
    • getExpressionForDataType

      public static com.github.javaparser.ast.expr.Expression getExpressionForDataType(org.dmg.pmml.DataType dataTypeParam)
    • getExpressionForOpType

      public static com.github.javaparser.ast.expr.Expression getExpressionForOpType(org.dmg.pmml.OpType opTypeParam)
    • getExpressionForObject

      public static com.github.javaparser.ast.expr.Expression getExpressionForObject(Object source)
    • getNameExprsFromBlock

      public static List<com.github.javaparser.ast.expr.NameExpr> getNameExprsFromBlock(com.github.javaparser.ast.stmt.BlockStmt toRead, String exprName)
      Return a lit<NameExpr> with all the instances of the given exprName
      Parameters:
      toRead -
      exprName -
      Returns:
    • assignExprFrom

      public static com.github.javaparser.ast.expr.AssignExpr assignExprFrom(String target, com.github.javaparser.ast.expr.Expression value)
      Return a new AssignExpr from a target name and a generic Expression.
      Parameters:
      target - String containing the name to assign the expression to
      value - the value to be assigned
      Returns:
      the new AssignExpr
    • assignExprFrom

      public static com.github.javaparser.ast.expr.AssignExpr assignExprFrom(String target, Enum<?> value)
      Return a new AssignExpr from a target name and an enum literal.
      Parameters:
      target - String containing the name to assign the expression to
      value - the enum value to be assigned
      Returns:
      the new AssignExpr
    • assignExprFrom

      public static com.github.javaparser.ast.expr.AssignExpr assignExprFrom(String target, String value)
      Return a new AssignExpr from a target name and String literal.
      Parameters:
      target - String containing the name to assign the expression to
      value - the String value to be assigned
      Returns:
      the new AssignExpr
    • literalExprFrom

      public static com.github.javaparser.ast.expr.Expression literalExprFrom(Enum<?> input)
      Return a new Expression containing an enum literal.
      Parameters:
      input - the enum value to be assigned
      Returns:
      the new Expression
    • literalExprFrom

      public static com.github.javaparser.ast.expr.Expression literalExprFrom(String input)
      Return a new Expression containing an String.
      Parameters:
      input - the String value to be assigned
      Returns:
      the new Expression
    • literalExprFrom

      public static com.github.javaparser.ast.expr.Expression literalExprFrom(org.kie.pmml.api.enums.DATA_TYPE type, String value)
      Return a new Expression containing an object with a specific value of a specific DATA_TYPE. This can either be a new object (for date and time) or a literal.
      Parameters:
      type - the DATA_TYPE of the specified value
      value - the value represented as String
      Returns:
      the new Expression
    • methodCallExprFrom

      public static com.github.javaparser.ast.expr.MethodCallExpr methodCallExprFrom(String scope, String name, com.github.javaparser.ast.expr.Expression... arguments)
      Return a new MethodCallExpr from scope, name and arguments.
      Parameters:
      scope - the scope of the method to call
      name - the name of the method to call
      arguments - vararg list of Expression arguments
      Returns:
      the new MethodCallExpr
    • getChainedMethodCallExprFrom

      public static com.github.javaparser.ast.expr.MethodCallExpr getChainedMethodCallExprFrom(String name, com.github.javaparser.ast.expr.MethodCallExpr parent)
      Return a "chained" MethodCallExpr by name parent one.
      Parameters:
      name - the name of the method to call
      parent - vararg list of Expression arguments
      Returns:
      the found MethodCallExpr
    • replaceStringLiteralExpressionInStatement

      public static void replaceStringLiteralExpressionInStatement(com.github.javaparser.ast.stmt.Statement container, String toReplace, String replacement)
      Replace StringLiteralExpresions in the given Statement
      Parameters:
      container -
      toReplace -
      replacement -
    • replaceNodesInStatement

      public static void replaceNodesInStatement(com.github.javaparser.ast.stmt.Statement container, List<CommonCodegenUtils.ReplacementTuple> replacementTuples)
      Replace Nodes in the given Statement
      Parameters:
      container -
      replacementTuples -
    • replaceNodeInStatement

      public static void replaceNodeInStatement(com.github.javaparser.ast.stmt.Statement container, CommonCodegenUtils.ReplacementTuple replacementTuple)
      Replace Node in the given Statement
      Parameters:
      container -
      replacementTuple -
    • addMethodDeclarationsToClass

      public static void addMethodDeclarationsToClass(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration classOrInterfaceDeclaration, List<com.github.javaparser.ast.body.MethodDeclaration> toAdd)
      Add a MethodDeclarations to the given ClassOrInterfaceDeclaration
      Parameters:
      classOrInterfaceDeclaration -
      toAdd -
    • addMethodDeclarationToClass

      public static void addMethodDeclarationToClass(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration classOrInterfaceDeclaration, com.github.javaparser.ast.body.MethodDeclaration toAdd)
      Add a MethodDeclaration to the given ClassOrInterfaceDeclaration
      Parameters:
      classOrInterfaceDeclaration -
      toAdd -
    • getVariableInitializer

      public static com.github.javaparser.ast.expr.Expression getVariableInitializer(com.github.javaparser.ast.body.MethodDeclaration methodDeclaration, String variableName)
      Retrieve the initializer of the given variableName from the given MethodDeclaration
      Returns:
    • getOptionalVariableInitializer

      public static Optional<com.github.javaparser.ast.expr.Expression> getOptionalVariableInitializer(com.github.javaparser.ast.body.MethodDeclaration methodDeclaration, String variableName)
      Retrieve the initializer of the given variableName from the given MethodDeclaration
      Returns:
    • getVariableInitializer

      public static Optional<com.github.javaparser.ast.expr.Expression> getVariableInitializer(com.github.javaparser.ast.stmt.BlockStmt blockStmt, String variableName)
      Retrieve the initializer of the given variableName from the given MethodDeclaration
      Returns:
    • replaceNameExprWithNullInStatement

      public static void replaceNameExprWithNullInStatement(com.github.javaparser.ast.stmt.Statement container, List<com.github.javaparser.ast.expr.NameExpr> toReplace)
      Replace the List<NameExpr>s in the given Statement with NullLiteralExpr
      Parameters:
      container -
      toReplace -
    • getArraysAsListInvocationMethodCall

      public static com.github.javaparser.ast.expr.MethodCallExpr getArraysAsListInvocationMethodCall(com.github.javaparser.ast.NodeList<com.github.javaparser.ast.expr.Expression> arguments)
    • getArraysAsListInvocation

      public static com.github.javaparser.ast.NodeList<com.github.javaparser.ast.expr.Expression> getArraysAsListInvocation(com.github.javaparser.ast.NodeList<com.github.javaparser.ast.expr.Expression> arguments)