protected int searchForClosingBracket(int startPosition, char openBracket, char closeBracket, IDocument document ) throws BadLocationException {
        int stack = 1;
        int closePosition = startPosition + 1;
        int length = document.getLength();
        char nextChar;

        // Scan forward for the closing bracket.  Ignore "nested" bracket pairs.
        while (closePosition < length && stack > 0) {
            nextChar = document.getChar( closePosition );
            if (nextChar == openBracket && nextChar != closeBracket)
                stack++;
            else if (nextChar == closeBracket)
                stack--;
            closePosition++;
        }

        if (stack == 0)
            return closePosition - 1;

        return -1;
    }
Returns the position of the closing bracket after startPosition.

@param startPosition the starting position for the search
@param openBracket the open bracket character
@param closeBracket the close bracket character
@param document the document being searched
@return the location of the closing bracket
plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/syntax/SQLDoubleClickStrategy.java