Merge remote-tracking branch 'origin/master'

This commit is contained in:
Alexander Lobas
2012-06-19 15:25:03 +04:00
22 changed files with 236 additions and 148 deletions
@@ -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);
}
@@ -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())
@@ -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);
}
@@ -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());
@@ -891,6 +891,7 @@ public class RefactoringUtil {
final Iterable<PsiTypeParameter> parametersIterable,
final PsiSubstitutor substitutor,
final PsiElementFactory factory) {
final Map<PsiElement, PsiElement> replacement = new LinkedHashMap<PsiElement, PsiElement>();
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
@@ -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() {
@@ -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(<caret>);
}
public class IImpl implements I {
public void add(){}
void foo() {
add();
}
}
@@ -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(, );
}
}
@@ -0,0 +1,7 @@
interface Bar<T> { }
interface Base<T> { }
class Foo<T,U> implements Base<U> {
void fo<caret>o(Bar<U> bar) { }
}
@@ -0,0 +1,10 @@
interface Bar<T> { }
interface Base<T> {
void foo(Bar<T> bar);
}
class Foo<T,U> implements Base<U> {
@Override
public void foo(Bar<U> bar) { }
}
@@ -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");
@@ -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);
}
@@ -814,7 +814,7 @@ public class Messages {
textField.setText(textArea.getText());
}
});
String s = textField.getText().replaceAll("[\\ ]*=[\\ ]*", "=");
String s = textField.getText().replaceAll("[ ]*=[ ]*", "=").replaceAll("\\-", "\\ \\-");
List<String> lines = StringUtil.splitHonorQuotes(s, ' ');
textArea.setText(StringUtil.join(lines, "\n"));
InsertPathAction.copyFromTo(textField, textArea);
@@ -73,7 +73,6 @@ public final class VcsConfiguration implements PersistentStateComponent<Element>
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<Element>
// 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<Element>
}
public boolean isChangedOnServerEnabled() {
return ENABLE_BACKGROUND_PROCESSES && CHECK_LOCALLY_CHANGED_CONFLICTS_IN_BACKGROUND;
return CHECK_LOCALLY_CHANGED_CONFLICTS_IN_BACKGROUND;
}
}
@@ -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) {
@@ -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();
}
}
@@ -8,7 +8,7 @@
<properties/>
<border type="none"/>
<children>
<grid id="e714c" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="e714c" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
@@ -79,7 +79,7 @@
</component>
</children>
</grid>
<grid id="d20ff" binding="myBackgroundProcesses" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="edb40" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -88,79 +88,58 @@
<clientProperties>
<BorderFactoryClass class="java.lang.String" value="com.intellij.ui.IdeBorderFactory$PlainSmallWithIndent"/>
</clientProperties>
<border type="none" title-resource-bundle="messages/VcsBundle" title-key="options.background.processes.title"/>
<border type="none" title-resource-bundle="messages/VcsBundle" title-key="cache.settings.dialog.title"/>
<children>
<component id="de949" class="javax.swing.JCheckBox" binding="myEnableBackgroundProcesses">
<component id="f7b04" class="javax.swing.JComponent" binding="myCachePanel" custom-create="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
</component>
<hspacer id="8e704">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
</children>
</grid>
<grid id="9c106" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<clientProperties>
<BorderFactoryClass class="java.lang.String" value="com.intellij.ui.IdeBorderFactory$PlainSmallWithIndent"/>
</clientProperties>
<border type="none" title-resource-bundle="messages/VcsBundle" title-key="options.check.changed.on.server.title"/>
<children>
<component id="9e0bc" class="javax.swing.JCheckBox" binding="myTrackChangedOnServer">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/VcsBundle" key="options.background.processes.enable"/>
<text resource-bundle="messages/VcsBundle" key="vcs.config.track.changed.on.server"/>
</properties>
</component>
<grid id="edb40" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<hspacer id="899ad">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="6b1ed" class="javax.swing.JSpinner" binding="myChangedOnServerInterval">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<clientProperties>
<BorderFactoryClass class="java.lang.String" value="com.intellij.ui.IdeBorderFactory$PlainSmallWithIndent"/>
</clientProperties>
<border type="none" title-resource-bundle="messages/VcsBundle" title-key="cache.settings.dialog.title"/>
<children>
<component id="f7b04" class="javax.swing.JComponent" binding="myCachePanel" custom-create="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
</component>
<hspacer id="8e704">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
</children>
</grid>
<grid id="9c106" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
</component>
<component id="765cd" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<clientProperties>
<BorderFactoryClass class="java.lang.String" value="com.intellij.ui.IdeBorderFactory$PlainSmallWithIndent"/>
</clientProperties>
<border type="none" title-resource-bundle="messages/VcsBundle" title-key="options.check.changed.on.server.title"/>
<children>
<component id="9e0bc" class="javax.swing.JCheckBox" binding="myTrackChangedOnServer">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/VcsBundle" key="vcs.config.track.changed.on.server"/>
</properties>
</component>
<hspacer id="899ad">
<constraints>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="6b1ed" class="javax.swing.JSpinner" binding="myChangedOnServerInterval">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="765cd" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="minutes"/>
</properties>
</component>
</children>
</grid>
<properties>
<text value="minutes"/>
</properties>
</component>
</children>
</grid>
</children>
@@ -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();
}
}
@@ -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<String, Map<VirtualFile, Collection<Change>>> getChangesByLists(@NotNull Collection<VirtualFile> rootsToSave) {
final Map<String, Map<VirtualFile, Collection<Change>>> result = new HashMap<String, Map<VirtualFile, Collection<Change>>>();
myRoots = myVcsManager.getAllVcsRoots();
final List<LocalChangeList> changeLists = myChangeManager.getChangeListsCopy();
for (LocalChangeList list : changeLists) {
final HashMap<VirtualFile, Collection<Change>> subMap = new HashMap<VirtualFile, Collection<Change>>();
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<Change> allChanges = myChangeManager.getAllChanges();
myRoots = myVcsManager.getAllVcsRoots();
addChangesToMap(rootsToSave, result, allChanges);
return result;
}
private void addChangesToMap(Collection<VirtualFile> rootsToSave,
Map<VirtualFile, Collection<Change>> result,
Collection<Change> 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<VirtualFile, Collection<Change>> result, @NotNull Change change, @NotNull ContentRevision revision, @NotNull Collection<VirtualFile> rootsToSave) {
@@ -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<String, ShelvedChangeList> 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<VirtualFile> rootsToSave) throws VcsException {
LOG.info("save " + rootsToSave);
final Map<VirtualFile,Collection<Change>> map = new LocalChangesUnderRoots(myProject).getChangesUnderRoots(rootsToSave);
final Set<Change> changes = new HashSet<Change>();
for (Collection<Change> changeCollection : map.values()) {
changes.addAll(changeCollection);
}
if (! changes.isEmpty()) {
String oldProgressTitle = myProgressIndicator.getText();
myProgressIndicator.setText(GitBundle.getString("update.shelving.changes"));
List<VcsException> exceptions = new ArrayList<VcsException>(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<String, Map<VirtualFile, Collection<Change>>> lists = new LocalChangesUnderRoots(myProject).getChangesByLists(rootsToSave);
String oldProgressTitle = myProgressIndicator.getText();
myProgressIndicator.setText(GitBundle.getString("update.shelving.changes"));
List<VcsException> exceptions = new ArrayList<VcsException>(1);
myShelvedLists = new HashMap<String, ShelvedChangeList>();
for (Map.Entry<String, Map<VirtualFile, Collection<Change>>> entry : lists.entrySet()) {
final Map<VirtualFile, Collection<Change>> map = entry.getValue();
final Set<Change> changes = new HashSet<Change>();
for (Collection<Change> 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
@@ -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);
}
}
@@ -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();
}