void (@NotNull PsiCodeBlock container, PsiElement @Nullable [] statements) { if (statements == null || statements.length <= 0) { return; } PsiElement first = statements[0]; ASTNode node = first.getNode(); if (node == null || !ElementType.JAVA_COMMENT_BIT_SET.contains(node.getElementType())) { return; } ASTNode commentWsText = node.getTreePrev(); if (commentWsText == null || !JavaJspElementType.WHITE_SPACE_BIT_SET.contains(commentWsText.getElementType())) { return; } int indent = 0; CharSequence text = commentWsText.getChars(); for (int i = text.length() - 1; i >= 0; i--, indent++) { if (text.charAt(i) == '\n') { break; } } if (indent <= 0) { return; } PsiElement codeBlockWsElement = null; ASTNode codeBlockWsNode = null; boolean lbraceFound = false; final PsiParserFacade parserFacade = PsiParserFacade.getInstance(container.getProject()); for (PsiElement codeBlockChild = container.getFirstChild(); codeBlockChild != null; codeBlockChild = codeBlockChild.getNextSibling()) { ASTNode childNode = codeBlockChild.getNode(); if (childNode == null) { continue; } if (!lbraceFound) { if (JavaTokenType.LBRACE == childNode.getElementType()) { lbraceFound = true; } continue; } if (JavaJspElementType.WHITE_SPACE_BIT_SET.contains(childNode.getElementType())) { codeBlockWsElement = codeBlockChild; codeBlockWsNode = childNode; break; } else if (JavaTokenType.RBRACE == childNode.getElementType()) { break; } } if (codeBlockWsElement != null) { CharSequence existingWhiteSpaceText = codeBlockWsNode.getChars(); int existingWhiteSpaceEndOffset = existingWhiteSpaceText.length(); for (int i = existingWhiteSpaceEndOffset - 1; i >= 0; i--) { if (existingWhiteSpaceText.charAt(i) == '\n') { existingWhiteSpaceEndOffset = i; break; } } String newWsText = text.subSequence(text.length() - indent, text.length()).toString(); // Add white spaces from all lines except the last one. if (existingWhiteSpaceEndOffset < existingWhiteSpaceText.length()) { newWsText = existingWhiteSpaceText.subSequence(0, existingWhiteSpaceEndOffset + 1).toString() + newWsText; } PsiElement indentElement = parserFacade.createWhiteSpaceFromText(newWsText); codeBlockWsElement.replace(indentElement); } else { PsiElement indentElement = parserFacade.createWhiteSpaceFromText(text.subSequence(text.length() - indent, text.length()).toString()); container.add(indentElement); } }