Search in sources :

Example 6 with FunctionInvocationNode

use of org.kie.dmn.feel.lang.ast.FunctionInvocationNode in project drools by kiegroup.

the class FEELParserTest method testLogicalNegation.

@Test
public void testLogicalNegation() {
    String inputExpression = "not ( true )";
    BaseNode neg = parse(inputExpression);
    assertThat(neg, is(instanceOf(FunctionInvocationNode.class)));
    assertThat(neg.getResultType(), is(BuiltInType.UNKNOWN));
    assertThat(neg.getText(), is("not ( true )"));
    FunctionInvocationNode not = (FunctionInvocationNode) neg;
    assertThat(not.getParams().getElements().get(0), is(instanceOf(BooleanNode.class)));
    assertThat(not.getParams().getElements().get(0).getResultType(), is(BuiltInType.BOOLEAN));
    assertThat(not.getParams().getElements().get(0).getText(), is("true"));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) FunctionInvocationNode(org.kie.dmn.feel.lang.ast.FunctionInvocationNode) Test(org.junit.Test)

Example 7 with FunctionInvocationNode

use of org.kie.dmn.feel.lang.ast.FunctionInvocationNode in project drools by kiegroup.

the class FEELParserTest method testFunctionInvocationPositionalParams.

@Test
public void testFunctionInvocationPositionalParams() {
    String inputExpression = "my.test.Function( x+10, \"foo\" )";
    BaseNode functionBase = parse(inputExpression);
    assertThat(functionBase, is(instanceOf(FunctionInvocationNode.class)));
    assertThat(functionBase.getText(), is(inputExpression));
    FunctionInvocationNode function = (FunctionInvocationNode) functionBase;
    assertThat(function.getName(), is(instanceOf(QualifiedNameNode.class)));
    assertThat(function.getName().getText(), is("my.test.Function"));
    assertThat(function.getParams(), is(instanceOf(ListNode.class)));
    assertThat(function.getParams().getElements().size(), is(2));
    assertThat(function.getParams().getElements().get(0), is(instanceOf(InfixOpNode.class)));
    assertThat(function.getParams().getElements().get(1), is(instanceOf(StringNode.class)));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) FunctionInvocationNode(org.kie.dmn.feel.lang.ast.FunctionInvocationNode) Test(org.junit.Test)

Example 8 with FunctionInvocationNode

use of org.kie.dmn.feel.lang.ast.FunctionInvocationNode in project drools by kiegroup.

the class FEELParserTest method testFunctionInvocationWithExpressionParameters.

@Test
public void testFunctionInvocationWithExpressionParameters() {
    String inputExpression = "date and time( date(\"2016-07-29\"), time(\"19:47:53\") )";
    BaseNode functionBase = parse(inputExpression);
    assertThat(functionBase, is(instanceOf(FunctionInvocationNode.class)));
    assertThat(functionBase.getText(), is(inputExpression));
    FunctionInvocationNode function = (FunctionInvocationNode) functionBase;
    assertThat(function.getName(), is(instanceOf(NameRefNode.class)));
    assertThat(function.getName().getText(), is("date and time"));
    assertThat(function.getParams(), is(instanceOf(ListNode.class)));
    assertThat(function.getParams().getElements().size(), is(2));
    assertThat(function.getParams().getElements().get(0), is(instanceOf(FunctionInvocationNode.class)));
    assertThat(function.getParams().getElements().get(1), is(instanceOf(FunctionInvocationNode.class)));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) FunctionInvocationNode(org.kie.dmn.feel.lang.ast.FunctionInvocationNode) Test(org.junit.Test)

Example 9 with FunctionInvocationNode

use of org.kie.dmn.feel.lang.ast.FunctionInvocationNode in project kie-wb-common by kiegroup.

the class DMNParseServiceImpl method parseRangeValue.

private String parseRangeValue(final BaseNode baseNode) {
    if (baseNode instanceof FunctionInvocationNode) {
        final FunctionInvocationNode functionInvocation = (FunctionInvocationNode) baseNode;
        final String functionName = functionInvocation.getName().getText();
        final String functionParams = functionInvocation.getParams().getText();
        return functionName + "(" + functionParams + ")";
    } else {
        return baseNode.getText();
    }
}
Also used : FunctionInvocationNode(org.kie.dmn.feel.lang.ast.FunctionInvocationNode)

Example 10 with FunctionInvocationNode

use of org.kie.dmn.feel.lang.ast.FunctionInvocationNode in project kie-wb-common by kiegroup.

the class TypeStackUtils method getTypeStack.

private List<Type> getTypeStack(final ASTNode currentNode, final ASTNode nextNode, final Position position, final boolean isListOfParameters, final boolean isParentEligible) {
    final List<Type> typeStack = new ArrayList<>();
    if (currentNode == null) {
        return typeStack;
    }
    final Type type = getType(currentNode);
    final boolean isNextListOfParameters = currentNode instanceof FunctionInvocationNode;
    final boolean isEligibleType = isEligibleType(currentNode, nextNode, position, isParentEligible) && !isListOfParameters;
    if (isEligibleType) {
        typeStack.add(type);
    }
    try {
        forEach(getChildren(currentNode), (current, next) -> {
            final boolean isParentEligibleType = isListOfParameters ? isParentEligible : isEligibleType;
            typeStack.addAll(getTypeStack(current, next, position, isNextListOfParameters, isParentEligibleType));
        });
    } catch (final Exception e) {
    // Ignore errors during node inspection.
    }
    return typeStack;
}
Also used : BuiltInType(org.kie.dmn.feel.lang.types.BuiltInType) Type(org.kie.dmn.feel.lang.Type) ArrayList(java.util.ArrayList) FunctionInvocationNode(org.kie.dmn.feel.lang.ast.FunctionInvocationNode)

Aggregations

FunctionInvocationNode (org.kie.dmn.feel.lang.ast.FunctionInvocationNode)11 Test (org.junit.Test)9 BaseNode (org.kie.dmn.feel.lang.ast.BaseNode)7 CompiledExpression (org.kie.dmn.feel.lang.CompiledExpression)2 CompilerContext (org.kie.dmn.feel.lang.CompilerContext)2 ASTNode (org.kie.dmn.feel.lang.ast.ASTNode)2 NamedParameterNode (org.kie.dmn.feel.lang.ast.NamedParameterNode)2 ArrayList (java.util.ArrayList)1 Ignore (org.junit.Ignore)1 Type (org.kie.dmn.feel.lang.Type)1 ListNode (org.kie.dmn.feel.lang.ast.ListNode)1 BuiltInType (org.kie.dmn.feel.lang.types.BuiltInType)1