private boolean transformSourceCode(IDocument document, DocumentCommand command) {
        String sourceCode = command.text;
        int quoteStart = -1, quoteEnd = -1;
        for (int i = 0; i < sourceCode.length(); i++) {
            final char ch = sourceCode.charAt(i);
            if (ch == '"') {
                quoteStart = i;
                break;
            } else if (Character.isUnicodeIdentifierPart(ch) || ch == '{' || ch == '<' || ch == '[') {
                // Letter or bracket before quote
                return false;
            }
        }
        for (int i = sourceCode.length() - 1; i >= 0; i--) {
            final char ch = sourceCode.charAt(i);
            if (ch == '"') {
                quoteEnd = i;
                break;
            } else if (Character.isUnicodeIdentifierPart(ch)) {
                // Letter before quote
                return false;
            }
        }
        if (quoteStart == -1 || quoteEnd == -1) {
            return false;
        }
        // Let's check that source code has some whitespaces
        int wsCount = 0;
        for (int i = quoteStart + 1; i < quoteEnd; i++) {
            if (Character.isWhitespace(sourceCode.charAt(i))) {
                wsCount++;
            }
        }
        if (wsCount < 3) {
            return false;
        }
        StringBuilder result = new StringBuilder(sourceCode.length());
        char prevChar = (char)-1;
        char escapeChar = '\\';
        boolean inString = false;
        boolean inComment = false;
        CommentType commentType = CommentType.Unknown; 
        
        for (int i = quoteStart; i < quoteEnd; i++) {
            final char ch = sourceCode.charAt(i);
            
	        if (inString) {
	        	if (prevChar == escapeChar) {
		            switch (ch) {
	                case 'n':
	                    if (!endsWithLF(result, '\n')) {
	                        result.append("\n");
	                    }
	                    break;
	                case 'r':
	                    if (!endsWithLF(result, '\r')) {
	                        result.append("\r");
	                    }
	                    break;
	                case 't':
	                    result.append("\t");
	                    break;
	                default:
	                    result.append(ch);
	                    break;
		            }
	        	}
	        	else {
		            switch (ch) {
	                case '"':
	                    inString = false;
	                    break;
	                default:
	                    if (ch == escapeChar) {
	                        break;
	                    }
                        result.append(ch);
                    }
		        }
	        }
            else if (inComment) {
        		if (commentType == CommentType.Unknown && prevChar == '/' && ch == '*') {
        			commentType = CommentType.Block;
        		}
        		else if (commentType == CommentType.Unknown && prevChar == '/' && ch == '/') {
        			commentType = CommentType.EndOfLine;
        		}
        		else if (commentType == CommentType.Block && prevChar == '*' && ch == '/' ) {
    				inComment = false;
        		}
        		else if (commentType == CommentType.EndOfLine && ch == '\n') {
    				inComment = false;
        		}
        	}
            else {
            	switch (ch) {
            	case '/':
            		inComment = true;
            		commentType = CommentType.Unknown;
            		break;
            	case '"':
            		inString = true;
            		break;
                case '\n':
                case '\r':
                    // Append linefeed even if it is outside of quotes
                    // (but only if string in quotes doesn't end with linefeed - we don't need doubles)
                    if (result.length() > 0 && !endsWithLF(result, '\n') && !endsWithLF(result, '\r')) {
                        result.append(ch == '\n' ? "\n" : "\r");
                    }
                    break;
            	}
            }
            
            prevChar = ch;
        }

        try {
            document.replace(command.offset, command.length, command.text);
            document.replace(command.offset, command.text.length(), result.toString());
        } catch (Exception e) {
            log.warn(e);
        }

        command.caretOffset = command.offset + result.length();
        command.text = null;
        command.length = 0;
        command.doit = false;

        return true;
    }
Creates a new SQL auto indent strategy for the given document partitioning.
plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/indent/SQLAutoIndentStrategy.java