private String getLeadingWhitespace(int offset) {
        try {
            IRegion line = document.getLineInformationOfOffset(offset);
            int lineOffset = line.getOffset();
            int nonWS = scanner.findNonWhitespaceForwardInAnyPartition(lineOffset, lineOffset + line.getLength());
            if (nonWS < 0) {
                return "";
            }

            int indentLength = nonWS - lineOffset;
            StringBuilder indent = createIndent();
            if (indentLength >= indent.length() && scanner.endsWithDelimiter(lineOffset, lineOffset + line.getLength() - 1)) {
                SQLScriptElement currentQuery = SQLScriptParser.extractQueryAtPos(context, offset, false);

                nonWS = currentQuery.getOffset();
                lineOffset = document.getLineInformationOfOffset(currentQuery.getOffset()).getOffset();
            }

            return document.get(lineOffset, nonWS - lineOffset);
        } catch (BadLocationException e) {
//            _log.debug(EditorMessages.error_badLocationException, e);
            return "";
        }
    }
Returns the indentation of the line at <code>offset</code> as a <code>StringBuilder</code>. If the offset is
not valid, the empty string is returned.

@param offset the offset in the document
@return the indentation (leading whitespace) of the line in which <code>offset</code> is located
plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/indent/SQLIndenter.java