public class CommonCodegenUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
OPTIONAL_FILTERED_KIEPMMLNAMEVALUE_NAME |
| Modifier and Type | Method and Description |
|---|---|
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 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.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.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 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.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 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 |
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 |
setExplicitConstructorInvocationArgument(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt constructorInvocationStmt,
String parameterName,
String value)
Return an
Optional<NameExpr> from the given ExplicitConstructorInvocationStmt |
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)
Optionalexpression, where kiePMMLNameValueListParam is the name of thekiePMMLNameValue = (kiePMMLNameValueListParam) .stream() .filter((KiePMMLNameValue kpmmlnv) -> Objects.equals("(fieldNameToRef)", kpmmlnv.getName())) .findFirst();
List<KiePMMLNameValue> parameter, and
fieldNameToRef is the name of the field to find, in the containing methodkiePMMLNameValueListParam - 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 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 methodAritymethodName - 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 setExplicitConstructorInvocationArgument(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt constructorInvocationStmt,
String parameterName,
String value)
Optional<NameExpr> from the given ExplicitConstructorInvocationStmtconstructorInvocationStmt - parameterName - value - public 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.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 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 foundCopyright © 2001–2020 JBoss by Red Hat. All rights reserved.