void (@NotNull String exceptionName, @NotNull PsiType exceptionType, PsiElement context, @NotNull PsiCatchSection catchSection) { FileTemplate template = FileTemplateManager.getInstance(catchSection.getProject()).getCodeTemplate(JavaTemplateUtil.TEMPLATE_CATCH_BODY); FileTemplate declarationTemplate = FileTemplateManager.getInstance(catchSection.getProject()).getCodeTemplate(JavaTemplateUtil.TEMPLATE_CATCH_DECLARATION); Properties props = FileTemplateManager.getInstance(myProject).getDefaultProperties(); props.setProperty(FileTemplate.ATTRIBUTE_EXCEPTION, exceptionName); props.setProperty(FileTemplate.ATTRIBUTE_EXCEPTION_TYPE, exceptionType.getCanonicalText()); if (context != null && context.isPhysical()) { PsiDirectory directory = context.getContainingFile().getContainingDirectory(); if (directory != null) { JavaTemplateUtil.setPackageNameAttribute(props, directory); } } try { PsiTryStatement tryStmt = (PsiTryStatement)PsiElementFactory.getInstance(myProject) .createStatementFromText("try {} catch (" + declarationTemplate.getText(props) + ") {\n}", null); PsiParameter parameter = tryStmt.getCatchSections()[0].getParameter(); String parameterName = parameter == null ? null : parameter.getName(); if (parameterName != null) { if (!exceptionName.equals(parameterName)) { parameterName = JavaCodeStyleManager.getInstance(myProject).suggestUniqueVariableName(parameterName, context, false); props.setProperty(FileTemplate.ATTRIBUTE_EXCEPTION, parameterName); parameter.setName(parameterName); } PsiParameter sectionParameter = catchSection.getParameter(); if (sectionParameter != null) { sectionParameter.replace(parameter); } } PsiCodeBlock block = PsiElementFactory.getInstance(myProject).createCodeBlockFromText("{\n" + template.getText(props) + "\n}", null); Objects.requireNonNull(catchSection.getCatchBlock()).replace(block); } catch (ProcessCanceledException ce) { throw ce; } catch (Exception e) { throw new IncorrectOperationException("Incorrect file template", (Throwable)e); } }