void (@NotNull PsiElement element) { final PsiTryStatement tryStatement = (PsiTryStatement)element.getParent(); final PsiResourceList resourceList = tryStatement.getResourceList(); if (resourceList == null || resourceList.getResourceVariablesCount() <= 1) { return; } CommentTracker tracker = new CommentTracker(); @NonNls final StringBuilder newTryStatementText = new StringBuilder(); int count = 0; for (PsiResourceListElement resource : resourceList) { if (count > 0) { newTryStatementText.append("{\n"); } ++count; newTryStatementText.append("try (").append(tracker.text(resource)).append(")"); } final PsiCodeBlock tryBlock = tryStatement.getTryBlock(); if (tryBlock == null) { return; } newTryStatementText.append(tracker.text(tryBlock)); for (int i = 1; i < count; i++) { newTryStatementText.append("\n}"); } final PsiCatchSection[] catchSections = tryStatement.getCatchSections(); for (PsiCatchSection catchSection : catchSections) { newTryStatementText.append(tracker.text(catchSection)); } final PsiCodeBlock finallyBlock = tryStatement.getFinallyBlock(); if (finallyBlock != null) { newTryStatementText.append("finally").append(tracker.text(finallyBlock)); } PsiReplacementUtil.replaceStatement(tryStatement, newTryStatementText.toString(), tracker); }