Search in sources :

Example 1 with NameRefNode

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

the class ASTBuilderVisitor method visitQualifiedName.

@Override
public BaseNode visitQualifiedName(FEEL_1_1Parser.QualifiedNameContext ctx) {
    ArrayList<NameRefNode> parts = new ArrayList<>();
    Type typeCursor = null;
    for (FEEL_1_1Parser.NameRefContext t : ctx.nameRef()) {
        String originalText = ParserHelper.getOriginalText(t);
        if (typeCursor == null) {
            typeCursor = scopeHelper.resolveType(originalText).orElse(BuiltInType.UNKNOWN);
        } else if (typeCursor instanceof CompositeType) {
            typeCursor = ((CompositeType) typeCursor).getFields().get(originalText);
        } else {
            // TODO throw error here?
            typeCursor = BuiltInType.UNKNOWN;
        }
        parts.add(ASTBuilderFactory.newNameRefNode(t, typeCursor));
    }
    return parts.size() > 1 ? ASTBuilderFactory.newQualifiedNameNode(ctx, parts, typeCursor) : parts.get(0);
}
Also used : CompositeType(org.kie.dmn.feel.lang.CompositeType) Type(org.kie.dmn.feel.lang.Type) BuiltInType(org.kie.dmn.feel.lang.types.BuiltInType) ArrayList(java.util.ArrayList) NameRefNode(org.kie.dmn.feel.lang.ast.NameRefNode) CompositeType(org.kie.dmn.feel.lang.CompositeType)

Example 2 with NameRefNode

use of org.kie.dmn.feel.lang.ast.NameRefNode 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 3 with NameRefNode

use of org.kie.dmn.feel.lang.ast.NameRefNode 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)

Aggregations

NameRefNode (org.kie.dmn.feel.lang.ast.NameRefNode)3 QualifiedNameNode (org.kie.dmn.feel.lang.ast.QualifiedNameNode)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 CompositeType (org.kie.dmn.feel.lang.CompositeType)1 Type (org.kie.dmn.feel.lang.Type)1 BaseNode (org.kie.dmn.feel.lang.ast.BaseNode)1 MapBackedType (org.kie.dmn.feel.lang.impl.MapBackedType)1 BuiltInType (org.kie.dmn.feel.lang.types.BuiltInType)1