List<RHQLTerm> terms = new ArrayList<RHQLTerm>();
// simple text match
if (tree.getToken().getType() == RHQLLexer.IDENT) {
String value = PrintUtils.collapseStringChildren(tree);
RHQLTerm nextTerm = new RHQLSimpleTerm(value);
terms.add(nextTerm);
return terms;
}
// advanced query match
String lineage = null;
String path = null;
String param = null;
CommonTree contextTree = (CommonTree) tree.getChild(0);
for (int childIndex = 0; childIndex < contextTree.getChildCount(); childIndex++) {
CommonTree child = (CommonTree) contextTree.getChild(childIndex);
if (child.getToken().getType() == RHQLLexer.LINEAGE) {
lineage = PrintUtils.collapseStringChildren(child);
} else if (child.getToken().getType() == RHQLLexer.PATH) {
path = PrintUtils.collapseStringChildren(child);
} else if (child.getToken().getType() == RHQLLexer.PARAM) {
child = (CommonTree) child.getChild(0); // get the IDENT child of PARAM
param = PrintUtils.collapseStringChildren(child);
}
}
String value = null;
if (tree.getChildCount() > 1) {
CommonTree valueTree = (CommonTree) tree.getChild(1);
for (int childIndex = 0; childIndex < valueTree.getChildCount(); childIndex++) {
CommonTree indentChildTree = (CommonTree) valueTree.getChild(childIndex);
value = PrintUtils.collapseStringChildren(indentChildTree);
int type = tree.getToken().getType();
RHQLComparisonOperator operator = getComparisonOperatorFromTokenType(type, value);
RHQLTerm nextTerm = new RHQLAdvancedTerm(lineage, path, param, operator, value);
terms.add(nextTerm);
}
}
return terms;