PsiMethod (final PsiField field) { final Project project = field.getProject(); final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project); final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project); final PsiExpression fieldInitializer = field.getInitializer(); final PsiMethod method = elementFactory.createMethod(codeStyleManager.variableNameToPropertyName(field.getName(), VariableKind.STATIC_FIELD), field.getType()); PsiCodeBlock body = method.getBody(); assert body != null; final PsiStatement methodCode = elementFactory.createStatementFromText(PsiKeyword.RETURN + " " + requireNonNull(fieldInitializer).getText() + ";", null); body.add(methodCode); return method; }