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);
}
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;
}
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);
}
Aggregations