diff --git a/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/action/RearrangeCodeAction.java b/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/action/RearrangeCodeAction.java index 65510df486de..843f8880d713 100644 --- a/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/action/RearrangeCodeAction.java +++ b/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/action/RearrangeCodeAction.java @@ -21,16 +21,11 @@ import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.editor.SelectionModel; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; import com.intellij.psi.codeStyle.arrangement.Rearranger; -import java.util.ArrayList; -import java.util.List; - /** * Arranges content at the target file(s). * @@ -66,23 +61,6 @@ public class RearrangeCodeAction extends AnAction { if (file == null) { return; } - - final List ranges = new ArrayList(); - SelectionModel selectionModel = editor.getSelectionModel(); - if (selectionModel.hasSelection()) { - ranges.add(TextRange.create(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd())); - } - else if (selectionModel.hasBlockSelection()) { - int[] starts = selectionModel.getBlockSelectionStarts(); - int[] ends = selectionModel.getBlockSelectionEnds(); - for (int i = 0; i < starts.length; i++) { - ranges.add(TextRange.create(starts[i], ends[i])); - } - } - else { - ranges.add(TextRange.create(0, document.getTextLength())); - } - - new RearrangeCodeProcessor(project, file, ranges).run(); + new RearrangeCodeProcessor(project, file, editor.getSelectionModel()).run(); } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/actions/RearrangeCodeProcessor.java b/platform/lang-impl/src/com/intellij/codeInsight/actions/RearrangeCodeProcessor.java index a4d2b820250a..91dca0b669b5 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/actions/RearrangeCodeProcessor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/actions/RearrangeCodeProcessor.java @@ -18,6 +18,7 @@ package com.intellij.codeInsight.actions; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.editor.Document; +import com.intellij.openapi.editor.SelectionModel; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.TextRange; @@ -25,11 +26,12 @@ import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; import com.intellij.psi.codeStyle.arrangement.Rearranger; import com.intellij.psi.codeStyle.arrangement.engine.ArrangementEngine; -import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.SmartList; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collection; +import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.FutureTask; @@ -39,7 +41,7 @@ public class RearrangeCodeProcessor extends AbstractLayoutCodeProcessor { public static final String PROGRESS_TEXT = "Rearranging code..."; @Nullable private Condition myAcceptCondition; - private Collection myRangesForFile = ContainerUtil.newArrayList(); + @Nullable private SelectionModel mySelectionModel; public RearrangeCodeProcessor(@NotNull AbstractLayoutCodeProcessor previousProcessor, @Nullable Condition acceptCondition) { @@ -49,18 +51,15 @@ public class RearrangeCodeProcessor extends AbstractLayoutCodeProcessor { public RearrangeCodeProcessor(@NotNull Project project, @NotNull PsiFile file, - @Nullable Collection ranges) { + @Nullable SelectionModel selectionModel) { super(project, file, PROGRESS_TEXT, COMMAND_NAME, false); - if (ranges != null) { - myRangesForFile.addAll(ranges); - } + mySelectionModel = selectionModel; } public RearrangeCodeProcessor(@NotNull Project project, @NotNull PsiFile[] files, @NotNull String commandName, - @Nullable Runnable postRunnable) - { + @Nullable Runnable postRunnable) { super(project, files, PROGRESS_TEXT, commandName, postRunnable, false); } @@ -74,25 +73,34 @@ public class RearrangeCodeProcessor extends AbstractLayoutCodeProcessor { return new FutureTask(new Callable() { @Override public Boolean call() throws Exception { - try { - if (!shouldRearrangeFile(file)) return true; - - Collection ranges = getRangesToFormat(file); - RearrangeCommand rearranger = new RearrangeCommand(myProject, file, COMMAND_NAME, ranges); - if (rearranger.couldRearrange()) { - rearranger.run(); - } - return true; - } - finally { - myRangesForFile.clear(); + if (!shouldRearrangeFile(file)) return true; + + Collection ranges = getRangesToFormat(file); + RearrangeCommand rearranger = new RearrangeCommand(myProject, file, COMMAND_NAME, ranges); + if (rearranger.couldRearrange()) { + rearranger.run(); } + return true; } }); } public Collection getRangesToFormat(@NotNull PsiFile file) { - return myRangesForFile.isEmpty() ? ContainerUtil.newArrayList(file.getTextRange()) : myRangesForFile; + final List ranges = new SmartList(); + if (mySelectionModel != null && mySelectionModel.hasSelection()) { + ranges.add(TextRange.create(mySelectionModel.getSelectionStart(), mySelectionModel.getSelectionEnd())); + } + else if (mySelectionModel != null && mySelectionModel.hasBlockSelection()) { + int[] starts = mySelectionModel.getBlockSelectionStarts(); + int[] ends = mySelectionModel.getBlockSelectionEnds(); + for (int i = 0; i < starts.length; i++) { + ranges.add(TextRange.create(starts[i], ends[i])); + } + } + else { + ranges.add(TextRange.create(0, file.getTextLength())); + } + return ranges; } } 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 d0b4d66e43ef..9ec010fcf543 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/actions/ReformatCodeAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/actions/ReformatCodeAction.java @@ -30,7 +30,6 @@ import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.editor.SelectionModel; import com.intellij.openapi.editor.ex.EditorSettingsExternalizable; import com.intellij.openapi.module.Module; import com.intellij.openapi.options.ShowSettingsUtil; @@ -57,7 +56,6 @@ import org.jetbrains.annotations.TestOnly; import javax.swing.*; import javax.swing.event.HyperlinkEvent; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; @@ -193,11 +191,7 @@ public class ReformatCodeAction extends AnAction implements DumbAware { } if (rearrangeEntries && editor != null) { - 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(); + new RearrangeCodeProcessor(project, file, editor.getSelectionModel()).run(); } } diff --git a/platform/platform-resources/src/brokenPlugins.txt b/platform/platform-resources/src/brokenPlugins.txt index a9a75cbc5189..b208cd2d7ff2 100644 --- a/platform/platform-resources/src/brokenPlugins.txt +++ b/platform/platform-resources/src/brokenPlugins.txt @@ -19,4 +19,5 @@ org.jetbrains.plugins.vagrant 0.1 0.2 org.intellij.clojure 0.2.1.178 net.nicoulaj.idea.markdown 0.9.5 0.9.4 0.9.3 0.9.2 0.9.1 0.8.3 0.8.2 0.8.1 0.8 0.7 0.6.1 0.6 0.5.1 0.5 0.4 0.3 0.2 0.1 zielu.gittoolbox 13.1.0 -com.jetbrains.chronon 134.1221 134.1414 134.1618 135.1291 135.476 135.666 \ No newline at end of file +com.jetbrains.chronon 134.1221 134.1414 134.1618 135.1291 135.476 135.666 +ArgoUML.Integration 0.1.1 0.1.2