use of com.github.javaparser.ast.expr.MethodReferenceExpr in project drools by kiegroup.
the class KiePMMLTreeModelFactoryTest method setConstructor.
@Test
public void setConstructor() {
String className = getSanitizedClassName(treeModel1.getModelName());
CompilationUnit cloneCU = JavaParserUtils.getKiePMMLModelCompilationUnit(className, PACKAGE_NAME, KIE_PMML_TREE_MODEL_TEMPLATE_JAVA, KIE_PMML_TREE_MODEL_TEMPLATE);
ClassOrInterfaceDeclaration modelTemplate = cloneCU.getClassByName(className).orElseThrow(() -> new KiePMMLException(MAIN_CLASS_NOT_FOUND + ": " + className));
String targetField = "whatIdo";
String fullNodeClassName = "full.Node.ClassName";
CommonCompilationDTO<TreeModel> source = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml1, treeModel1, new HasClassLoaderMock());
KiePMMLTreeModelFactory.setConstructor(TreeCompilationDTO.fromCompilationDTO(source), modelTemplate, fullNodeClassName);
ConstructorDeclaration constructorDeclaration = modelTemplate.getDefaultConstructor().orElseThrow(() -> new KiePMMLInternalException(String.format(MISSING_DEFAULT_CONSTRUCTOR, modelTemplate.getName()))).clone();
BlockStmt body = constructorDeclaration.getBody();
// targetField
Optional<AssignExpr> optRetrieved = CommonCodegenUtils.getAssignExpression(body, "targetField");
assertTrue(optRetrieved.isPresent());
AssignExpr retrieved = optRetrieved.get();
Expression initializer = retrieved.getValue();
assertTrue(initializer instanceof StringLiteralExpr);
String expected = String.format("\"%s\"", targetField);
assertEquals(expected, initializer.toString());
// miningFunction
optRetrieved = CommonCodegenUtils.getAssignExpression(body, "miningFunction");
assertTrue(optRetrieved.isPresent());
retrieved = optRetrieved.get();
initializer = retrieved.getValue();
assertTrue(initializer instanceof NameExpr);
MINING_FUNCTION miningFunction = MINING_FUNCTION.byName(treeModel1.getMiningFunction().value());
expected = miningFunction.getClass().getName() + "." + miningFunction.name();
assertEquals(expected, initializer.toString());
// pmmlMODEL
optRetrieved = CommonCodegenUtils.getAssignExpression(body, "pmmlMODEL");
assertTrue(optRetrieved.isPresent());
retrieved = optRetrieved.get();
initializer = retrieved.getValue();
assertTrue(initializer instanceof NameExpr);
expected = PMML_MODEL.TREE_MODEL.getClass().getName() + "." + PMML_MODEL.TREE_MODEL.name();
assertEquals(expected, initializer.toString());
// nodeFunction
optRetrieved = CommonCodegenUtils.getAssignExpression(body, "nodeFunction");
assertTrue(optRetrieved.isPresent());
retrieved = optRetrieved.get();
initializer = retrieved.getValue();
assertTrue(initializer instanceof MethodReferenceExpr);
expected = fullNodeClassName;
assertEquals(expected, ((MethodReferenceExpr) initializer).getScope().toString());
expected = "evaluateNode";
assertEquals(expected, ((MethodReferenceExpr) initializer).getIdentifier());
}
use of com.github.javaparser.ast.expr.MethodReferenceExpr in project drools by kiegroup.
the class KiePMMLRegressionTableFactory method getResultUpdaterSupportedExpression.
/**
* Create a <b>resultUpdater</b> <code>CastExpr</code>
* @param normalizationMethod
* @return
*/
static MethodReferenceExpr getResultUpdaterSupportedExpression(final RegressionModel.NormalizationMethod normalizationMethod) {
final String thisExpressionMethodName = String.format("update%sResult", normalizationMethod.name());
final CastExpr castExpr = new CastExpr();
final String doubleClassName = Double.class.getSimpleName();
final ClassOrInterfaceType consumerType = getTypedClassOrInterfaceTypeByTypeNames(SerializableFunction.class.getCanonicalName(), Arrays.asList(doubleClassName, doubleClassName));
castExpr.setType(consumerType);
castExpr.setExpression(KiePMMLRegressionTable.class.getSimpleName());
final MethodReferenceExpr toReturn = new MethodReferenceExpr();
toReturn.setScope(castExpr);
toReturn.setIdentifier(thisExpressionMethodName);
return toReturn;
}
use of com.github.javaparser.ast.expr.MethodReferenceExpr in project checker-framework by typetools.
the class JointJavacJavaParserVisitor method visitMemberReference.
@Override
public Void visitMemberReference(MemberReferenceTree javacTree, Node javaParserNode) {
MethodReferenceExpr node = castNode(MethodReferenceExpr.class, javaParserNode, javacTree);
processMemberReference(javacTree, node);
if (node.getScope().isTypeExpr()) {
javacTree.getQualifierExpression().accept(this, node.getScope().asTypeExpr().getType());
} else {
javacTree.getQualifierExpression().accept(this, node.getScope());
}
assert (javacTree.getTypeArguments() != null) == node.getTypeArguments().isPresent();
if (javacTree.getTypeArguments() != null) {
visitLists(javacTree.getTypeArguments(), node.getTypeArguments().get());
}
return null;
}
Aggregations