PsiMethod (@NotNull PsiField field) { PsiElementFactory factory = JavaPsiFacade.getElementFactory(field.getProject()); Project project = field.getProject(); String name = field.getName(); String getName = suggestGetterName(field); PsiMethod getMethod = factory.createMethod(getName, AnnotationTargetUtil.keepStrictlyTypeUseAnnotations(field.getModifierList(), field.getType())); PsiUtil.setModifierProperty(getMethod, PsiModifier.PUBLIC, true); if (field.hasModifierProperty(PsiModifier.STATIC)) { PsiUtil.setModifierProperty(getMethod, PsiModifier.STATIC, true); } NullableNotNullManager.getInstance(project).copyNullableOrNotNullAnnotation(field, getMethod); PsiCodeBlock body = factory.createCodeBlockFromText("{\nreturn " + name + ";\n}", null); Objects.requireNonNull(getMethod.getBody()).replace(body); getMethod = (PsiMethod)CodeStyleManager.getInstance(project).reformat(getMethod); return getMethod; }