@Nullable private static PsiMethod generateDummyMethod(Editor editor, PsiFile file) throws IncorrectOperationException { final PsiMethod method = TestIntegrationUtils.createDummyMethod(file); final PsiGenerationInfo<PsiMethod> info = OverrideImplementUtil.createGenerationInfo(method); int offset = findOffsetToInsertMethodTo(editor, file); GenerateMembersUtil.insertMembersAtOffset(file, offset, Collections.singletonList(info)); final PsiMethod member = info.getPsiMember(); return member != null ? CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(member) : null; }
private static void insertGenerationInfos( InsertionContext context, List<PsiGenerationInfo<PsiMethod>> infos) { List<PsiGenerationInfo<PsiMethod>> newInfos = GenerateMembersUtil.insertMembersAtOffset( context.getFile(), context.getStartOffset(), infos); if (!newInfos.isEmpty()) { final List<PsiElement> elements = new ArrayList<PsiElement>(); for (GenerationInfo member : newInfos) { if (!(member instanceof TemplateGenerationInfo)) { final PsiMember psiMember = member.getPsiMember(); if (psiMember != null) { elements.add(psiMember); } } } GlobalInspectionContextBase.cleanupElements( context.getProject(), null, elements.toArray(new PsiElement[elements.size()])); newInfos.get(0).positionCaret(context.getEditor(), true); } }