Search in sources :

Example 1 with PathExpressionNode

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

the class FEELParserTest method testContextPathExpression.

@Test
public void testContextPathExpression() {
    String inputExpression = "{ x : \"foo\" }.x";
    BaseNode pathBase = parse(inputExpression);
    assertThat(pathBase, is(instanceOf(PathExpressionNode.class)));
    assertThat(pathBase.getText(), is(inputExpression));
    assertThat(pathBase.getResultType(), is(BuiltInType.STRING));
    PathExpressionNode pathExpr = (PathExpressionNode) pathBase;
    assertThat(pathExpr.getExpression(), is(instanceOf(ContextNode.class)));
    assertThat(pathExpr.getExpression().getText(), is("{ x : \"foo\" }"));
    assertThat(pathExpr.getName(), is(instanceOf(NameRefNode.class)));
    assertThat(pathExpr.getName().getText(), is("x"));
}
Also used : PathExpressionNode(org.kie.dmn.feel.lang.ast.PathExpressionNode) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) Test(org.junit.Test)

Example 2 with PathExpressionNode

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

the class ASTCompilerVisitor method visit.

@Override
public DirectCompilerResult visit(PathExpressionNode n) {
    DirectCompilerResult expr = n.getExpression().accept(this);
    BaseNode nameNode = n.getName();
    if (nameNode instanceof QualifiedNameNode) {
        QualifiedNameNode qualifiedNameNode = (QualifiedNameNode) n.getName();
        List<Expression> exprs = qualifiedNameNode.getParts().stream().map(name -> new StringLiteralExpr(name.getText())).collect(Collectors.toList());
        return DirectCompilerResult.of(Expressions.path(expr.getExpression(), exprs), // here we could still try to infer the result type, but presently use ANY
        BuiltInType.UNKNOWN).withFD(expr);
    } else {
        return DirectCompilerResult.of(Expressions.path(expr.getExpression(), new StringLiteralExpr(nameNode.getText())), // here we could still try to infer the result type, but presently use ANY
        BuiltInType.UNKNOWN).withFD(expr);
    }
}
Also used : QuantifiedExpressionNode(org.kie.dmn.feel.lang.ast.QuantifiedExpressionNode) SimpleType(org.kie.dmn.feel.lang.SimpleType) Visitor(org.kie.dmn.feel.lang.ast.Visitor) ListNode(org.kie.dmn.feel.lang.ast.ListNode) ContextNode(org.kie.dmn.feel.lang.ast.ContextNode) FunctionInvocationNode(org.kie.dmn.feel.lang.ast.FunctionInvocationNode) NullLiteralExpr(com.github.javaparser.ast.expr.NullLiteralExpr) InNode(org.kie.dmn.feel.lang.ast.InNode) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) Duration(java.time.Duration) Map(java.util.Map) Msg(org.kie.dmn.feel.util.Msg) NumberNode(org.kie.dmn.feel.lang.ast.NumberNode) Expression(com.github.javaparser.ast.expr.Expression) BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr) ForExpressionNode(org.kie.dmn.feel.lang.ast.ForExpressionNode) IfExpressionNode(org.kie.dmn.feel.lang.ast.IfExpressionNode) UnknownType(com.github.javaparser.ast.type.UnknownType) DashNode(org.kie.dmn.feel.lang.ast.DashNode) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) BuiltInType(org.kie.dmn.feel.lang.types.BuiltInType) TypeNode(org.kie.dmn.feel.lang.ast.TypeNode) ASTNode(org.kie.dmn.feel.lang.ast.ASTNode) Collectors(java.util.stream.Collectors) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) EnclosedExpr(com.github.javaparser.ast.expr.EnclosedExpr) List(java.util.List) StaticJavaParser(com.github.javaparser.StaticJavaParser) InfixOpNode(org.kie.dmn.feel.lang.ast.InfixOpNode) QualifiedNameNode(org.kie.dmn.feel.lang.ast.QualifiedNameNode) Entry(java.util.Map.Entry) NullNode(org.kie.dmn.feel.lang.ast.NullNode) CTypeNode(org.kie.dmn.feel.lang.ast.CTypeNode) FieldAccessExpr(com.github.javaparser.ast.expr.FieldAccessExpr) FunctionTypeNode(org.kie.dmn.feel.lang.ast.FunctionTypeNode) ChronoPeriod(java.time.chrono.ChronoPeriod) FunctionDefNode(org.kie.dmn.feel.lang.ast.FunctionDefNode) EvalHelper(org.kie.dmn.feel.util.EvalHelper) ScopeHelper(org.kie.dmn.feel.parser.feel11.ScopeHelper) ContextEntryNode(org.kie.dmn.feel.lang.ast.ContextEntryNode) NamedParameterNode(org.kie.dmn.feel.lang.ast.NamedParameterNode) LambdaExpr(com.github.javaparser.ast.expr.LambdaExpr) NameRefNode(org.kie.dmn.feel.lang.ast.NameRefNode) MapBackedType(org.kie.dmn.feel.lang.impl.MapBackedType) ConditionalExpr(com.github.javaparser.ast.expr.ConditionalExpr) UnaryTestNode(org.kie.dmn.feel.lang.ast.UnaryTestNode) NameDefNode(org.kie.dmn.feel.lang.ast.NameDefNode) Parameter(com.github.javaparser.ast.body.Parameter) HashMap(java.util.HashMap) IterationContextNode(org.kie.dmn.feel.lang.ast.IterationContextNode) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) CompositeType(org.kie.dmn.feel.lang.CompositeType) TemporalConstantNode(org.kie.dmn.feel.lang.ast.TemporalConstantNode) BooleanNode(org.kie.dmn.feel.lang.ast.BooleanNode) Type(org.kie.dmn.feel.lang.Type) AtLiteralNode(org.kie.dmn.feel.lang.ast.AtLiteralNode) ListTypeNode(org.kie.dmn.feel.lang.ast.ListTypeNode) BooleanLiteralExpr(com.github.javaparser.ast.expr.BooleanLiteralExpr) UnaryTestListNode(org.kie.dmn.feel.lang.ast.UnaryTestListNode) RangeNode(org.kie.dmn.feel.lang.ast.RangeNode) FormalParameterNode(org.kie.dmn.feel.lang.ast.FormalParameterNode) NameExpr(com.github.javaparser.ast.expr.NameExpr) PathExpressionNode(org.kie.dmn.feel.lang.ast.PathExpressionNode) FieldDeclaration(com.github.javaparser.ast.body.FieldDeclaration) DirectCompilerResult.mergeFDs(org.kie.dmn.feel.codegen.feel11.DirectCompilerResult.mergeFDs) SignedUnaryNode(org.kie.dmn.feel.lang.ast.SignedUnaryNode) TypeAndFn(org.kie.dmn.feel.lang.ast.AtLiteralNode.TypeAndFn) BetweenNode(org.kie.dmn.feel.lang.ast.BetweenNode) ContextTypeNode(org.kie.dmn.feel.lang.ast.ContextTypeNode) FilterExpressionNode(org.kie.dmn.feel.lang.ast.FilterExpressionNode) IntegerLiteralExpr(com.github.javaparser.ast.expr.IntegerLiteralExpr) InstanceOfNode(org.kie.dmn.feel.lang.ast.InstanceOfNode) StringNode(org.kie.dmn.feel.lang.ast.StringNode) Expression(com.github.javaparser.ast.expr.Expression) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) QualifiedNameNode(org.kie.dmn.feel.lang.ast.QualifiedNameNode)

