ASTNode (PsiWhiteSpace whiteSpace, PsiElement nextElement) { String text = whiteSpace.getText(); int endLPos = text.lastIndexOf('\n'); if (text.lastIndexOf('\n', endLPos - 1) >= 0) { // has at least two line breaks return ASTFactory.whitespace(text.substring(endLPos)); } if (nextElement instanceof PsiWhiteSpace && nextElement.getText().contains("\n") && !text.contains("\n")) { text = '\n' + text; } return ASTFactory.whitespace(text); }