CharSequence (@NotNull CharSequence whiteSpaceText, @NotNull PsiElement startElement, final int startOffset, final int endOffset, CodeStyleSettings codeStyleSettings) { assert startElement.getTextRange().contains(startOffset) : String.format("Element: %s, range: %s, offset: %d", startElement, startElement.getTextRange(), startOffset); // Collect target text from the PSI elements and delegate to the text-based method. StringBuilder buffer = new StringBuilder(); for (PsiElement current = startElement; current != null && current.getTextRange().getStartOffset() < endOffset; current = next(current)) { final TextRange range = current.getTextRange(); final String text = current.getText(); if (StringUtil.isEmpty(text)) { continue; } int start = startOffset > range.getStartOffset() ? startOffset - range.getStartOffset() : 0; if (start >= text.length()) { continue; } int end = endOffset < range.getEndOffset() ? text.length() - (range.getEndOffset() - endOffset) : text.length(); if (end <= start) { continue; } if (start == 0 && end == text.length()) { buffer.append(text); } else { buffer.append(text, start, end); } } return adjustWhiteSpaceIfNecessary(whiteSpaceText, buffer, 0, endOffset - startOffset, codeStyleSettings, null); }