Search in sources :

Example 1 with QualifiedNameNode

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

the class ASTBuilderVisitor method getFunctionName.

private String getFunctionName(BaseNode name) {
    String functionName = null;
    if (name instanceof NameRefNode) {
        // simple name
        functionName = name.getText();
    } else {
        QualifiedNameNode qn = (QualifiedNameNode) name;
        functionName = qn.getParts().stream().map(p -> p.getText()).collect(Collectors.joining(" "));
    }
    return functionName;
}
Also used : QualifiedNameNode(org.kie.dmn.feel.lang.ast.QualifiedNameNode) NameRefNode(org.kie.dmn.feel.lang.ast.NameRefNode)

Example 2 with QualifiedNameNode

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

the class FEELParserTest method testQualifiedName.

@Test
public void testQualifiedName() {
    String inputExpression = "My Person.Full Name";
    MapBackedType personType = new MapBackedType("Person", mapOf(entry("Full Name", BuiltInType.STRING), entry("Age", BuiltInType.NUMBER)));
    BaseNode qualRef = parse(inputExpression, mapOf(entry("My Person", personType)));
    assertThat(qualRef, is(instanceOf(QualifiedNameNode.class)));
    assertThat(qualRef.getResultType(), is(BuiltInType.STRING));
    List<NameRefNode> parts = ((QualifiedNameNode) qualRef).getParts();
    // `My Person` ...
    assertThat(parts.get(0), is(instanceOf(NameRefNode.class)));
    assertThat(parts.get(0).getResultType(), is(personType));
    // ... `.Full Name`
    assertThat(parts.get(1), is(instanceOf(NameRefNode.class)));
    assertThat(parts.get(1).getResultType(), is(BuiltInType.STRING));
    assertLocation(inputExpression, qualRef);
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) MapBackedType(org.kie.dmn.feel.lang.impl.MapBackedType) QualifiedNameNode(org.kie.dmn.feel.lang.ast.QualifiedNameNode) NameRefNode(org.kie.dmn.feel.lang.ast.NameRefNode) Test(org.junit.Test)

Example 3 with QualifiedNameNode

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

the class FEELParserTest method testNestedContexts2.

@Test
public void testNestedContexts2() {
    String inputExpression = "{ an applicant : { " + "    home address : {" + "        street name: \"broadway st\"," + "        city : \"New York\" " + "    } " + " },\n " + " street : an applicant.home address.street name \n" + "}";
    BaseNode ctxbase = parse(inputExpression);
    assertThat(ctxbase, is(instanceOf(ContextNode.class)));
    assertThat(ctxbase.getText(), is(inputExpression));
    ContextNode ctx = (ContextNode) ctxbase;
    assertThat(ctx.getEntries().size(), is(2));
    ContextEntryNode entry = ctx.getEntries().get(1);
    assertThat(entry.getName(), is(instanceOf(NameDefNode.class)));
    assertThat(entry.getResultType(), is(BuiltInType.STRING));
    NameDefNode name = (NameDefNode) entry.getName();
    assertThat(name.getText(), is("street"));
    assertThat(entry.getValue(), is(instanceOf(QualifiedNameNode.class)));
    QualifiedNameNode qnn = (QualifiedNameNode) entry.getValue();
    assertThat(qnn.getParts().get(0).getText(), is("an applicant"));
    assertThat(qnn.getParts().get(1).getText(), is("home address"));
    assertThat(qnn.getParts().get(2).getText(), is("street name"));
}
Also used : NameDefNode(org.kie.dmn.feel.lang.ast.NameDefNode) IterationContextNode(org.kie.dmn.feel.lang.ast.IterationContextNode) ContextNode(org.kie.dmn.feel.lang.ast.ContextNode) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) QualifiedNameNode(org.kie.dmn.feel.lang.ast.QualifiedNameNode) ContextEntryNode(org.kie.dmn.feel.lang.ast.ContextEntryNode) Test(org.junit.Test)

Aggregations

QualifiedNameNode (org.kie.dmn.feel.lang.ast.QualifiedNameNode)3 Test (org.junit.Test)2 BaseNode (org.kie.dmn.feel.lang.ast.BaseNode)2 NameRefNode (org.kie.dmn.feel.lang.ast.NameRefNode)2 ContextEntryNode (org.kie.dmn.feel.lang.ast.ContextEntryNode)1 ContextNode (org.kie.dmn.feel.lang.ast.ContextNode)1 IterationContextNode (org.kie.dmn.feel.lang.ast.IterationContextNode)1 NameDefNode (org.kie.dmn.feel.lang.ast.NameDefNode)1 MapBackedType (org.kie.dmn.feel.lang.impl.MapBackedType)1