void (@NotNull ImperativeCommand.Environment env) { Generator<PsiJavaFile> javaFiles = psiJavaFiles(); PsiJavaFile psiFile = env.generateValue(javaFiles, "Open %s in editor"); IntentionAction makeSealedAction = new SealClassAction().asIntention(); FileEditorManager editorManager = FileEditorManager.getInstance(myProject); Editor editor = editorManager.openTextEditor(new OpenFileDescriptor(myProject, psiFile.getVirtualFile()), true); Collection<PsiClass> classes = PsiTreeUtil.findChildrenOfType(psiFile, PsiClass.class); List<PsiClass> psiClasses = ContainerUtil.filter(classes, psiClass -> canConvertToSealedClass(editor, makeSealedAction, psiClass)); if (psiClasses.isEmpty()) { env.logMessage("Haven't found any suitable classes, skipping"); return; } MadTestingUtil.changeAndRevert(myProject, () -> { PsiClass psiClass = env.generateValue(Generator.sampledFrom(psiClasses), "Converting class: %s"); PsiIdentifier classIdentifier = Objects.requireNonNull(psiClass.getNameIdentifier()); editor.getCaretModel().moveToOffset(classIdentifier.getTextOffset()); boolean convertedToSealed = convertToSealedClass(editor, makeSealedAction, classIdentifier); if (!convertedToSealed) { env.logMessage("Failed to convert to sealed class, skipping"); return; } PsiDocumentManager.getInstance(myProject).commitAllDocuments(); Set<PsiFile> relatedFiles = new HashSet<>(); relatedFiles.add(psiFile); DirectClassInheritorsSearch.search(psiClass).mapping(PsiElement::getContainingFile).forEach(e -> { relatedFiles.add(e); return true; }); relatedFiles.forEach(f -> assertFalse(MadTestingUtil.containsErrorElements(f.getViewProvider()))); PsiFile fileToChange = env.generateValue(Generator.sampledFrom(relatedFiles.toArray(PsiFile.EMPTY_ARRAY)), "Invoking intention in %s"); env.executeCommands(IntDistribution.uniform(1, 5), Generator.constant(new InvokeIntention(fileToChange, new JavaGreenIntentionPolicy()))); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); relatedFiles.forEach(f -> assertFalse(MadTestingUtil.containsErrorElements(f.getViewProvider()))); }); }