diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/requests/RequestManagerImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/requests/RequestManagerImpl.java index 78d614b334fa..9d10487564ae 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/requests/RequestManagerImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/requests/RequestManagerImpl.java @@ -151,7 +151,7 @@ public class RequestManagerImpl extends DebugProcessAdapterImpl implements Reque request.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD); } - if (requestor.COUNT_FILTER_ENABLED) { + if (requestor.COUNT_FILTER_ENABLED && requestor.COUNT_FILTER > 0) { request.addCountFilter(requestor.COUNT_FILTER); } diff --git a/java/java-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureUtil.java b/java/java-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureUtil.java index 91f005293fad..ccf13bcce327 100644 --- a/java/java-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureUtil.java +++ b/java/java-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureUtil.java @@ -75,12 +75,12 @@ public class ChangeSignatureUtil { } } } else { - if (newElements.size() > 1) { + if (newElements.size() > 1 && (!elements.isEmpty() || index < newElements.size() - 1)) { PsiElement anchor; if (index == 0) { anchor = list.getFirstChild(); } else { - anchor = elements.get(index - 1); + anchor = index - 1 < elements.size() ? elements.get(index - 1) : null; } final PsiElement psi = Factory .createSingleLeafElement(JavaTokenType.COMMA, ",", 0, 1, SharedImplUtil.findCharTableByTree(list.getNode()), list.getManager()) diff --git a/java/java-impl/src/com/intellij/refactoring/changeSignature/DetectedJavaChangeInfo.java b/java/java-impl/src/com/intellij/refactoring/changeSignature/DetectedJavaChangeInfo.java index 9755a46d10da..a2093af6fa23 100644 --- a/java/java-impl/src/com/intellij/refactoring/changeSignature/DetectedJavaChangeInfo.java +++ b/java/java-impl/src/com/intellij/refactoring/changeSignature/DetectedJavaChangeInfo.java @@ -253,8 +253,12 @@ class DetectedJavaChangeInfo extends JavaChangeInfoImpl { final PsiMethod currentMethod = (PsiMethod)initialChangeInfo.getMethod(); if (silently || ApplicationManager.getApplication().isUnitTestMode()) { + final TextRange signatureRange = JavaChangeSignatureDetector.getSignatureRange(currentMethod); + final String currentSignature = currentMethod.getContainingFile().getText().substring(signatureRange.getStartOffset(), + signatureRange.getEndOffset()); temporallyRevertChanges(currentMethod, oldText); createChangeSignatureProcessor(method).run(); + temporallyRevertChanges(currentMethod, currentSignature, JavaChangeSignatureDetector.getSignatureRange(currentMethod)); return true; } final JavaMethodDescriptor descriptor = new JavaMethodDescriptor(currentMethod) { @@ -289,6 +293,12 @@ class DetectedJavaChangeInfo extends JavaChangeInfoImpl { } private static void temporallyRevertChanges(final PsiElement psiElement, final String oldText) { + temporallyRevertChanges(psiElement, oldText, psiElement.getTextRange()); + } + + private static void temporallyRevertChanges(final PsiElement psiElement, + final String oldText, + final TextRange textRange) { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { @@ -296,7 +306,6 @@ class DetectedJavaChangeInfo extends JavaChangeInfoImpl { final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(psiElement.getProject()); final Document document = documentManager.getDocument(file); if (document != null) { - final TextRange textRange = psiElement.getTextRange(); document.replaceString(textRange.getStartOffset(), textRange.getEndOffset(), oldText); documentManager.commitDocument(document); } diff --git a/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureDetector.java b/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureDetector.java index 291e1f286598..bb32a53612ba 100644 --- a/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureDetector.java +++ b/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaChangeSignatureDetector.java @@ -145,7 +145,7 @@ public class JavaChangeSignatureDetector implements LanguageChangeSignatureDetec textRange.getEndOffset() <= method.getTextRange().getEndOffset(); } - private static TextRange getSignatureRange(PsiMethod method) { + public static TextRange getSignatureRange(PsiMethod method) { final PsiCodeBlock body = method.getBody(); if (body != null) { return new TextRange(method.getTextRange().getStartOffset(), body.getTextOffset()); diff --git a/java/java-impl/src/com/intellij/refactoring/util/RefactoringUtil.java b/java/java-impl/src/com/intellij/refactoring/util/RefactoringUtil.java index 7cb034015791..e7499783944c 100644 --- a/java/java-impl/src/com/intellij/refactoring/util/RefactoringUtil.java +++ b/java/java-impl/src/com/intellij/refactoring/util/RefactoringUtil.java @@ -891,6 +891,7 @@ public class RefactoringUtil { final Iterable parametersIterable, final PsiSubstitutor substitutor, final PsiElementFactory factory) { + final Map replacement = new LinkedHashMap(); for (PsiTypeParameter parameter : parametersIterable) { PsiType substitutedType = substitutor.substitute(parameter); if (substitutedType == null) { @@ -900,12 +901,17 @@ public class RefactoringUtil { final PsiElement element = reference.getElement(); final PsiElement parent = element.getParent(); if (parent instanceof PsiTypeElement) { - parent.replace(factory.createTypeElement(substitutedType)); + replacement.put(parent, factory.createTypeElement(substitutedType)); } else if (element instanceof PsiJavaCodeReferenceElement && substitutedType instanceof PsiClassType) { - element.replace(factory.createReferenceElementByType((PsiClassType)substitutedType)); + replacement.put(element, factory.createReferenceElementByType((PsiClassType)substitutedType)); } } } + for (PsiElement element : replacement.keySet()) { + if (element.isValid()) { + element.replace(replacement.get(element)); + } + } } @Nullable diff --git a/java/java-tests/testData/refactoring/changeSignatureGesture/DeleteParamInSuperUsed_after.java b/java/java-tests/testData/refactoring/changeSignatureGesture/DeleteParamInSuperUsed_after.java index 5355960a925d..81b93fe139a7 100644 --- a/java/java-tests/testData/refactoring/changeSignatureGesture/DeleteParamInSuperUsed_after.java +++ b/java/java-tests/testData/refactoring/changeSignatureGesture/DeleteParamInSuperUsed_after.java @@ -5,7 +5,7 @@ public class Parent { } class Child extends Parent { - public void foo(float j, String s) { + public void foo(float j, String s ) { } void bar() { diff --git a/java/java-tests/testData/refactoring/changeSignatureGesture/MultiParams.java b/java/java-tests/testData/refactoring/changeSignatureGesture/MultiParams.java new file mode 100644 index 000000000000..cce5899370a4 --- /dev/null +++ b/java/java-tests/testData/refactoring/changeSignatureGesture/MultiParams.java @@ -0,0 +1,27 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package refactoring.changeSignatureGesture; +interface I { + void add(); +} + +public class IImpl implements I { + public void add(){} + + void foo() { + add(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/changeSignatureGesture/MultiParams_after.java b/java/java-tests/testData/refactoring/changeSignatureGesture/MultiParams_after.java new file mode 100644 index 000000000000..e98af5f6af47 --- /dev/null +++ b/java/java-tests/testData/refactoring/changeSignatureGesture/MultiParams_after.java @@ -0,0 +1,27 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package refactoring.changeSignatureGesture; +interface I { + void add(int x, int y); +} + +public class IImpl implements I { + public void add(int x, int y){} + + void foo() { + add(, ); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/pullUp/TypeParamsConflictingNames.java b/java/java-tests/testData/refactoring/pullUp/TypeParamsConflictingNames.java new file mode 100644 index 000000000000..d7b4dff9b570 --- /dev/null +++ b/java/java-tests/testData/refactoring/pullUp/TypeParamsConflictingNames.java @@ -0,0 +1,7 @@ +interface Bar { } + +interface Base { } + +class Foo implements Base { + void foo(Bar bar) { } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/pullUp/TypeParamsConflictingNames_after.java b/java/java-tests/testData/refactoring/pullUp/TypeParamsConflictingNames_after.java new file mode 100644 index 000000000000..984121891943 --- /dev/null +++ b/java/java-tests/testData/refactoring/pullUp/TypeParamsConflictingNames_after.java @@ -0,0 +1,10 @@ +interface Bar { } + +interface Base { + void foo(Bar bar); +} + +class Foo implements Base { + @Override + public void foo(Bar bar) { } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/refactoring/ChangeSignatureGestureTest.java b/java/java-tests/testSrc/com/intellij/refactoring/ChangeSignatureGestureTest.java index 79db612ff419..61f3b18f5bc8 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/ChangeSignatureGestureTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/ChangeSignatureGestureTest.java @@ -88,6 +88,10 @@ public class ChangeSignatureGestureTest extends LightCodeInsightFixtureTestCase public void testOccurrencesInSameFile() { doTypingTest("int param"); } + + public void testMultiParams() { + doTypingTest("int x, int y"); + } public void testAddParameter2Constructor() { doTypingTest("int param"); diff --git a/java/java-tests/testSrc/com/intellij/refactoring/PullUpTest.java b/java/java-tests/testSrc/com/intellij/refactoring/PullUpTest.java index c4f5a7aa0e89..141ca3afd68c 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/PullUpTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/PullUpTest.java @@ -115,6 +115,10 @@ public class PullUpTest extends LightRefactoringTestCase { doTest(false, new RefactoringTestUtil.MemberDescriptor("I", PsiClass.class)); } + public void testTypeParamsConflictingNames() throws Exception { + doTest(false, new RefactoringTestUtil.MemberDescriptor("foo", PsiMethod.class)); + } + private void doTest(RefactoringTestUtil.MemberDescriptor... membersToFind) throws Exception { doTest(true, membersToFind); } diff --git a/platform/platform-api/src/com/intellij/openapi/ui/Messages.java b/platform/platform-api/src/com/intellij/openapi/ui/Messages.java index cc69e4b78d7b..f7ac237dbc15 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/Messages.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/Messages.java @@ -814,7 +814,7 @@ public class Messages { textField.setText(textArea.getText()); } }); - String s = textField.getText().replaceAll("[\\ ]*=[\\ ]*", "="); + String s = textField.getText().replaceAll("[ ]*=[ ]*", "=").replaceAll("\\-", "\\ \\-"); List lines = StringUtil.splitHonorQuotes(s, ' '); textArea.setText(StringUtil.join(lines, "\n")); InsertPathAction.copyFromTo(textField, textArea); diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsConfiguration.java b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsConfiguration.java index 4bd2e96dc49b..ed1ee2ed824b 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsConfiguration.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsConfiguration.java @@ -73,7 +73,6 @@ public final class VcsConfiguration implements PersistentStateComponent public volatile boolean CHECK_LOCALLY_CHANGED_CONFLICTS_IN_BACKGROUND = false; public VcsShowConfirmationOption.Value MOVE_TO_FAILED_COMMIT_CHANGELIST = VcsShowConfirmationOption.Value.SHOW_CONFIRMATION; public VcsShowConfirmationOption.Value REMOVE_EMPTY_INACTIVE_CHANGELISTS = VcsShowConfirmationOption.Value.SHOW_CONFIRMATION; - public boolean ENABLE_BACKGROUND_PROCESSES = false; public int CHANGED_ON_SERVER_INTERVAL = 60; public boolean SHOW_ONLY_CHANGED_IN_SELECTION_DIFF = true; public boolean CHECK_COMMIT_MESSAGE_SPELLING = true; @@ -85,11 +84,9 @@ public final class VcsConfiguration implements PersistentStateComponent // asked only for non-DVCS public boolean INCLUDE_TEXT_INTO_PATCH = false; public boolean INCLUDE_TEXT_INTO_SHELF = false; - public boolean CREATE_PATCH_EXPAND_DETAILS_DEFAULT = true; public Boolean SHOW_PATCH_IN_EXPLORER = null; public boolean SHOW_FILE_HISTORY_DETAILS = true; public boolean SHOW_VCS_ERROR_NOTIFICATIONS = true; - public boolean CHANGE_DETAILS_ON = false; public enum StandardOption { ADD(VcsBundle.message("vcs.command.name.add")), @@ -354,6 +351,6 @@ public final class VcsConfiguration implements PersistentStateComponent } public boolean isChangedOnServerEnabled() { - return ENABLE_BACKGROUND_PROCESSES && CHECK_LOCALLY_CHANGED_CONFLICTS_IN_BACKGROUND; + return CHECK_LOCALLY_CHANGED_CONFLICTS_IN_BACKGROUND; } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CacheSettingsDialog.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CacheSettingsDialog.java index 72850b4e28a8..eeb3b66012e9 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CacheSettingsDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CacheSettingsDialog.java @@ -19,7 +19,6 @@ import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.vcs.VcsBundle; -import com.intellij.openapi.vcs.VcsConfiguration; import javax.swing.*; @@ -45,9 +44,6 @@ public class CacheSettingsDialog extends DialogWrapper { protected void doOKAction() { try { - if (myPanel.isCachingEnabled()) { - VcsConfiguration.getInstance(myProject).ENABLE_BACKGROUND_PROCESSES = true; - } myPanel.apply(); } catch (ConfigurationException e) { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CacheSettingsPanel.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CacheSettingsPanel.java index 874ed11a751f..37a1ebfe274b 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CacheSettingsPanel.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CacheSettingsPanel.java @@ -112,15 +112,8 @@ public class CacheSettingsPanel implements Configurable { public void disposeUIResources() { } - public void setEnableCaching(final boolean value) { - myRefreshCheckbox.setSelected(value); - } - public void setEnabled(final boolean value) { myRefreshCheckbox.setEnabled(value); } - public boolean isCachingEnabled() { - return myRefreshCheckbox.isSelected(); - } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsBackgroundOperationsConfigurationPanel.form b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsBackgroundOperationsConfigurationPanel.form index 7d0b32243890..b3ae11499a2d 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsBackgroundOperationsConfigurationPanel.form +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsBackgroundOperationsConfigurationPanel.form @@ -8,7 +8,7 @@ - + @@ -79,7 +79,7 @@ - + @@ -88,79 +88,58 @@ - + - + - + + + + + + + + + + + + + + + + + + + + + + + + - + - - + - + + + + + + - - - - - - - - - - - - - - - - - - - + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsBackgroundOperationsConfigurationPanel.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsBackgroundOperationsConfigurationPanel.java index 055d5e4c9e06..1a9884ee003b 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsBackgroundOperationsConfigurationPanel.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsBackgroundOperationsConfigurationPanel.java @@ -44,33 +44,26 @@ public class VcsBackgroundOperationsConfigurationPanel implements SearchableConf private JCheckBox myCbCheckoutInBackground; private JCheckBox myPerformRevertInBackgroundCheckBox; private JCheckBox myTrackChangedOnServer; - private JCheckBox myEnableBackgroundProcesses; private JComponent myCachePanel; private JSpinner myChangedOnServerInterval; - private JPanel myBackgroundProcesses; - private JPanel myCachedCommittedChanges; private CacheSettingsPanel myCacheSettingsPanel; public VcsBackgroundOperationsConfigurationPanel(final Project project) { myProject = project; if (! myProject.isDefault()) { - myEnableBackgroundProcesses.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - final boolean backgroundEnabled = myEnableBackgroundProcesses.isSelected(); - if (! backgroundEnabled) { - myCacheSettingsPanel.setEnableCaching(false); - myTrackChangedOnServer.setSelected(false); - } - myTrackChangedOnServer.setEnabled(backgroundEnabled); - myCacheSettingsPanel.setEnabled(backgroundEnabled); - } - }); myCacheSettingsPanel.initPanel(project); final VcsConfiguration settings = VcsConfiguration.getInstance(myProject); myChangedOnServerInterval.setModel(new SpinnerNumberModel(settings.CHANGED_ON_SERVER_INTERVAL, 5, 48 * 10 * 60, 5)); + + myTrackChangedOnServer.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + myChangedOnServerInterval.setEnabled(myTrackChangedOnServer.isSelected()); + } + }); + } - myBackgroundProcesses.setVisible(! myProject.isDefault()); } public void apply() throws ConfigurationException { @@ -84,12 +77,10 @@ public class VcsBackgroundOperationsConfigurationPanel implements SearchableConf settings.PERFORM_ADD_REMOVE_IN_BACKGROUND = myCbAddRemoveInBackground.isSelected(); settings.PERFORM_ROLLBACK_IN_BACKGROUND = myPerformRevertInBackgroundCheckBox.isSelected(); - boolean remoteCacheStateChanged = (settings.CHECK_LOCALLY_CHANGED_CONFLICTS_IN_BACKGROUND != myTrackChangedOnServer.isSelected()) || - (settings.ENABLE_BACKGROUND_PROCESSES = myEnableBackgroundProcesses.isSelected()); + boolean remoteCacheStateChanged = settings.CHECK_LOCALLY_CHANGED_CONFLICTS_IN_BACKGROUND != myTrackChangedOnServer.isSelected(); if (! myProject.isDefault()) { settings.CHECK_LOCALLY_CHANGED_CONFLICTS_IN_BACKGROUND = myTrackChangedOnServer.isSelected(); settings.CHANGED_ON_SERVER_INTERVAL = ((Number) myChangedOnServerInterval.getValue()).intValue(); - settings.ENABLE_BACKGROUND_PROCESSES = myEnableBackgroundProcesses.isSelected(); myCacheSettingsPanel.apply(); } @@ -130,7 +121,6 @@ public class VcsBackgroundOperationsConfigurationPanel implements SearchableConf if (settings.CHECK_LOCALLY_CHANGED_CONFLICTS_IN_BACKGROUND != myTrackChangedOnServer.isSelected()) { return true; } - if (settings.ENABLE_BACKGROUND_PROCESSES != myEnableBackgroundProcesses.isSelected()) return true; if (myCacheSettingsPanel.isModified()) return true; if (settings.CHANGED_ON_SERVER_INTERVAL != ((Number) myChangedOnServerInterval.getValue()).intValue()) return true; } @@ -151,8 +141,8 @@ public class VcsBackgroundOperationsConfigurationPanel implements SearchableConf if (! myProject.isDefault()) { myTrackChangedOnServer.setSelected(settings.CHECK_LOCALLY_CHANGED_CONFLICTS_IN_BACKGROUND); - myEnableBackgroundProcesses.setSelected(settings.ENABLE_BACKGROUND_PROCESSES); myChangedOnServerInterval.setValue(settings.CHANGED_ON_SERVER_INTERVAL); + myChangedOnServerInterval.setEnabled(myTrackChangedOnServer.isSelected()); myCacheSettingsPanel.reset(); } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/LocalChangesUnderRoots.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/LocalChangesUnderRoots.java index 3412cdb4f57c..e20dbd7d3860 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/LocalChangesUnderRoots.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/LocalChangesUnderRoots.java @@ -19,20 +19,14 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vcs.VcsRoot; -import com.intellij.openapi.vcs.changes.Change; -import com.intellij.openapi.vcs.changes.ChangeListManager; -import com.intellij.openapi.vcs.changes.ChangesUtil; -import com.intellij.openapi.vcs.changes.ContentRevision; +import com.intellij.openapi.vcs.changes.*; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; +import java.util.*; /** * Utility class to sort changes by roots. @@ -52,6 +46,19 @@ public class LocalChangesUnderRoots { myVcsManager = ProjectLevelVcsManager.getInstance(myProject); } + public Map>> getChangesByLists(@NotNull Collection rootsToSave) { + final Map>> result = new HashMap>>(); + myRoots = myVcsManager.getAllVcsRoots(); + + final List changeLists = myChangeManager.getChangeListsCopy(); + for (LocalChangeList list : changeLists) { + final HashMap> subMap = new HashMap>(); + addChangesToMap(rootsToSave, subMap, list.getChanges()); + result.put(list.getName(), subMap); + } + return result; + } + /** * Sort all changes registered in the {@link ChangeListManager} by VCS roots, * filtering out any roots except the specified ones. @@ -64,6 +71,13 @@ public class LocalChangesUnderRoots { final Collection allChanges = myChangeManager.getAllChanges(); myRoots = myVcsManager.getAllVcsRoots(); + addChangesToMap(rootsToSave, result, allChanges); + return result; + } + + private void addChangesToMap(Collection rootsToSave, + Map> result, + Collection allChanges) { for (Change change : allChanges) { if (change.getBeforeRevision() != null) { addChangeToMap(result, change, change.getBeforeRevision(), rootsToSave); @@ -72,7 +86,6 @@ public class LocalChangesUnderRoots { addChangeToMap(result, change, change.getAfterRevision(), rootsToSave); } } - return result; } private void addChangeToMap(@NotNull Map> result, @NotNull Change change, @NotNull ContentRevision revision, @NotNull Collection rootsToSave) { diff --git a/plugins/git4idea/src/git4idea/stash/GitShelveChangesSaver.java b/plugins/git4idea/src/git4idea/stash/GitShelveChangesSaver.java index 14cd4d97817d..467bf02936c8 100644 --- a/plugins/git4idea/src/git4idea/stash/GitShelveChangesSaver.java +++ b/plugins/git4idea/src/git4idea/stash/GitShelveChangesSaver.java @@ -26,6 +26,8 @@ import com.intellij.openapi.vcs.changes.shelf.ShelvedChangesViewManager; import com.intellij.openapi.vcs.impl.LocalChangesUnderRoots; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.continuation.ContinuationContext; +import com.intellij.util.continuation.TaskDescriptor; +import com.intellij.util.continuation.Where; import git4idea.commands.Git; import git4idea.i18n.GitBundle; import git4idea.rollback.GitRollbackEnvironment; @@ -40,7 +42,7 @@ public class GitShelveChangesSaver extends GitChangesSaver { private static final Logger LOG = Logger.getInstance(GitShelveChangesSaver.class); private final ShelveChangesManager myShelveManager; private final ShelvedChangesViewManager myShelveViewManager; - private ShelvedChangeList myShelvedChangeList; + private Map myShelvedLists; public GitShelveChangesSaver(Project project, Git git, ProgressIndicator indicator, String stashMessage) { super(project, git, indicator, stashMessage); @@ -51,43 +53,57 @@ public class GitShelveChangesSaver extends GitChangesSaver { @Override protected void save(@NotNull Collection rootsToSave) throws VcsException { LOG.info("save " + rootsToSave); - final Map> map = new LocalChangesUnderRoots(myProject).getChangesUnderRoots(rootsToSave); - final Set changes = new HashSet(); - for (Collection changeCollection : map.values()) { - changes.addAll(changeCollection); - } - if (! changes.isEmpty()) { - String oldProgressTitle = myProgressIndicator.getText(); - myProgressIndicator.setText(GitBundle.getString("update.shelving.changes")); - List exceptions = new ArrayList(1); - myShelvedChangeList = GitShelveUtils.shelveChanges(myProject, myShelveManager, changes, myStashMessage, exceptions, false); - myProgressIndicator.setText(oldProgressTitle); - if (! exceptions.isEmpty()) { - LOG.info("save " + exceptions, exceptions.get(0)); - throw exceptions.get(0); - } else { - for (VirtualFile root : rootsToSave) { - GitRollbackEnvironment.resetHardLocal(myProject, root); - } + final Map>> lists = new LocalChangesUnderRoots(myProject).getChangesByLists(rootsToSave); + + String oldProgressTitle = myProgressIndicator.getText(); + myProgressIndicator.setText(GitBundle.getString("update.shelving.changes")); + List exceptions = new ArrayList(1); + myShelvedLists = new HashMap(); + + for (Map.Entry>> entry : lists.entrySet()) { + final Map> map = entry.getValue(); + final Set changes = new HashSet(); + for (Collection changeCollection : map.values()) { + changes.addAll(changeCollection); + } + if (! changes.isEmpty()) { + final ShelvedChangeList list = GitShelveUtils.shelveChanges(myProject, myShelveManager, changes, + myStashMessage + " [" + entry.getKey() + "]", exceptions, false); + myShelvedLists.put(entry.getKey(), list); } } + if (! exceptions.isEmpty()) { + LOG.info("save " + exceptions, exceptions.get(0)); + myShelvedLists = null; // no restore here since during shelving changes are not rolled back... + throw exceptions.get(0); + } else { + for (VirtualFile root : rootsToSave) { + GitRollbackEnvironment.resetHardLocal(myProject, root); + } + } + myProgressIndicator.setText(oldProgressTitle); } protected void load(ContinuationContext context) { - if (myShelvedChangeList != null) { + if (myShelvedLists != null) { LOG.info("load "); - String oldProgressTitle = myProgressIndicator.getText(); + final String oldProgressTitle = myProgressIndicator.getText(); myProgressIndicator.setText(GitBundle.getString("update.unshelving.changes")); - if (myShelvedChangeList != null) { - GitShelveUtils.doSystemUnshelve(myProject, myShelvedChangeList, myShelveManager, context); + context.next(new TaskDescriptor("", Where.AWT) { + @Override + public void run(ContinuationContext context) { + myProgressIndicator.setText(oldProgressTitle); + } + }); + for (ShelvedChangeList list : myShelvedLists.values()) { + GitShelveUtils.doSystemUnshelve(myProject, list, myShelveManager, context); } - myProgressIndicator.setText(oldProgressTitle); } } @Override protected boolean wereChangesSaved() { - return myShelvedChangeList != null; + return myShelvedLists != null; } @Override @@ -97,7 +113,7 @@ public class GitShelveChangesSaver extends GitChangesSaver { @Override protected void showSavedChanges() { - myShelveViewManager.activateView(myShelvedChangeList); + myShelveViewManager.activateView(myShelvedLists.get(myShelvedLists.keySet().iterator().next())); } @Override diff --git a/plugins/git4idea/src/git4idea/update/GitComplexProcess.java b/plugins/git4idea/src/git4idea/update/GitComplexProcess.java index f85cf18f5a8d..ca6e480afc99 100644 --- a/plugins/git4idea/src/git4idea/update/GitComplexProcess.java +++ b/plugins/git4idea/src/git4idea/update/GitComplexProcess.java @@ -17,7 +17,10 @@ package git4idea.update; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.changes.ChangeListManager; -import com.intellij.util.continuation.*; +import com.intellij.util.continuation.Continuation; +import com.intellij.util.continuation.ContinuationContext; +import com.intellij.util.continuation.TaskDescriptor; +import com.intellij.util.continuation.Where; import git4idea.GitUtil; import git4idea.repo.GitRepository; import git4idea.repo.GitRepositoryManager; @@ -114,7 +117,6 @@ public class GitComplexProcess { private void run() { Continuation continuation = Continuation.createForCurrentProgress(myProject, true, myTitle); - GatheringContinuationContext initContext = new GatheringContinuationContext(); String taskTitle = "Git: " + myTitle; TaskDescriptor operation = new TaskDescriptor(taskTitle, Where.POOLED) { @Override public void run(final ContinuationContext context) { @@ -131,8 +133,7 @@ public class GitComplexProcess { UNBLOCK }; - initContext.next(tasks); - continuation.run(initContext.getList()); + continuation.run(tasks); } } diff --git a/plugins/git4idea/src/git4idea/update/GitUpdateProcess.java b/plugins/git4idea/src/git4idea/update/GitUpdateProcess.java index f857984995f6..f38a7be8cc7e 100644 --- a/plugins/git4idea/src/git4idea/update/GitUpdateProcess.java +++ b/plugins/git4idea/src/git4idea/update/GitUpdateProcess.java @@ -27,6 +27,8 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.Consumer; import com.intellij.util.continuation.ContinuationContext; import com.intellij.util.continuation.ContinuationFinalTasksInserter; +import com.intellij.util.continuation.TaskDescriptor; +import com.intellij.util.continuation.Where; import com.intellij.util.text.DateFormatUtil; import git4idea.GitBranch; import git4idea.GitUtil; @@ -236,8 +238,15 @@ public class GitUpdateProcess { // try restore changes under all circumstances final ContinuationFinalTasksInserter finalTasksInserter = new ContinuationFinalTasksInserter(context); finalTasksInserter.allNextAreFinal(); + // !!!! this task is put NEXT, i.e. if unshelve/unstash will be done synchronously or scheduled on context, + // it is unimportant -> files will be refreshed after + context.next(new TaskDescriptor("Refresh local files", Where.POOLED) { + @Override + public void run(ContinuationContext context) { + mySaver.refresh(); + } + }); mySaver.restoreLocalChanges(context); - mySaver.refresh(); finalTasksInserter.removeFinalPropertyAdder(); }