Class CommonCodegenUtils
java.lang.Object
org.kie.pmml.compiler.commons.utils.CommonCodegenUtils
Class meant to provide helper methods to all code-generating classes
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddListPopulationByMethodCallExpr(List<com.github.javaparser.ast.expr.MethodCallExpr> toAdd, com.github.javaparser.ast.stmt.BlockStmt body, String listName) For every entry in the given list, addstatic voidaddListPopulationByObjectCreationExpr(List<com.github.javaparser.ast.expr.ObjectCreationExpr> toAdd, com.github.javaparser.ast.stmt.BlockStmt body, String listName) For every entry in the given list, addstatic voidaddMapPopulation(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, addstatic voidaddMapPopulationExpressions(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 providedBlockStmtbody.static com.github.javaparser.ast.body.MethodDeclarationaddMethod(com.github.javaparser.ast.body.MethodDeclaration methodTemplate, com.github.javaparser.ast.body.ClassOrInterfaceDeclaration tableTemplate, String methodName) Add aMethodDeclarationto the classstatic voidaddMethodDeclarationsToClass(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration classOrInterfaceDeclaration, List<com.github.javaparser.ast.body.MethodDeclaration> toAdd) Add aMethodDeclarations to the givenClassOrInterfaceDeclarationstatic voidaddMethodDeclarationToClass(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration classOrInterfaceDeclaration, com.github.javaparser.ast.body.MethodDeclaration toAdd) Add aMethodDeclarationto the givenClassOrInterfaceDeclarationstatic com.github.javaparser.ast.expr.AssignExprassignExprFrom(String target, com.github.javaparser.ast.expr.Expression value) Return a newAssignExprfrom a target name and a genericExpression.static com.github.javaparser.ast.expr.AssignExprassignExprFrom(String target, Enum<?> value) Return a newAssignExprfrom a target name and an enum literal.static com.github.javaparser.ast.expr.AssignExprassignExprFrom(String target, String value) Return a newAssignExprfrom a target name andStringliteral.static com.github.javaparser.ast.stmt.ExpressionStmtCreate an empty Arrays.asList()ExpressionStmtstatic com.github.javaparser.ast.stmt.ExpressionStmtcreateArraysAsListFromList(List<?> source) Create a populated Arrays.asList(?...static voidcreateHashMap(com.github.javaparser.ast.stmt.BlockStmt body, String mapName, List<String> mapTypes) Declare and initialize a newMapin the givenBlockStmtstatic voidcreateLinkedHashMap(com.github.javaparser.ast.stmt.BlockStmt body, String mapName, List<String> mapTypes) Declare and initialize a newLinkedHashMapin the givenBlockStmtstatic voidcreatePopulatedHashMap(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 newHashMapin the givenBlockStmtstatic voidcreatePopulatedLinkedHashMap(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 newLinkedHashMapin the givenBlockStmtstatic 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.MethodCallExprgetArraysAsListInvocationMethodCall(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 anOptional<AssignExpr>with the given assignExpressionName from the givenBlockStmtstatic com.github.javaparser.ast.expr.MethodCallExprgetChainedMethodCallExprFrom(String name, com.github.javaparser.ast.expr.MethodCallExpr parent) Return a "chained"MethodCallExprby name parent one.static Optional<com.github.javaparser.ast.expr.MethodReferenceExpr>getExplicitConstructorInvocationMethodReference(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt constructorInvocationStmt, String typeName) Return anOptional<MethodReferenceExpr>from the givenExplicitConstructorInvocationStmtstatic Optional<com.github.javaparser.ast.expr.NameExpr>getExplicitConstructorInvocationParameter(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt constructorInvocationStmt, String parameterName) Return anOptional<NameExpr>from the givenExplicitConstructorInvocationStmtstatic Optional<com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt>getExplicitConstructorInvocationStmt(com.github.javaparser.ast.stmt.BlockStmt body) Return anOptional<ExplicitConstructorInvocationStmt>from the givenBlockStmtstatic com.github.javaparser.ast.expr.ExpressiongetExpressionForDataType(org.dmg.pmml.DataType dataTypeParam) static com.github.javaparser.ast.expr.ExpressiongetExpressionForObject(Object source) static com.github.javaparser.ast.expr.ExpressiongetExpressionForOpType(org.dmg.pmml.OpType opTypeParam) static com.github.javaparser.ast.stmt.ExpressionStmtgetFilteredKiePMMLNameValueExpression(String kiePMMLNameValueListParam, String fieldNameToRef, boolean stringLiteralComparison) Returnsstatic com.github.javaparser.ast.stmt.BlockStmtgetInitializerBlockStmt(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration classOrInterfaceDeclaration) Return anBlockStmtfrom the givenClassOrInterfaceDeclarationstatic com.github.javaparser.ast.body.InitializerDeclarationgetInitializerDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration classOrInterfaceDeclaration) Return anInitializerDeclarationfrom the givenClassOrInterfaceDeclarationstatic Optional<com.github.javaparser.ast.body.MethodDeclaration>getMethodDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration classOrInterfaceDeclaration, String methodName) Return anOptional<MethodDeclaration>with the first method methodName from the givenClassOrInterfaceDeclarationstatic com.github.javaparser.ast.body.MethodDeclarationgetMethodDeclaration(String methodName) Returnsstatic com.github.javaparser.ast.body.MethodDeclarationgetMethodDeclaration(String methodName, Map<String, com.github.javaparser.ast.type.ClassOrInterfaceType> parameterNameTypeMap) Returnsstatic com.github.javaparser.ast.stmt.BlockStmtgetMethodDeclarationBlockStmt(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration classOrInterfaceDeclaration, String methodName) Return anBlockStmtfor the method methodName from the givenClassOrInterfaceDeclarationstatic List<com.github.javaparser.ast.expr.NameExpr>getNameExprsFromBlock(com.github.javaparser.ast.stmt.BlockStmt toRead, String exprName) Return alit<NameExpr>with all the instances of the given exprNamestatic 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 givenMethodDeclarationstatic com.github.javaparser.ast.stmt.ReturnStmtgetReturnStmt(String returnedVariableName) Returnsstatic com.github.javaparser.ast.type.ClassOrInterfaceTypegetTypedClassOrInterfaceTypeByTypeNames(String className, List<String> typesName) Returnsstatic com.github.javaparser.ast.type.ClassOrInterfaceTypegetTypedClassOrInterfaceTypeByTypes(String className, List<com.github.javaparser.ast.type.Type> types) Returnsstatic Optional<com.github.javaparser.ast.body.VariableDeclarator>getVariableDeclarator(com.github.javaparser.ast.body.MethodDeclaration methodDeclaration, String variableName) Return anOptional<VariableDeclarator>with the first variable variableName from the givenMethodDeclarationstatic Optional<com.github.javaparser.ast.body.VariableDeclarator>getVariableDeclarator(com.github.javaparser.ast.stmt.BlockStmt body, String variableName) Return anOptional<VariableDeclarator>with the first variable variableName from the givenBlockStmtstatic com.github.javaparser.ast.expr.ExpressiongetVariableInitializer(com.github.javaparser.ast.body.MethodDeclaration methodDeclaration, String variableName) Retrieve the initializer of the given variableName from the givenMethodDeclarationstatic 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 givenMethodDeclarationstatic com.github.javaparser.ast.expr.ExpressionliteralExprFrom(Enum<?> input) Return a newExpressioncontaining an enum literal.static com.github.javaparser.ast.expr.ExpressionliteralExprFrom(String input) Return a newExpressioncontaining anString.static com.github.javaparser.ast.expr.ExpressionliteralExprFrom(org.kie.pmml.api.enums.DATA_TYPE type, String value) Return a newExpressioncontaining an object with a specific value of a specificDATA_TYPE.static com.github.javaparser.ast.expr.MethodCallExprmethodCallExprFrom(String scope, String name, com.github.javaparser.ast.expr.Expression... arguments) Return a newMethodCallExprfrom scope, name and arguments.static voidpopulateListInListGetter(List<? extends com.github.javaparser.ast.expr.Expression> toAdd, com.github.javaparser.ast.body.MethodDeclaration methodDeclaration, String listName) Method to be used to populate aListinside a getter method meant to return only thatListstatic voidpopulateMethodDeclarations(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration toPopulate, Collection<com.github.javaparser.ast.body.MethodDeclaration> methodDeclarations) Populate theClassOrInterfaceDeclarationwith the providedMethodDeclarationsstatic voidreplaceNameExprWithNullInStatement(com.github.javaparser.ast.stmt.Statement container, List<com.github.javaparser.ast.expr.NameExpr> toReplace) Replace theList<NameExpr>s in the givenStatementwithNullLiteralExprstatic voidreplaceNodeInStatement(com.github.javaparser.ast.stmt.Statement container, CommonCodegenUtils.ReplacementTuple replacementTuple) ReplaceNodein the givenStatementstatic voidreplaceNodesInStatement(com.github.javaparser.ast.stmt.Statement container, List<CommonCodegenUtils.ReplacementTuple> replacementTuples) ReplaceNodes in the givenStatementstatic voidreplaceStringLiteralExpressionInStatement(com.github.javaparser.ast.stmt.Statement container, String toReplace, String replacement) ReplaceStringLiteralExpresions in the givenStatementstatic voidsetAssignExpressionValue(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 givenBlockStmtIt throwsKiePMMLExceptionif variable is not foundstatic voidsetConstructorDeclarationParameterArgument(com.github.javaparser.ast.body.ConstructorDeclaration constructorDeclaration, String parameterName, String value) Set the value of the given parameterName in the givenConstructorDeclarationstatic voidsetConstructorDeclarationReferenceArgument(com.github.javaparser.ast.body.ConstructorDeclaration constructorDeclaration, String referenceName, String value) Set the value of the given parameterName in the givenConstructorDeclarationstatic voidsetExplicitConstructorInvocationStmtArgument(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt constructorInvocationStmt, String parameterName, String value) Set the value of the given parameterName in the givenExplicitConstructorInvocationStmtstatic voidsetVariableDeclaratorValue(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 givenBlockStmtIt throwsKiePMMLExceptionif variable is not found
-
Field Details
-
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 theClassOrInterfaceDeclarationwith the providedMethodDeclarations- Parameters:
toPopulate-methodDeclarations-
-
getFilteredKiePMMLNameValueExpression
public static com.github.javaparser.ast.stmt.ExpressionStmt getFilteredKiePMMLNameValueExpression(String kiePMMLNameValueListParam, String fieldNameToRef, boolean stringLiteralComparison) ReturnsOptional
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- iftrue, 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 givenBlockStmt- 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 newMapin the givenBlockStmt- 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 newLinkedHashMapin the givenBlockStmt- 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 newHashMapin the givenBlockStmt- 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 newLinkedHashMapin the givenBlockStmt- 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 providedBlockStmtbody.- Parameters:
toAdd- the map containing the input values to processbody- the destination bodymapName- 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 givenBlockStmt- 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 aListinside a getter method meant to return only thatList- 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 givenBlockStmt- 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) Returnsempty (methodName)((list of parameterType parameter name)) { }a multi-parameters
MethodDeclarationwhose names are the keys of the givenMapand 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) Returnsempty (methodName)() { }A no-parameter
MethodDeclarationwhose name is derived from given methodName and methodArity- Parameters:
methodName-- Returns:
-
getReturnStmt
Returnsreturn (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 typedClassOrInterfaceType- 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 typedClassOrInterfaceType- 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 givenBlockStmtIt throwsKiePMMLExceptionif 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 anOptional<AssignExpr>with the given assignExpressionName from the givenBlockStmt- Parameters:
body-assignExpressionName-- Returns:
Optional<AssignExpr>with the foundAssignExpr, orOptional .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 anOptional<ExplicitConstructorInvocationStmt>from the givenBlockStmt- Parameters:
body-- Returns:
Optional<ExplicitConstructorInvocationStmt>with the foundExplicitConstructorInvocationStmt, orOptional.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 givenConstructorDeclaration- 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 givenConstructorDeclaration- 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 givenExplicitConstructorInvocationStmt- 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 anBlockStmtfrom the givenClassOrInterfaceDeclaration- 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 anInitializerDeclarationfrom the givenClassOrInterfaceDeclaration- 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 anOptional<NameExpr>from the givenExplicitConstructorInvocationStmt- Parameters:
constructorInvocationStmt-parameterName-- Returns:
Optional<NameExpr>with the foundNameExpr, orOptional.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 anOptional<MethodReferenceExpr>from the givenExplicitConstructorInvocationStmt- Parameters:
constructorInvocationStmt-typeName-- Returns:
Optional<MethodReferenceExpr>with the foundMethodReferenceExpr, orOptional.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 anBlockStmtfor the method methodName from the givenClassOrInterfaceDeclaration- 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 anOptional<MethodDeclaration>with the first method methodName from the givenClassOrInterfaceDeclaration- Parameters:
classOrInterfaceDeclaration-methodName-- Returns:
Optional<MethodDeclaration>with the first foundMethodDeclaration, orOptional.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 aMethodDeclarationto 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 givenBlockStmtIt throwsKiePMMLExceptionif 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 anOptional<VariableDeclarator>with the first variable variableName from the givenMethodDeclaration- Parameters:
methodDeclaration-variableName-- Returns:
Optional<VariableDeclarator>with the first foundVariableDeclarator, orOptional.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 anOptional<VariableDeclarator>with the first variable variableName from the givenBlockStmt- Parameters:
body-variableName-- Returns:
Optional<VariableDeclarator>with the first foundVariableDeclarator, orOptional.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
-
getNameExprsFromBlock
public static List<com.github.javaparser.ast.expr.NameExpr> getNameExprsFromBlock(com.github.javaparser.ast.stmt.BlockStmt toRead, String exprName) Return alit<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 newAssignExprfrom a target name and a genericExpression.- Parameters:
target-Stringcontaining the name to assign the expression tovalue- 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 newAssignExprfrom a target name and an enum literal.- Parameters:
target-Stringcontaining the name to assign the expression tovalue- the enum value to be assigned- Returns:
- the new
AssignExpr
-
assignExprFrom
Return a newAssignExprfrom a target name andStringliteral. -
literalExprFrom
Return a newExpressioncontaining an enum literal.- Parameters:
input- the enum value to be assigned- Returns:
- the new
Expression
-
literalExprFrom
Return a newExpressioncontaining anString.- Parameters:
input- theStringvalue 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 newExpressioncontaining an object with a specific value of a specificDATA_TYPE. This can either be a new object (for date and time) or a literal.- Parameters:
type- theDATA_TYPEof the specified valuevalue- the value represented asString- 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 newMethodCallExprfrom scope, name and arguments.- Parameters:
scope- the scope of the method to callname- the name of the method to callarguments- vararg list ofExpressionarguments- 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"MethodCallExprby name parent one.- Parameters:
name- the name of the method to callparent- vararg list ofExpressionarguments- Returns:
- the found
MethodCallExpr
-
replaceStringLiteralExpressionInStatement
public static void replaceStringLiteralExpressionInStatement(com.github.javaparser.ast.stmt.Statement container, String toReplace, String replacement) ReplaceStringLiteralExpresions in the givenStatement- Parameters:
container-toReplace-replacement-
-
replaceNodesInStatement
public static void replaceNodesInStatement(com.github.javaparser.ast.stmt.Statement container, List<CommonCodegenUtils.ReplacementTuple> replacementTuples) ReplaceNodes in the givenStatement- Parameters:
container-replacementTuples-
-
replaceNodeInStatement
public static void replaceNodeInStatement(com.github.javaparser.ast.stmt.Statement container, CommonCodegenUtils.ReplacementTuple replacementTuple) ReplaceNodein the givenStatement- Parameters:
container-replacementTuple-
-
addMethodDeclarationsToClass
public static void addMethodDeclarationsToClass(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration classOrInterfaceDeclaration, List<com.github.javaparser.ast.body.MethodDeclaration> toAdd) Add aMethodDeclarations to the givenClassOrInterfaceDeclaration- Parameters:
classOrInterfaceDeclaration-toAdd-
-
addMethodDeclarationToClass
public static void addMethodDeclarationToClass(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration classOrInterfaceDeclaration, com.github.javaparser.ast.body.MethodDeclaration toAdd) Add aMethodDeclarationto the givenClassOrInterfaceDeclaration- 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 givenMethodDeclaration- 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 givenMethodDeclaration- 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 givenMethodDeclaration- Returns:
-
replaceNameExprWithNullInStatement
public static void replaceNameExprWithNullInStatement(com.github.javaparser.ast.stmt.Statement container, List<com.github.javaparser.ast.expr.NameExpr> toReplace) Replace theList<NameExpr>s in the givenStatementwithNullLiteralExpr- 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)
-