Search in sources :

Example 1 with OpenBracketToken

use of org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.OpenBracketToken in project scout.rt by eclipse.

the class SqlFormatter method formatBracketExpr.

private void formatBracketExpr(BracketExpr stm, FormatContext ctx) {
    boolean multiline = isMultiline(stm);
    for (IToken t : stm.getChildren()) {
        if (t instanceof OpenBracketToken) {
            formatDefault(t, ctx);
            if (multiline) {
                ctx.println();
                ctx.in();
            }
        } else if (t instanceof CloseBracketToken) {
            if (multiline) {
                ctx.out();
            }
            formatDefault(t, ctx);
        } else if (t instanceof Statement) {
            formatStatement((Statement) t, ctx);
        } else if (t instanceof SingleStatement) {
            formatSingleStatement((SingleStatement) t, ctx);
        } else if (t instanceof ListExpr) {
            formatListExpr((ListExpr) t, multiline, ctx);
        } else {
            formatDefault(t, ctx);
        }
    }
}
Also used : CloseBracketToken(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.CloseBracketToken) IToken(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.IToken) Statement(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.Statement) SingleStatement(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.SingleStatement) SingleStatement(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.SingleStatement) ListExpr(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.ListExpr) OpenBracketToken(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.OpenBracketToken)

Example 2 with OpenBracketToken

use of org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.OpenBracketToken in project scout.rt by eclipse.

the class SqlParser method parseBracketExpr.

@SuppressWarnings("squid:S2583")
private BracketExpr parseBracketExpr(List<IToken> list, ParseContext ctx) {
    // BracketExpr = OpenBracketToken (Statement | ListExpr) CloseBracketToken
    ParseStep lock = ctx.checkAndAdd("BracketExpr", list);
    if (lock == null) {
        return null;
    }
    try {
        IToken open = null;
        IToken t = null;
        IToken close = null;
        ArrayList<IToken> backup = new ArrayList<IToken>(list);
        if ((open = removeToken(list, OpenBracketToken.class)) != null && ((t = parseStatement(list, ctx)) != null || (t = parseListExpr(list, ctx)) != null || t == null) && (close = removeToken(list, CloseBracketToken.class)) != null) {
        // NOSONAR
        // ok
        } else {
            // restore incomplete
            list.clear();
            list.addAll(backup);
            return null;
        }
        BracketExpr e = new BracketExpr();
        e.addChild(open);
        if (t != null) {
            e.addChild(t);
        }
        e.addChild(close);
        return e;
    } finally {
        ctx.remove(lock);
    }
}
Also used : IToken(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.IToken) ArrayList(java.util.ArrayList) BracketExpr(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.BracketExpr) OpenBracketToken(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.OpenBracketToken)

Aggregations

IToken (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.IToken)2 OpenBracketToken (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.OpenBracketToken)2 ArrayList (java.util.ArrayList)1 BracketExpr (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.BracketExpr)1 CloseBracketToken (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.CloseBracketToken)1 ListExpr (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.ListExpr)1 SingleStatement (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.SingleStatement)1 Statement (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.Statement)1