Example 3 with PathExpressionNode

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

the class FEELParserTest method testContextPathExpression3.

@Test
public void testContextPathExpression3() {
    String inputExpression = "{ first name : \"bob\" }.first name";
    BaseNode pathBase = parse(inputExpression);
    assertThat(pathBase, is(instanceOf(PathExpressionNode.class)));
    assertThat(pathBase.getText(), is(inputExpression));
    assertThat(pathBase.getResultType(), is(BuiltInType.STRING));
    PathExpressionNode pathExpr = (PathExpressionNode) pathBase;
    assertThat(pathExpr.getExpression(), is(instanceOf(ContextNode.class)));
    assertThat(pathExpr.getExpression().getText(), is("{ first name : \"bob\" }"));
    assertThat(pathExpr.getName(), is(instanceOf(NameRefNode.class)));
    assertThat(pathExpr.getName().getText(), is("first name"));
}
Also used : PathExpressionNode(org.kie.dmn.feel.lang.ast.PathExpressionNode) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) Test(org.junit.Test)

Example 4 with PathExpressionNode

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

the class FEELParserTest method testContextPathExpression2.

@Test
public void testContextPathExpression2() {
    String inputExpression = "{ x : { y : \"foo\" } }.x.y";
    BaseNode pathBase = parse(inputExpression);
    assertThat(pathBase, is(instanceOf(PathExpressionNode.class)));
    assertThat(pathBase.getText(), is(inputExpression));
    assertThat(pathBase.getResultType(), is(BuiltInType.STRING));
    PathExpressionNode pathExpr = (PathExpressionNode) pathBase;
    assertThat(pathExpr.getExpression(), is(instanceOf(ContextNode.class)));
    assertThat(pathExpr.getExpression().getText(), is("{ x : { y : \"foo\" } }"));
    assertThat(pathExpr.getName(), is(instanceOf(QualifiedNameNode.class)));
    assertThat(pathExpr.getName().getText(), is("x.y"));
}
Also used : PathExpressionNode(org.kie.dmn.feel.lang.ast.PathExpressionNode) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) Test(org.junit.Test)

