void (@NotNull Project project, @NotNull final Editor editor, @NotNull PsiFile file) { CodeFoldingManager foldingManager = CodeFoldingManager.getInstance(project); foldingManager.updateFoldRegions(editor); final FoldRegion[] allFoldRegions = editor.getFoldingModel().getAllFoldRegions(); Runnable processor = () -> { for (FoldRegion region : allFoldRegions) { PsiElement element = EditorFoldingInfo.get(editor).getPsiElement(region); if (element instanceof PsiDocCommentBase || Boolean.TRUE.equals(region.getUserData(DOC_COMMENT_MARK)) || hasAllowedTokenType(editor, region, element)) { region.setExpanded(myExpand); } } }; editor.getFoldingModel().runBatchFoldingOperation(processor); }