void (@NotNull PsiElement context, @NotNull Editor editor) { PsiExpression expression = JavaPostfixTemplatesUtils.getTopmostExpression(context); assert expression != null; Project project = context.getProject(); editor.getDocument().deleteString(expression.getTextRange().getStartOffset(), expression.getTextRange().getEndOffset()); TemplateManager manager = TemplateManager.getInstance(project); Template template = manager.createTemplate("", ""); template.setToReformat(true); template.addTextSegment("try ("); MacroCallNode name = new MacroCallNode(new SuggestVariableNameMacro()); template.addVariable("type", new TypeExpression(project, new PsiType[]{expression.getType()}), false); template.addTextSegment(" "); template.addVariable("name", name, name, true); template.addTextSegment(" = "); template.addVariable("variable", new TextExpression(expression.getText()), false); template.addTextSegment(") {\n"); template.addEndVariable(); template.addTextSegment("\n}"); Collection<PsiClassType> unhandled = getUnhandled(expression); for (PsiClassType exception : unhandled) { MacroCallNode variable = new MacroCallNode(new SuggestVariableNameMacro()); template.addTextSegment("catch("); template.addVariable("type " + exception.getClassName(), new TypeExpression(project, new PsiType[]{exception}), false); template.addTextSegment(" "); template.addVariable("name " + exception.getClassName(), variable, variable, false); template.addTextSegment(") {}"); } manager.startTemplate(editor, template); }