use of com.github.javaparser.ast.expr.TypeExpr in project drools by kiegroup.
the class CommonCodegenUtils method setConstructorDeclarationReferenceArgument.
/**
* Set the <b>value</b> of the given <b>parameterName</b> in the given <code>ConstructorDeclaration</code>
* @param constructorDeclaration
* @param referenceName
* @param value
* @throws KiePMMLException if the given parameter is not found
*/
public static void setConstructorDeclarationReferenceArgument(final ConstructorDeclaration constructorDeclaration, final String referenceName, final String value) {
final BlockStmt body = constructorDeclaration.getBody();
final ExplicitConstructorInvocationStmt superStatement = CommonCodegenUtils.getExplicitConstructorInvocationStmt(body).orElseThrow(() -> new KiePMMLException(String.format(MISSING_CONSTRUCTOR_IN_BODY, body)));
final MethodReferenceExpr methodReferenceExpr = getExplicitConstructorInvocationMethodReference(superStatement, referenceName).orElseThrow(() -> new KiePMMLException(String.format(MISSING_PARAMETER_IN_CONSTRUCTOR_INVOCATION, referenceName, constructorDeclaration)));
if (value != null) {
methodReferenceExpr.setScope(new TypeExpr(parseClassOrInterfaceType(value)));
} else {
superStatement.getArguments().replace(methodReferenceExpr, new NullLiteralExpr());
}
}
use of com.github.javaparser.ast.expr.TypeExpr in project drools by kiegroup.
the class KiePMMLNodeFactory method populateEvaluateNodeWithNodeFunctions.
/**
* Set the <b>nodeFunctions</b> <code>VariableDeclarator</code> initializer of the given <code>BlockStmt</code> with <code>MethodReferenceExpr</code>s to
* <b>nested</b> <b>evaluateNode</b> methods.
*
* If <b>nestedNodesFullClasses</b>, set an empty list
* <p>
* <code>Object nodeFunctions = java.util.Collections.emptyList();</code>
* </p>
*
* otherwise, an <code>ArrayList</code> of related references
* <p>
* <code>Object nodeFunctions = java.util.Arrays.asList(full.node.NodeClassName0::evaluateNode, full.node.NodeClassName1::evaluateNode);</code>
* </p>
*
* @param toPopulate
* @param nestedNodesFullClasses
*/
static void populateEvaluateNodeWithNodeFunctions(final BlockStmt toPopulate, final List<String> nestedNodesFullClasses) {
final MethodCallExpr valuesInit = new MethodCallExpr();
if (nestedNodesFullClasses.isEmpty()) {
valuesInit.setScope(new TypeExpr(parseClassOrInterfaceType(Collections.class.getName())));
valuesInit.setName(EMPTY_LIST);
} else {
final NodeList<Expression> methodReferenceExprs = NodeList.nodeList(nestedNodesFullClasses.stream().map(KiePMMLNodeFactory::getEvaluateNodeMethodReference).collect(Collectors.toList()));
valuesInit.setScope(new TypeExpr(parseClassOrInterfaceType(Arrays.class.getName())));
valuesInit.setName(AS_LIST);
valuesInit.setArguments(methodReferenceExprs);
}
CommonCodegenUtils.setVariableDeclaratorValue(toPopulate, NODE_FUNCTIONS, valuesInit);
}
use of com.github.javaparser.ast.expr.TypeExpr in project drools by kiegroup.
the class KiePMMLNodeFactoryTest method mergeNodeReferences.
@Test
public void mergeNodeReferences() {
KiePMMLNodeFactory.NodeNamesDTO nodeNamesDTO = new KiePMMLNodeFactory.NodeNamesDTO(nodeRoot, createNodeClassName(), null, 1.0);
KiePMMLNodeFactory.JavaParserDTO toPopulate = new KiePMMLNodeFactory.JavaParserDTO(nodeNamesDTO, PACKAGE_NAME);
Node nestedNode = nodeRoot.getNodes().get(0);
// Creating evaluateNodeInitializer
String nestedNodeClassName = nodeNamesDTO.childrenNodes.get(nestedNode);
String fullNestedNodeClassName = String.format(PACKAGE_CLASS_TEMPLATE, PACKAGE_NAME, nestedNodeClassName);
final NodeList<Expression> methodReferenceExprs = NodeList.nodeList(KiePMMLNodeFactory.getEvaluateNodeMethodReference(fullNestedNodeClassName));
MethodReferenceExpr evaluateNodeReference = new MethodReferenceExpr();
evaluateNodeReference.setScope(new NameExpr(fullNestedNodeClassName));
evaluateNodeReference.setIdentifier(EVALUATE_NODE);
MethodCallExpr evaluateNodeInitializer = new MethodCallExpr();
evaluateNodeInitializer.setScope(new TypeExpr(parseClassOrInterfaceType(Arrays.class.getName())));
evaluateNodeInitializer.setName(AS_LIST);
evaluateNodeInitializer.setArguments(methodReferenceExprs);
//
KiePMMLNodeFactory.NodeNamesDTO nestedNodeNamesDTO = new KiePMMLNodeFactory.NodeNamesDTO(nestedNode, nodeNamesDTO.getNestedNodeClassName(nestedNode), nodeNamesDTO.nodeClassName, nodeNamesDTO.missingValuePenalty);
KiePMMLNodeFactory.mergeNodeReferences(toPopulate, nestedNodeNamesDTO, evaluateNodeInitializer);
MethodReferenceExpr retrieved = evaluateNodeInitializer.getArguments().get(0).asMethodReferenceExpr();
String expected = toPopulate.nodeClassName;
assertEquals(expected, retrieved.getScope().asNameExpr().toString());
expected = EVALUATE_NODE + nestedNodeClassName;
assertEquals(expected, retrieved.getIdentifier());
}
use of com.github.javaparser.ast.expr.TypeExpr in project checker-framework by typetools.
the class DoubleJavaParserVisitor method visit.
@Override
public void visit(final TypeExpr node1, final Node other) {
TypeExpr node2 = (TypeExpr) other;
defaultAction(node1, node2);
node1.getType().accept(this, node2.getType());
}
Aggregations