List<FoldRegion> (@NotNull EditorFoldingInfo info, @NotNull FoldingModelEx foldingModel, @NotNull Map<TextRange, Boolean> rangeToExpandStatusMap, @NotNull Map<FoldRegion, Boolean> shouldExpand, @NotNull Map<FoldingGroup, Boolean> groupExpand) { List<FoldRegion> newRegions = new ArrayList<>(); SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(myProject); for (FoldingUpdate.RegionInfo regionInfo : myRegionInfos) { ProgressManager.checkCanceled(); FoldingDescriptor descriptor = regionInfo.descriptor; FoldingGroup group = descriptor.getGroup(); TextRange range = descriptor.getRange(); String placeholder = null; try { placeholder = descriptor.getPlaceholderText(); } catch (IndexNotReadyException ignore) { } if (range.getEndOffset() > myEditor.getDocument().getTextLength()) { LOG.error(String.format("Invalid folding descriptor detected (%s). It ends beyond the document range (%d)", descriptor, myEditor.getDocument().getTextLength())); continue; } FoldRegion region = foldingModel.createFoldRegion(range.getStartOffset(), range.getEndOffset(), placeholder == null ? "..." : placeholder, group, descriptor.isNonExpandable()); if (region == null) continue; PsiElement psi; try (AccessToken ignore = SlowOperations.knownIssue("IDEA-326651, EA-831712")) { psi = descriptor.getElement().getPsi(); if (psi == null || !psi.isValid() || !myFile.isValid()) { region.dispose(); continue; } } region.setGutterMarkEnabledForSingleLine(descriptor.isGutterMarkEnabledForSingleLine()); if (descriptor.canBeRemovedWhenCollapsed()) region.putUserData(CAN_BE_REMOVED_WHEN_COLLAPSED, Boolean.TRUE); region.putUserData(COLLAPSED_BY_DEFAULT, regionInfo.collapsedByDefault); region.putUserData(SIGNATURE, ObjectUtils.chooseNotNull(regionInfo.signature, NO_SIGNATURE)); info.addRegion(region, smartPointerManager.createSmartPsiElementPointer(psi)); newRegions.add(region); if (descriptor.isNonExpandable()) { region.putUserData(FoldingModelImpl.SELECT_REGION_ON_CARET_NEARBY, Boolean.TRUE); } else { boolean expandStatus = shouldExpandNewRegion(range, rangeToExpandStatusMap, regionInfo.collapsedByDefault); if (group == null) { shouldExpand.put(region, expandStatus); } else { final Boolean alreadyExpanded = groupExpand.get(group); groupExpand.put(group, alreadyExpanded == null ? expandStatus : alreadyExpanded.booleanValue() || expandStatus); } } } return newRegions; }