Search in sources :

Example 6 with MethodReferenceExpr

use of com.github.javaparser.ast.expr.MethodReferenceExpr in project drools by kiegroup.

the class Expressions method genContextType.

public static Expression genContextType(Map<String, Expression> fields) {
    final ClassOrInterfaceType sie = parseClassOrInterfaceType(java.util.AbstractMap.SimpleImmutableEntry.class.getCanonicalName());
    sie.setTypeArguments(parseClassOrInterfaceType(String.class.getCanonicalName()), parseClassOrInterfaceType(org.kie.dmn.feel.lang.Type.class.getCanonicalName()));
    List<Expression> entryParams = fields.entrySet().stream().map(e -> new ObjectCreationExpr(null, sie, new NodeList<>(stringLiteral(e.getKey()), e.getValue()))).collect(Collectors.toList());
    MethodCallExpr mOf = new MethodCallExpr(new NameExpr(java.util.stream.Stream.class.getCanonicalName()), "of");
    entryParams.forEach(mOf::addArgument);
    MethodCallExpr mCollect = new MethodCallExpr(mOf, "collect");
    mCollect.addArgument(new MethodCallExpr(new NameExpr(java.util.stream.Collectors.class.getCanonicalName()), "toMap").addArgument(new MethodReferenceExpr(new NameExpr(java.util.Map.Entry.class.getCanonicalName()), new NodeList<>(), "getKey")).addArgument(new MethodReferenceExpr(new NameExpr(java.util.Map.Entry.class.getCanonicalName()), new NodeList<>(), "getValue")));
    return new ObjectCreationExpr(null, MapBackedTypeT, new NodeList<>(stringLiteral("[anonymous]"), mCollect));
}
Also used : StaticJavaParser.parseClassOrInterfaceType(com.github.javaparser.StaticJavaParser.parseClassOrInterfaceType) ClassExpr(com.github.javaparser.ast.expr.ClassExpr) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) LambdaExpr(com.github.javaparser.ast.expr.LambdaExpr) ExpressionStmt(com.github.javaparser.ast.stmt.ExpressionStmt) MapBackedType(org.kie.dmn.feel.lang.impl.MapBackedType) GenFnType(org.kie.dmn.feel.lang.types.GenFnType) UnaryTestNode(org.kie.dmn.feel.lang.ast.UnaryTestNode) Parameter(com.github.javaparser.ast.body.Parameter) QuantifiedExpressionNode(org.kie.dmn.feel.lang.ast.QuantifiedExpressionNode) CastExpr(com.github.javaparser.ast.expr.CastExpr) Type(com.github.javaparser.ast.type.Type) ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) NamedParameter(org.kie.dmn.feel.lang.impl.NamedParameter) Map(java.util.Map) Expression(com.github.javaparser.ast.expr.Expression) NodeList(com.github.javaparser.ast.NodeList) UnknownType(com.github.javaparser.ast.type.UnknownType) BuiltInTypeT(org.kie.dmn.feel.codegen.feel11.Constants.BuiltInTypeT) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) BigDecimalT(org.kie.dmn.feel.codegen.feel11.Constants.BigDecimalT) RangeNode(org.kie.dmn.feel.lang.ast.RangeNode) StaticJavaParser.parseExpression(com.github.javaparser.StaticJavaParser.parseExpression) NameExpr(com.github.javaparser.ast.expr.NameExpr) Collectors(java.util.stream.Collectors) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) EnclosedExpr(com.github.javaparser.ast.expr.EnclosedExpr) MethodReferenceExpr(com.github.javaparser.ast.expr.MethodReferenceExpr) List(java.util.List) InfixOpNode(org.kie.dmn.feel.lang.ast.InfixOpNode) FieldDeclaration(com.github.javaparser.ast.body.FieldDeclaration) GenListType(org.kie.dmn.feel.lang.types.GenListType) BaseFEELFunction(org.kie.dmn.feel.runtime.functions.BaseFEELFunction) EvalHelper(org.kie.dmn.feel.util.EvalHelper) ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) Collectors(java.util.stream.Collectors) NodeList(com.github.javaparser.ast.NodeList) NameExpr(com.github.javaparser.ast.expr.NameExpr) StaticJavaParser.parseClassOrInterfaceType(com.github.javaparser.StaticJavaParser.parseClassOrInterfaceType) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) MethodReferenceExpr(com.github.javaparser.ast.expr.MethodReferenceExpr) Expression(com.github.javaparser.ast.expr.Expression) StaticJavaParser.parseExpression(com.github.javaparser.StaticJavaParser.parseExpression) Map(java.util.Map) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Example 7 with MethodReferenceExpr

use of com.github.javaparser.ast.expr.MethodReferenceExpr in project drools by kiegroup.

