private int getBlockBalance(IDocument document, int offset, SQLBlockCompletionInfo blockInfo) {
        if (offset < 1) {
            return -1;
        }
        if (offset >= document.getLength()) {
            return 1;
        }

        int begin = offset;
        int end = offset;

        SQLHeuristicScanner scanner = new SQLHeuristicScanner(document, syntaxManager);

        while (true) {
            begin = scanner.findOpeningPeer(begin, blockInfo);
            end = scanner.findClosingPeer(end, blockInfo);
            if (begin == -1 && end == -1) {
                return 0;
            }
            if (begin == -1) {
                return -1;
            }
            if (end == -1) {
                return 1;
            }
        }
    }
Returns the block balance, i.e. zero if the blocks are balanced at <code>offset</code>, a negative number if
there are more closing than opening peers, and a positive number if there are more opening than closing peers.
plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/indent/SQLAutoIndentStrategy.java