use of org.activityinfo.store.query.shared.NodeMatch in project activityinfo by bedatadriven.
the class FormulaValidator method validateReference.
private FieldType validateReference(FormulaNode formulaNode) {
Collection<NodeMatch> matches;
try {
if (formulaNode instanceof SymbolNode) {
matches = nodeMatcher.resolveSymbol((SymbolNode) formulaNode);
} else if (formulaNode instanceof CompoundExpr) {
matches = nodeMatcher.resolveCompoundExpr((CompoundExpr) formulaNode);
} else {
throw new IllegalArgumentException();
}
} catch (FormulaException e) {
errors.add(new FormulaError(formulaNode, e.getMessage()));
throw new ValidationFailed();
}
if (matches.isEmpty()) {
errors.add(new FormulaError(formulaNode, "Invalid field reference"));
throw new ValidationFailed();
}
for (NodeMatch match : matches) {
references.add(new FieldReference(formulaNode.getSourceRange(), match));
}
NodeMatch match = matches.iterator().next();
if (match.isEnumBoolean()) {
return BooleanType.INSTANCE;
} else if (match.isCalculated()) {
return findCalculatedFieldType(match.getFieldNode());
} else if (match.isRootId()) {
return TextType.SIMPLE;
} else {
return match.getFieldNode().getType();
}
}
use of org.activityinfo.store.query.shared.NodeMatch in project activityinfo by bedatadriven.
the class SubFormSummaryTest method matchNodes.
@Test
public void matchNodes() {
TestingStorageProvider catalog = new TestingStorageProvider();
ClinicForm clinicForm = catalog.getClinicForm();
FormTree formTree = catalog.getFormTree(clinicForm.getFormId());
NodeMatcher nodeMatcher = new NodeMatcher(formTree);
Collection<NodeMatch> nodeMatches = nodeMatcher.resolveSymbol(new SymbolNode("NUM_CONSULT"));
assertThat(nodeMatches, hasSize(1));
NodeMatch nodeMatch = Iterables.getOnlyElement(nodeMatches);
JoinNode joinNode = Iterables.getOnlyElement(nodeMatch.getJoins());
}
Aggregations