From e167f2fdad88487f134c1f30ff9acbb1c77d72d9 Mon Sep 17 00:00:00 2001 From: Yaroslav Lepenkin Date: Mon, 13 Oct 2014 17:33:46 +0400 Subject: [PATCH] use rearrange code processor instead of direct call, fix for possible ReadOnlyModificationException --- .../actions/ReformatCodeAction.java | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/actions/ReformatCodeAction.java b/platform/lang-impl/src/com/intellij/codeInsight/actions/ReformatCodeAction.java index 8ec833e8258b..d7a8b0c2661e 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/actions/ReformatCodeAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/actions/ReformatCodeAction.java @@ -187,23 +187,11 @@ public class ReformatCodeAction extends AnAction implements DumbAware { } if (rearrangeEntries && file != null && editor != null) { - final ArrangementEngine engine = ServiceManager.getService(project, ArrangementEngine.class); - try { - final PsiFile finalFile = file; - SelectionModel selectionModel = editor.getSelectionModel(); - final TextRange rangeToUse = selectionModel.hasSelection() - ? TextRange.create(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd()) - : TextRange.create(0, editor.getDocument().getTextLength()); - CommandProcessor.getInstance().executeCommand(project, new Runnable() { - @Override - public void run() { - engine.arrange(editor, finalFile, Collections.singleton(rangeToUse)); - } - }, getTemplatePresentation().getText(), null); - } - finally { - PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument()); - } + SelectionModel selectionModel = editor.getSelectionModel(); + final TextRange rangeToUse = selectionModel.hasSelection() + ? TextRange.create(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd()) + : TextRange.create(0, editor.getDocument().getTextLength()); + new RearrangeCodeProcessor(project, file, Collections.singleton(rangeToUse)).run(); } }