diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ComponentStoreImpl.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ComponentStoreImpl.java index 95e82d2b1b7e..700d12562673 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ComponentStoreImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ComponentStoreImpl.java @@ -540,18 +540,13 @@ public abstract class ComponentStoreImpl implements IComponentStore.Reloadable { } @NotNull - public static ReloadComponentStoreStatus reloadStore(@NotNull Collection> changedStorages, @NotNull IComponentStore.Reloadable store) { - MultiMap storageToFiles = MultiMap.createLinkedSet(); - for (Pair pair : changedStorages) { - storageToFiles.putValue(pair.second, pair.first); - } - + public static ReloadComponentStoreStatus reloadStore(@NotNull MultiMap changes, @NotNull IComponentStore.Reloadable store) { Collection notReloadableComponents; boolean willBeReloaded = false; try { AccessToken token = WriteAction.start(); try { - notReloadableComponents = store.reload(storageToFiles); + notReloadableComponents = store.reload(changes); } catch (Throwable e) { Messages.showWarningDialog(ProjectBundle.message("project.reload.failed", e.getMessage()), @@ -566,12 +561,12 @@ public abstract class ComponentStoreImpl implements IComponentStore.Reloadable { return ReloadComponentStoreStatus.SUCCESS; } - willBeReloaded = askToRestart(store, notReloadableComponents, changedStorages); + willBeReloaded = askToRestart(store, notReloadableComponents, changes); return willBeReloaded ? ReloadComponentStoreStatus.RESTART_AGREED : ReloadComponentStoreStatus.RESTART_CANCELLED; } finally { if (!willBeReloaded) { - for (StateStorage storage : storageToFiles.keySet()) { + for (StateStorage storage : changes.keySet()) { if (storage instanceof StateStorageBase) { ((StateStorageBase)storage).enableSaving(); } @@ -583,7 +578,7 @@ public abstract class ComponentStoreImpl implements IComponentStore.Reloadable { // used in settings repository plugin public static boolean askToRestart(@NotNull Reloadable store, @NotNull Collection notReloadableComponents, - @Nullable Collection> changedStorages) { + @Nullable MultiMap changedStorages) { StringBuilder message = new StringBuilder(); String storeName = store instanceof IApplicationStore ? "Application" : "Project"; message.append(storeName).append(' '); @@ -611,8 +606,7 @@ public abstract class ComponentStoreImpl implements IComponentStore.Reloadable { if (Messages.showYesNoDialog(message.toString(), storeName + " Files Changed", Messages.getQuestionIcon()) == Messages.YES) { if (changedStorages != null) { - for (Pair cause : changedStorages) { - StateStorage storage = cause.getSecond(); + for (StateStorage storage : changedStorages.keySet()) { if (storage instanceof StateStorageBase) { ((StateStorageBase)storage).disableSaving(); } diff --git a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java index 2fc79974cee9..d39275763b53 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java @@ -59,9 +59,9 @@ import com.intellij.util.SingleAlarm; import com.intellij.util.SmartList; import com.intellij.util.TimeoutUtil; import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.containers.MultiMap; import com.intellij.util.messages.MessageBus; import com.intellij.util.ui.UIUtil; -import gnu.trove.THashSet; import org.jdom.Element; import org.jdom.JDOMException; import org.jetbrains.annotations.NonNls; @@ -84,7 +84,7 @@ public class ProjectManagerImpl extends ProjectManagerEx implements PersistentSt public static final int CURRENT_FORMAT_VERSION = 4; private static final Key> LISTENERS_IN_PROJECT_KEY = Key.create("LISTENERS_IN_PROJECT_KEY"); - private static final Key>> CHANGED_FILES_KEY = Key.create("CHANGED_FILES_KEY"); + private static final Key> CHANGED_FILES_KEY = Key.create("CHANGED_FILES_KEY"); @SuppressWarnings("FieldAccessedSynchronizedAndUnsynchronized") private ProjectImpl myDefaultProject; // Only used asynchronously in save and dispose, which itself are synchronized. @@ -97,7 +97,7 @@ public class ProjectManagerImpl extends ProjectManagerEx implements PersistentSt private final List myListeners = ContainerUtil.createLockFreeCopyOnWriteList(); private final SingleAlarm myChangedFilesAlarm; - private final List> myChangedApplicationFiles = new SmartList>(); + private final MultiMap myChangedApplicationFiles = MultiMap.createLinkedSet(); private final AtomicInteger myReloadBlockCount = new AtomicInteger(0); private final ProgressManager myProgressManager; @@ -652,7 +652,7 @@ public class ProjectManagerImpl extends ProjectManagerEx implements PersistentSt continue; } - List> changes = CHANGED_FILES_KEY.get(project); + MultiMap changes = CHANGED_FILES_KEY.get(project); if (changes == null) { continue; } @@ -676,10 +676,11 @@ public class ProjectManagerImpl extends ProjectManagerEx implements PersistentSt return true; } - Set> causes = new THashSet>(myChangedApplicationFiles); + MultiMap changes = MultiMap.createLinkedSet(); + changes.putAllValues(myChangedApplicationFiles); myChangedApplicationFiles.clear(); - ReloadComponentStoreStatus status = ComponentStoreImpl.reloadStore(causes, ((ApplicationImpl)ApplicationManager.getApplication()).getStateStore()); + ReloadComponentStoreStatus status = ComponentStoreImpl.reloadStore(changes, ((ApplicationImpl)ApplicationManager.getApplication()).getStateStore()); if (status == ReloadComponentStoreStatus.RESTART_AGREED) { ApplicationManagerEx.getApplicationEx().restart(true); return false; @@ -743,20 +744,21 @@ public class ProjectManagerImpl extends ProjectManagerEx implements PersistentSt LOG.debug("[RELOAD] Registering project to reload: " + file, new Exception()); } + MultiMap changes; if (project == null) { - myChangedApplicationFiles.add(Pair.create(file, storage)); + changes = myChangedApplicationFiles; } else { - List> changes = CHANGED_FILES_KEY.get(project); + changes = CHANGED_FILES_KEY.get(project); if (changes == null) { - changes = new SmartList>(); + changes = MultiMap.createLinkedSet(); CHANGED_FILES_KEY.set(project, changes); } + } - //noinspection SynchronizationOnLocalVariableOrMethodParameter - synchronized (changes) { - changes.add(Pair.create(file, storage)); - } + //noinspection SynchronizationOnLocalVariableOrMethodParameter + synchronized (changes) { + changes.putValue(storage, file); } if (storage instanceof StateStorageBase) {