PsiElement (PsiParameter catchParameter) { final PsiTryStatement tryStatement = ((PsiCatchSection)catchParameter.getDeclarationScope()).getTryStatement(); if (tryStatement.getCatchBlocks().length == 1 && tryStatement.getFinallyBlock() == null && tryStatement.getResourceList() == null) { // unwrap entire try statement final PsiCodeBlock tryBlock = tryStatement.getTryBlock(); PsiElement lastAddedStatement = null; if (tryBlock != null) { final PsiElement firstElement = tryBlock.getFirstBodyElement(); if (firstElement != null) { final PsiElement tryParent = tryStatement.getParent(); if (!(tryParent instanceof PsiCodeBlock)) { tryStatement.replace(tryBlock); return tryBlock; } boolean mayCompleteNormally = ControlFlowUtils.codeBlockMayCompleteNormally(tryBlock); if (!mayCompleteNormally) { PsiElement nextElement = PsiTreeUtil.skipWhitespacesAndCommentsForward(tryStatement.getNextSibling()); PsiJavaToken rBrace = ((PsiCodeBlock)tryParent).getRBrace(); PsiElement lastElement = PsiTreeUtil.skipWhitespacesAndCommentsBackward(rBrace); if (nextElement != null && lastElement != null && nextElement != rBrace) { tryParent.deleteChildRange(nextElement, lastElement); } } final PsiElement lastBodyElement = tryBlock.getLastBodyElement(); assert lastBodyElement != null : tryBlock.getText(); tryParent.addRangeBefore(firstElement, lastBodyElement, tryStatement); lastAddedStatement = tryStatement.getPrevSibling(); while (lastAddedStatement != null && (lastAddedStatement instanceof PsiWhiteSpace || lastAddedStatement.getTextLength() == 0)) { lastAddedStatement = lastAddedStatement.getPrevSibling(); } } } tryStatement.delete(); return lastAddedStatement; } // delete catch section final PsiElement catchSection = catchParameter.getParent(); assert catchSection instanceof PsiCatchSection : catchSection; //save previous element to move caret to PsiElement previousElement = catchSection.getPrevSibling(); while (previousElement instanceof PsiWhiteSpace) { previousElement = previousElement.getPrevSibling(); } catchSection.delete(); return previousElement; }