void (@NotNull ImperativeCommand.Environment env, @NotNull VirtualFile file) { Project project = getProject(); if (!isCompilable(project, file)) return; myFixture.openFileInEditor(file); PsiJavaFile psiJavaFile = ObjectUtils.tryCast(myFixture.getFile(), PsiJavaFile.class); if (psiJavaFile == null) return; PsiClass psiClass = findClass(file, psiJavaFile); // enum and annotation fields are not supported if (psiClass == null || psiClass.isEnum() || psiClass.isAnnotationType()) return; List<PsiMember> members = findMembers(psiClass); int nMembers = members.size(); if (nMembers == 0) return; PsiMember psiMember = env.generateValue(Generator.sampledFrom(members.toArray(PsiMember.EMPTY_ARRAY)), "Selected member %s"); SmartPsiElementPointer<PsiClass> classPtr = SmartPointerManager.createPointer(psiClass); if (!moveMemberFromClass(project, psiClass, psiMember)) return; psiClass = Objects.requireNonNull(classPtr.getElement()); PsiErrorElement errorElement = Objects.requireNonNull(PsiTreeUtil.getPrevSiblingOfType(psiClass, PsiErrorElement.class)); int outerMemberOffset = errorElement.getTextRange().getStartOffset(); assertTrue("Failed to find member after moving it out of a class", outerMemberOffset != -1); moveMemberToClass(outerMemberOffset); psiClass = classPtr.getElement(); if (psiClass == null) return; assertSize(nMembers, findMembers(psiClass)); }