public Collection<NodeMatch> resolveSymbol(SymbolNode symbol) { return matchNodes(new QueryPath(symbol), tree.getRootFields()); }
private Collection<NodeMatch> unionMatches(QueryPath path, FormTree.Node parentField) { List<NodeMatch> results = Lists.newArrayList(); for (ResourceId childFormId : parentField.getRange()) { Optional<FormClass> childForm = tree.getFormClassIfPresent(childFormId); if(childForm.isPresent()) { Iterable<FormTree.Node> childFields = parentField.getChildren(childFormId); if (path.matches(childForm.get()) && path.peek().equals(ColumnModel.RECORD_ID_SYMBOL)) { results.add(NodeMatch.forId(parentField, childForm.get())); } else if (path.matches(childForm.get()) || path.matches(parentField)) { results.addAll(matchNodes(path.next(), childFields)); } else { // Descend the next level results.addAll(matchNodes(path, childFields)); } } } return results; }
/** * Resolves a compound expression like "province.name" to one or more {@code FormTree.Nodes} * * @return a binding to the corresponding {@code FormTree.Node} * * @throws AmbiguousSymbolException if the expression could match multiple nodes in the tree */ public Collection<NodeMatch> resolveCompoundExpr(CompoundExpr expr) { QueryPath queryPath = new QueryPath(expr); // Given an expression like Province.Name, see if we can match the // the first symbol against the root form's id or label if(queryPath.matches(tree.getRootFormClass())) { return matchNodes(queryPath.next(), tree.getRootFields()); } return matchNodes(queryPath, tree.getRootFields()); }