PsiMethod (@NotNull PsiClass psiClass, @NotNull String methodText) { PsiMethod[] methods = psiClass.getMethods(); assertSize(1, methods); PsiMethod psiMethod = methods[0]; Project project = getProject(); PsiElementFactory factory = PsiElementFactory.getInstance(project); Computable<PsiMethod> replaceMethodAction = () -> (PsiMethod)psiMethod.replace(factory.createMethodFromText(methodText, psiMethod)); return WriteCommandAction.runWriteCommandAction(project, replaceMethodAction); }