TextRange (TextRange textRange, ASTNode nodeAfter, String whiteSpace) { String whiteSpaceToUse = myDocumentModel.adjustWhiteSpaceIfNecessary(whiteSpace, textRange.getStartOffset(), textRange.getEndOffset(), nodeAfter, true).toString(); final String wsReplaced = replaceWithPSI(textRange, whiteSpaceToUse); if (wsReplaced != null){ return new TextRange(textRange.getStartOffset(), textRange.getStartOffset() + wsReplaced.length()); } else { return textRange; } }