Search in sources :

Example 1 with TreeToQueryCapable

use of com.haulmont.cuba.core.sys.jpql.tree.TreeToQueryCapable in project cuba by cuba-platform.

the class TreeToQuery method pre.

@Override
public Object pre(Object t) {
    if (!(t instanceof CommonTree)) {
        return t;
    }
    if (t instanceof CommonErrorNode) {
        invalidNodes.add(new ErrorRec((CommonErrorNode) t, "Error node"));
        return t;
    }
    CommonTree node = (CommonTree) t;
    if (node.token == null)
        return t;
    if (node.getType() == JPA2Lexer.HAVING || node.parent != null && node.parent.getType() == JPA2Lexer.T_SIMPLE_CONDITION && !parentNodeHasPreviousLparen(node) || node.parent != null && node.parent.getType() == JPA2Lexer.T_GROUP_BY || node.parent != null && node.parent.getType() == JPA2Lexer.T_ORDER_BY && node.getType() != JPA2Lexer.T_ORDER_BY_FIELD || node.parent != null && node.parent.getType() == JPA2Lexer.T_CONDITION && node.getType() == JPA2Lexer.LPAREN && (node.childIndex == 0 || node.parent.getChild(node.childIndex - 1).getType() != JPA2Lexer.LPAREN) || node.getType() == JPA2Lexer.AND || node.parent != null && node.parent.getType() == JPA2Lexer.T_ORDER_BY_FIELD || node.parent != null && node.parent.getType() == JPA2Lexer.T_SELECTED_ITEM && node.getType() == JPA2Lexer.AS || node.getType() == JPA2Lexer.OR || node.getType() == JPA2Lexer.NOT || node.getType() == JPA2Lexer.DISTINCT && node.childIndex == 0 || node.getType() == JPA2Lexer.JOIN || node.getType() == JPA2Lexer.LEFT || node.getType() == JPA2Lexer.OUTER || node.getType() == JPA2Lexer.INNER || node.getType() == JPA2Lexer.FETCH || node.getType() == JPA2Lexer.CASE || node.getType() == JPA2Lexer.WHEN || node.getType() == JPA2Lexer.THEN || node.getType() == JPA2Lexer.ELSE || node.getType() == JPA2Lexer.END) {
        sb.appendSpace();
    }
    if (node.getType() == JPA2Lexer.T_ORDER_BY_FIELD && node.childIndex > 0 && node.parent.getChild(node.childIndex - 1).getType() == JPA2Lexer.T_ORDER_BY_FIELD) {
        sb.appendString(", ");
    }
    if (isGroupByItem(node)) {
        if (node.childIndex > 0 && isGroupByItem((CommonTree) node.parent.getChild(node.childIndex - 1))) {
            sb.appendString(", ");
        }
    }
    if (node instanceof TreeToQueryCapable) {
        return ((TreeToQueryCapable) t).treeToQueryPre(sb, invalidNodes);
    }
    if (node.getType() == JPA2Lexer.T_SELECTED_ITEMS) {
        return t;
    }
    if (node.getType() == JPA2Lexer.T_SOURCES) {
        sb.appendString("from ");
        return t;
    }
    sb.appendString(node.toString());
    return t;
}
Also used : CommonTree(org.antlr.runtime.tree.CommonTree) CommonErrorNode(org.antlr.runtime.tree.CommonErrorNode) TreeToQueryCapable(com.haulmont.cuba.core.sys.jpql.tree.TreeToQueryCapable)

Aggregations

TreeToQueryCapable (com.haulmont.cuba.core.sys.jpql.tree.TreeToQueryCapable)1 CommonErrorNode (org.antlr.runtime.tree.CommonErrorNode)1 CommonTree (org.antlr.runtime.tree.CommonTree)1