the class KiePMMLNodeFactory method getEvaluateNodeMethodReference.

/**
 * Return a <b>evaluateNode</b> <code>MethodReferenceExpr</code>
 * <p>
 *     <code>{_fullNodeClassName_}::evaluateNode</code>
 * </p>
 *
 * @param fullNodeClassName
 * @return
 */
static MethodReferenceExpr getEvaluateNodeMethodReference(final String fullNodeClassName) {
    MethodReferenceExpr toAdd = new MethodReferenceExpr();
    toAdd.setScope(new NameExpr(fullNodeClassName));
    toAdd.setIdentifier(EVALUATE_NODE);
    return toAdd;
}
Also used : NameExpr(com.github.javaparser.ast.expr.NameExpr) MethodReferenceExpr(com.github.javaparser.ast.expr.MethodReferenceExpr)

Example 8 with MethodReferenceExpr

use of com.github.javaparser.ast.expr.MethodReferenceExpr in project drools by kiegroup.

the class KiePMMLNodeFactoryTest method getEvaluateNodeMethodReference.

@Test
public void getEvaluateNodeMethodReference() {
    String fullNodeClassName = "full.node.NodeClassName";
    MethodReferenceExpr retrieved = KiePMMLNodeFactory.getEvaluateNodeMethodReference(fullNodeClassName);
    assertEquals(fullNodeClassName, retrieved.getScope().toString());
    assertEquals(EVALUATE_NODE, retrieved.getIdentifier());
}
Also used : MethodReferenceExpr(com.github.javaparser.ast.expr.MethodReferenceExpr) Test(org.junit.Test)

Example 9 with MethodReferenceExpr

use of com.github.javaparser.ast.expr.MethodReferenceExpr in project checker-framework by typetools.

the class DoubleJavaParserVisitor method visit.

@Override
public void visit(final MethodReferenceExpr node1, final Node other) {
    MethodReferenceExpr node2 = (MethodReferenceExpr) other;
    defaultAction(node1, node2);
    node1.getScope().accept(this, node2.getScope());
    node1.getTypeArguments().ifPresent(l -> visitLists(l, node2.getTypeArguments().get()));
}
Also used : MethodReferenceExpr(com.github.javaparser.ast.expr.MethodReferenceExpr)

Example 10 with MethodReferenceExpr

use of com.github.javaparser.ast.expr.MethodReferenceExpr in project drools by kiegroup.

the class AccumulateInline method addAccumulateClassInitializationToMethod.

private void addAccumulateClassInitializationToMethod(MethodCallExpr accumulateDSL, String identifier) {
    this.packageModel.addGeneratedPOJO(accumulateInlineClass);
    final MethodCallExpr functionDSL = createDslTopLevelMethod(ACC_FUNCTION_CALL);
    functionDSL.addArgument(new MethodReferenceExpr(new NameExpr(accumulateInlineClassName), new NodeList<>(), "new"));
    functionDSL.addArgument(context.getVarExpr(identifier));
    final String bindingId = this.basePattern.getIdentifier();
    final MethodCallExpr asDSL = new MethodCallExpr(functionDSL, BIND_AS_CALL);
    asDSL.addArgument(context.getVarExpr(bindingId));
    accumulateDSL.addArgument(asDSL);
}
Also used : NodeList(com.github.javaparser.ast.NodeList) NameExpr(com.github.javaparser.ast.expr.NameExpr) MethodReferenceExpr(com.github.javaparser.ast.expr.MethodReferenceExpr) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Aggregations

MethodReferenceExpr (com.github.javaparser.ast.expr.MethodReferenceExpr)18 NameExpr (com.github.javaparser.ast.expr.NameExpr)10 Expression (com.github.javaparser.ast.expr.Expression)9 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)6 Test (org.junit.Test)6 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)5 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)5 KiePMMLException (org.kie.pmml.api.exceptions.KiePMMLException)5 NodeList (com.github.javaparser.ast.NodeList)4 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)4 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)4 StaticJavaParser.parseClassOrInterfaceType (com.github.javaparser.StaticJavaParser.parseClassOrInterfaceType)3 ConstructorDeclaration (com.github.javaparser.ast.body.ConstructorDeclaration)3 Parameter (com.github.javaparser.ast.body.Parameter)3 AssignExpr (com.github.javaparser.ast.expr.AssignExpr)3 CastExpr (com.github.javaparser.ast.expr.CastExpr)3 NullLiteralExpr (com.github.javaparser.ast.expr.NullLiteralExpr)3 ObjectCreationExpr (com.github.javaparser.ast.expr.ObjectCreationExpr)3 TypeExpr (com.github.javaparser.ast.expr.TypeExpr)3 ExplicitConstructorInvocationStmt (com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt)3