public class CommonCodegenUtils extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
CommonCodegenUtils.ReplacementTupla |
| Modifier and Type | Field and Description |
|---|---|
static String |
OPTIONAL_FILTERED_KIEPMMLNAMEVALUE_NAME |
| Modifier and Type | Method and Description |
|---|---|
static void |
addListPopulation(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.
|
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.
|
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,
Enum<?> value)
Return a new
AssignExpr from a target name and an enum literal. |
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,
String value)
Return a new
AssignExpr from a target name and String literal. |
static com.github.javaparser.ast.stmt.ExpressionStmt |
createArraysAsListExpression()
Create an empty Arrays.asList()
ExpressionStmt |
static com.github.javaparser.ast.stmt.ExpressionStmt |
createArraysAsListFromList(List<?> source)
Create a populated Arrays.asList(?...
|
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 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 |
getExpressionForObject(Object source) |
static com.github.javaparser.ast.stmt.ExpressionStmt |
getFilteredKiePMMLNameValueExpression(String kiePMMLNameValueListParam,
String fieldNameToRef,
boolean stringLiteralComparison)
Returns
Optional
List<KiePMMLNameValue> parameter, and
fieldNameToRef is the name of the field to find, in the containing method |
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 |
getMethodDeclaration(String methodName)
Returns
empty (methodName)() {
}
A no-parameter
MethodDeclaration whose name is derived from given methodName
and methodArity |
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 |
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
return (returnedVariableName);
e.g
return varOne;
|
static com.github.javaparser.ast.type.ClassOrInterfaceType |
getTypedClassOrInterfaceType(String className,
List<String> typesName)
Returns
(className)<(comma-separated list of types)>
e.g
CLASS_NAME
ClassOrInterfaceType |
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 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.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 |
getVariableInitializer(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.expr.Expression |
literalExprFrom(Enum<?> input)
Return a new
Expression containing an enum literal. |
static com.github.javaparser.ast.expr.Expression |
literalExprFrom(String input)
Return a new
Expression containing an String. |
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 |
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.ReplacementTupla replacementTupla)
Replace
Node in the given Statement |
static void |
replaceNodesInStatement(com.github.javaparser.ast.stmt.Statement container,
List<CommonCodegenUtils.ReplacementTupla> replacementTuplas)
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 |
public static String OPTIONAL_FILTERED_KIEPMMLNAMEVALUE_NAME
public static void populateMethodDeclarations(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration toPopulate,
Collection<com.github.javaparser.ast.body.MethodDeclaration> methodDeclarations)
ClassOrInterfaceDeclaration with the provided MethodDeclarationstoPopulate - methodDeclarations - public static com.github.javaparser.ast.stmt.ExpressionStmt getFilteredKiePMMLNameValueExpression(String kiePMMLNameValueListParam, String fieldNameToRef, boolean stringLiteralComparison)
OptionalkiePMMLNameValue = (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
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 existspublic static void addMapPopulation(Map<String,com.github.javaparser.ast.body.MethodDeclaration> toAdd, com.github.javaparser.ast.stmt.BlockStmt body, String mapName)
(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 BlockStmttoAdd - body - mapName - public static void addListPopulation(List<com.github.javaparser.ast.expr.ObjectCreationExpr> toAdd, com.github.javaparser.ast.stmt.BlockStmt body, String listName)
(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 BlockStmttoAdd - body - listName - public static com.github.javaparser.ast.stmt.ExpressionStmt createArraysAsListExpression()
ExpressionStmtpublic static com.github.javaparser.ast.stmt.ExpressionStmt createArraysAsListFromList(List<?> source)
ExpressionStmtsource - public static com.github.javaparser.ast.body.MethodDeclaration getMethodDeclaration(String methodName, Map<String,com.github.javaparser.ast.type.ClassOrInterfaceType> parameterNameTypeMap)
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
methodName - parameterNameTypeMap - expecting an ordered map here, since parameters order matter for
caller codepublic static com.github.javaparser.ast.body.MethodDeclaration getMethodDeclaration(String methodName)
empty (methodName)() {
}
A no-parameter MethodDeclaration whose name is derived from given methodName
and methodArity
methodName - public static com.github.javaparser.ast.stmt.ReturnStmt getReturnStmt(String returnedVariableName)
return (returnedVariableName);
e.g
return varOne;
returnedVariableName - public static com.github.javaparser.ast.type.ClassOrInterfaceType getTypedClassOrInterfaceType(String className, List<String> typesName)
(className)<(comma-separated list of types)>
e.g
CLASS_NAME
a typed ClassOrInterfaceTypeclassName - typesName - public static void setAssignExpressionValue(com.github.javaparser.ast.stmt.BlockStmt body,
String assignExpressionName,
com.github.javaparser.ast.expr.Expression value)
BlockStmt
It throws KiePMMLException if variable is not foundbody - assignExpressionName - value - KiePMMLException - if AssignExpr with given assignExpressionName is not
foundpublic static Optional<com.github.javaparser.ast.expr.AssignExpr> getAssignExpression(com.github.javaparser.ast.stmt.BlockStmt body, String assignExpressionName)
Optional<AssignExpr> with the given assignExpressionName from the given
BlockStmtbody - assignExpressionName - Optional<AssignExpr> with the found AssignExpr, or Optional
.empty() if no match
has been foundpublic static Optional<com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt> getExplicitConstructorInvocationStmt(com.github.javaparser.ast.stmt.BlockStmt body)
Optional<ExplicitConstructorInvocationStmt> from the given BlockStmtbody - Optional<ExplicitConstructorInvocationStmt> with the found
ExplicitConstructorInvocationStmt, or Optional.empty() if none is foundpublic static void setConstructorDeclarationParameterArgument(com.github.javaparser.ast.body.ConstructorDeclaration constructorDeclaration,
String parameterName,
String value)
ConstructorDeclarationconstructorDeclaration - parameterName - value - org.kie.pmml.api.exceptions.KiePMMLException - if the given parameter is not foundpublic static void setConstructorDeclarationReferenceArgument(com.github.javaparser.ast.body.ConstructorDeclaration constructorDeclaration,
String referenceName,
String value)
ConstructorDeclarationconstructorDeclaration - referenceName - value - org.kie.pmml.api.exceptions.KiePMMLException - if the given parameter is not foundpublic static void setExplicitConstructorInvocationStmtArgument(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt constructorInvocationStmt,
String parameterName,
String value)
ExplicitConstructorInvocationStmtconstructorInvocationStmt - parameterName - value - org.kie.pmml.api.exceptions.KiePMMLException - if the given parameter is not foundpublic static com.github.javaparser.ast.stmt.BlockStmt getInitializerBlockStmt(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration classOrInterfaceDeclaration)
BlockStmt from the given ClassOrInterfaceDeclarationclassOrInterfaceDeclaration - org.kie.pmml.api.exceptions.KiePMMLException - if none is foundpublic static com.github.javaparser.ast.body.InitializerDeclaration getInitializerDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration classOrInterfaceDeclaration)
InitializerDeclaration from the given ClassOrInterfaceDeclarationclassOrInterfaceDeclaration - org.kie.pmml.api.exceptions.KiePMMLException - if none is foundpublic static Optional<com.github.javaparser.ast.expr.NameExpr> getExplicitConstructorInvocationParameter(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt constructorInvocationStmt, String parameterName)
Optional<NameExpr> from the given ExplicitConstructorInvocationStmtconstructorInvocationStmt - parameterName - Optional<NameExpr> with the found NameExpr, or Optional.empty()
if none is foundpublic static Optional<com.github.javaparser.ast.expr.MethodReferenceExpr> getExplicitConstructorInvocationMethodReference(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt constructorInvocationStmt, String typeName)
Optional<MethodReferenceExpr> from the given
ExplicitConstructorInvocationStmtconstructorInvocationStmt - typeName - Optional<MethodReferenceExpr> with the found MethodReferenceExpr, or
Optional.empty() if none is foundpublic static com.github.javaparser.ast.stmt.BlockStmt getMethodDeclarationBlockStmt(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration classOrInterfaceDeclaration,
String methodName)
BlockStmt for the method methodName from the given ClassOrInterfaceDeclarationclassOrInterfaceDeclaration - methodName - org.kie.pmml.api.exceptions.KiePMMLException - if none is foundpublic static Optional<com.github.javaparser.ast.body.MethodDeclaration> getMethodDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration classOrInterfaceDeclaration, String methodName)
Optional<MethodDeclaration> with the first method methodName from
the given ClassOrInterfaceDeclarationclassOrInterfaceDeclaration - methodName - Optional<MethodDeclaration> with the first found MethodDeclaration, or
Optional.empty() if no match
has been foundpublic static com.github.javaparser.ast.body.MethodDeclaration addMethod(com.github.javaparser.ast.body.MethodDeclaration methodTemplate,
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration tableTemplate,
String methodName)
MethodDeclaration to the classmethodTemplate - tableTemplate - methodName - public static void setVariableDeclaratorValue(com.github.javaparser.ast.stmt.BlockStmt body,
String variableDeclaratorName,
com.github.javaparser.ast.expr.Expression value)
BlockStmt
It throws KiePMMLException if variable is not foundbody - variableDeclaratorName - value - KiePMMLException - if VariableDeclarator with given variableDeclaratorName is not
foundpublic static Optional<com.github.javaparser.ast.body.VariableDeclarator> getVariableDeclarator(com.github.javaparser.ast.body.MethodDeclaration methodDeclaration, String variableName)
Optional<VariableDeclarator> with the first variable variableName
from the given MethodDeclarationmethodDeclaration - variableName - Optional<VariableDeclarator> with the first found VariableDeclarator,
or Optional.empty() if no match
has been foundpublic static Optional<com.github.javaparser.ast.body.VariableDeclarator> getVariableDeclarator(com.github.javaparser.ast.stmt.BlockStmt body, String variableName)
Optional<VariableDeclarator> with the first variable variableName
from the given BlockStmtbody - variableName - Optional<VariableDeclarator> with the first found VariableDeclarator,
or Optional.empty() if no match
has been foundpublic static com.github.javaparser.ast.expr.Expression getExpressionForObject(Object source)
public static List<com.github.javaparser.ast.expr.NameExpr> getNameExprsFromBlock(com.github.javaparser.ast.stmt.BlockStmt toRead, String exprName)
lit<NameExpr> with all the instances of the given exprNametoRead - exprName - public static com.github.javaparser.ast.expr.AssignExpr assignExprFrom(String target, com.github.javaparser.ast.expr.Expression value)
AssignExpr from a target name and a generic Expression.target - String containing the name to assign the expression tovalue - the value to be assignedAssignExprpublic static com.github.javaparser.ast.expr.AssignExpr assignExprFrom(String target, Enum<?> value)
AssignExpr from a target name and an enum literal.target - String containing the name to assign the expression tovalue - the enum value to be assignedAssignExprpublic static com.github.javaparser.ast.expr.AssignExpr assignExprFrom(String target, String value)
AssignExpr from a target name and String literal.public static com.github.javaparser.ast.expr.Expression literalExprFrom(Enum<?> input)
Expression containing an enum literal.input - the enum value to be assignedExpressionpublic static com.github.javaparser.ast.expr.Expression literalExprFrom(String input)
Expression containing an String.input - the String value to be assignedExpressionpublic static com.github.javaparser.ast.expr.MethodCallExpr methodCallExprFrom(String scope, String name, com.github.javaparser.ast.expr.Expression... arguments)
MethodCallExpr from scope, name and arguments.scope - the scope of the method to callname - the name of the method to callarguments - vararg list of Expression argumentsMethodCallExprpublic static void replaceStringLiteralExpressionInStatement(com.github.javaparser.ast.stmt.Statement container,
String toReplace,
String replacement)
StringLiteralExpresions in the given Statementcontainer - toReplace - replacement - public static void replaceNodesInStatement(com.github.javaparser.ast.stmt.Statement container,
List<CommonCodegenUtils.ReplacementTupla> replacementTuplas)
Nodes in the given Statementcontainer - replacementTuplas - public static void replaceNodeInStatement(com.github.javaparser.ast.stmt.Statement container,
CommonCodegenUtils.ReplacementTupla replacementTupla)
Node in the given Statementcontainer - replacementTupla - public static void addMethodDeclarationsToClass(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration classOrInterfaceDeclaration,
List<com.github.javaparser.ast.body.MethodDeclaration> toAdd)
MethodDeclarations to the given ClassOrInterfaceDeclarationclassOrInterfaceDeclaration - toAdd - public static void addMethodDeclarationToClass(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration classOrInterfaceDeclaration,
com.github.javaparser.ast.body.MethodDeclaration toAdd)
MethodDeclaration to the given ClassOrInterfaceDeclarationclassOrInterfaceDeclaration - toAdd - public static com.github.javaparser.ast.expr.Expression getVariableInitializer(com.github.javaparser.ast.body.MethodDeclaration methodDeclaration,
String variableName)
MethodDeclarationpublic static Optional<com.github.javaparser.ast.expr.Expression> getOptionalVariableInitializer(com.github.javaparser.ast.body.MethodDeclaration methodDeclaration, String variableName)
MethodDeclarationpublic static Optional<com.github.javaparser.ast.expr.Expression> getVariableInitializer(com.github.javaparser.ast.stmt.BlockStmt blockStmt, String variableName)
MethodDeclarationpublic static void replaceNameExprWithNullInStatement(com.github.javaparser.ast.stmt.Statement container,
List<com.github.javaparser.ast.expr.NameExpr> toReplace)
List<NameExpr>s in the given Statement with NullLiteralExprcontainer - toReplace - Copyright © 2001–2021 JBoss by Red Hat. All rights reserved.