Example 5 with PathExpressionNode

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

the class FEELParserTest method testPathExpression.

@Test
public void testPathExpression() {
    String inputExpression = "[ 10, 15 ].size";
    BaseNode pathBase = parse(inputExpression);
    assertThat(pathBase, is(instanceOf(PathExpressionNode.class)));
    assertThat(pathBase.getText(), is(inputExpression));
    PathExpressionNode pathExpr = (PathExpressionNode) pathBase;
    assertThat(pathExpr.getExpression(), is(instanceOf(ListNode.class)));
    assertThat(pathExpr.getExpression().getText(), is("10, 15"));
    assertThat(pathExpr.getName(), is(instanceOf(NameRefNode.class)));
    assertThat(pathExpr.getName().getText(), is("size"));
}
Also used : PathExpressionNode(org.kie.dmn.feel.lang.ast.PathExpressionNode) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) Test(org.junit.Test)

Aggregations

BaseNode (org.kie.dmn.feel.lang.ast.BaseNode)5 PathExpressionNode (org.kie.dmn.feel.lang.ast.PathExpressionNode)5 Test (org.junit.Test)4 StaticJavaParser (com.github.javaparser.StaticJavaParser)1 FieldDeclaration (com.github.javaparser.ast.body.FieldDeclaration)1 Parameter (com.github.javaparser.ast.body.Parameter)1 BinaryExpr (com.github.javaparser.ast.expr.BinaryExpr)1 BooleanLiteralExpr (com.github.javaparser.ast.expr.BooleanLiteralExpr)1 ConditionalExpr (com.github.javaparser.ast.expr.ConditionalExpr)1 EnclosedExpr (com.github.javaparser.ast.expr.EnclosedExpr)1 Expression (com.github.javaparser.ast.expr.Expression)1 FieldAccessExpr (com.github.javaparser.ast.expr.FieldAccessExpr)1 IntegerLiteralExpr (com.github.javaparser.ast.expr.IntegerLiteralExpr)1 LambdaExpr (com.github.javaparser.ast.expr.LambdaExpr)1 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)1 NameExpr (com.github.javaparser.ast.expr.NameExpr)1 NullLiteralExpr (com.github.javaparser.ast.expr.NullLiteralExpr)1 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)1 UnknownType (com.github.javaparser.ast.type.UnknownType)1 Duration (java.time.Duration)1