PsiMethod (@NotNull PsiField field, PsiClass psiClass, boolean ignoreInvalidTemplate, @NotNull TemplatesManager templatesManager) { Project project = field.getProject(); PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); String template = templatesManager.getDefaultTemplate().getTemplate(); Function<String, String> calculateTemplateText = currentTemplate -> GenerationUtil.velocityGenerateCode(psiClass, Collections.singletonList(field), new HashMap<>(), currentTemplate, 0, false); String methodText; try { methodText = calculateTemplateText.fun(template); } catch (GenerateCodeException e) { if (ignoreInvalidTemplate) { LOG.info(e); methodText = calculateTemplateText.fun(templatesManager.getDefaultTemplates().get(0).getTemplate()); } else { throw e; } } boolean isGetter = templatesManager instanceof GetterTemplatesManager; PsiMethod result; try { result = factory.createMethodFromText(methodText, psiClass); } catch (IncorrectOperationException e) { if (ignoreInvalidTemplate) { LOG.info(e); result = isGetter ? PropertyUtilBase.generateGetterPrototype(field) : PropertyUtilBase.generateSetterPrototype(field); } else { throw new GenerateCodeException(e); } } result = (PsiMethod)CodeStyleManager.getInstance(project).reformat(result); PsiModifierListOwner annotationTarget; if (isGetter) { annotationTarget = result; } else { final PsiParameter[] parameters = result.getParameterList().getParameters(); annotationTarget = parameters.length == 1 ? parameters[0] : null; } if (annotationTarget != null) { NullableNotNullManager.getInstance(project).copyNullableOrNotNullAnnotation(field, annotationTarget); } return generatePrototype(field, result); }