PsiMethod (PsiClass clazz, @NotNull PsiMethod newMethod, Editor editor) { int offset = (editor != null) ? editor.getCaretModel().getOffset() : (clazz.getTextRange().getEndOffset() - 1); final PsiGenerationInfo<PsiMethod> generationInfo = new PsiGenerationInfo<>(newMethod, false); GenerateMembersUtil.insertMembersAtOffset(clazz, offset, Collections.singletonList(generationInfo)); return generationInfo.getPsiMember(); }