void (@NotNull Document document, boolean isViewer, Consumer<? super Editor> task) { EditorFactory editorFactory = EditorFactory.getInstance(); Editor editor = isViewer ? editorFactory.createViewer(document) : editorFactory.createEditor(document); try { task.consume(editor); } finally { editorFactory.releaseEditor(editor); } }