void (final List<? extends Document> documents, final Map<String, RangeMarker> sliceUsageName2Offset, final String name) { WriteCommandAction.runWriteCommandAction(null, () -> { for (int i = 1; i < 9; i++) { String newName = name + i; String s = "<flown" + newName + ">"; boolean continueExtraction = false; for (Document document : documents) { if (!document.getText().contains(s)) continue; int off = document.getText().indexOf(s); document.deleteString(off, off + s.length()); RangeMarker prev = sliceUsageName2Offset.put(newName, document.createRangeMarker(off, off)); assertNull(prev); continueExtraction = true; } if (continueExtraction) { extract(documents, sliceUsageName2Offset, newName); } } }); }