void (@NotNull PsiElement element) { final PsiJavaToken token = (PsiJavaToken)element; final PsiIfStatement parentStatement = (PsiIfStatement)token.getParent(); assert parentStatement != null; final PsiBlockStatement elseBranch = (PsiBlockStatement)parentStatement.getElseBranch(); assert elseBranch != null; final PsiElement lastChild = elseBranch.getLastChild(); final PsiCodeBlock elseBranchBlock = elseBranch.getCodeBlock(); final PsiStatement elseBranchContents = elseBranchBlock.getStatements()[0]; final PsiElement grandParent = parentStatement.getParent(); if (lastChild instanceof PsiComment) { addElementAndPrevWhiteSpace(lastChild, grandParent, parentStatement); } final List<PsiComment> before = new ArrayList<>(1); final List<PsiComment> after = new ArrayList<>(1); collectComments(elseBranchContents, before, after); for (PsiComment comment : before) { addElementAndPrevWhiteSpace(comment, parentStatement, token); } for (PsiComment comment : after) { grandParent.addAfter(comment, parentStatement); } PsiReplacementUtil.replaceStatement(elseBranch, elseBranchContents.getText()); }