FoldRegion (int startOffset) { FoldRegion[] foldRegions = getEditor().getFoldingModel().getAllFoldRegions(); for (FoldRegion foldRegion : foldRegions) { if (foldRegion.getStartOffset() == startOffset) { return foldRegion; } } throw new IllegalArgumentException(String.format( "Can't find fold region with start offset %d. Registered fold regions: %s. Document text: '%s'", startOffset, Arrays.toString(foldRegions), getEditor().getDocument().getCharsSequence() )); }