From 67f9062dcbad7f8add6821e5b2cebf400d62aed1 Mon Sep 17 00:00:00 2001 From: Konstantin Kolosovsky Date: Wed, 11 Dec 2019 19:53:36 +0300 Subject: [PATCH] vcs: Refactor "CommittedChangesListener" - provide default implementation, @NotNull, cleanup Deprecate "CommittedChangesAdapter" GitOrigin-RevId: c35fbf33f085df551484d4ecf95432b73d7cf27e --- .../committed/CommittedChangesAdapter.java | 31 ++------------- .../committed/CommittedChangesCache.java | 15 ++++--- .../committed/CommittedChangesListener.java | 39 ++++++++----------- .../CommittedChangesViewManager.java | 7 ++-- .../committed/IncomingChangesIndicator.java | 4 +- .../IncomingChangesViewProvider.java | 11 +++--- .../committed/OutdatedVersionNotifier.java | 6 +-- .../committed/CommittedChangesCacheTest.java | 10 +++-- .../svn/history/LoadedRevisionsCache.java | 9 ++--- .../history/SvnEditCommitMessageAction.java | 4 +- 10 files changed, 53 insertions(+), 83 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesAdapter.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesAdapter.java index 1e81aa219f0f..a4574e67a716 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesAdapter.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesAdapter.java @@ -1,34 +1,9 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.vcs.changes.committed; -import com.intellij.openapi.vcs.RepositoryLocation; -import com.intellij.openapi.vcs.VcsException; -import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - /** - * @author yole + * @deprecated Use {@link CommittedChangesListener} */ +@Deprecated public class CommittedChangesAdapter implements CommittedChangesListener { - @Override - public void changesLoaded(RepositoryLocation location, List changes) { - } - - @Override - public void incomingChangesUpdated(@Nullable final List receivedChanges) { - } - - @Override - public void changesCleared() { - } - - @Override - public void presentationChanged() { - } - - @Override - public void refreshErrorStatusChanged(@Nullable VcsException lastError) { - } } \ No newline at end of file diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesCache.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesCache.java index 94fb60b02aca..4b4ec026b723 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesCache.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesCache.java @@ -437,7 +437,7 @@ public class CommittedChangesCache extends SimplePersistentStateComponent changes) { + private void fireChangesLoaded(@NotNull RepositoryLocation location, @NotNull List changes) { MessageBusUtil.invokeLaterIfNeededOnSyncPublisher(myProject, COMMITTED_TOPIC, listener -> listener.changesLoaded(location, changes)); } @@ -448,7 +448,7 @@ public class CommittedChangesCache extends SimplePersistentStateComponent refreshCache(final ChangesCacheFile cacheFile) throws VcsException, IOException { + private List refreshCache(@NotNull ChangesCacheFile cacheFile) throws VcsException, IOException { debug("Refreshing cache for " + cacheFile.getLocation()); final List newLists = new ArrayList<>(); @@ -458,7 +458,7 @@ public class CommittedChangesCache extends SimplePersistentStateComponent> externalLists = myExternallyLoadedChangeLists.get(location.getKey()); final long latestChangeList = getLatestListForFile(cacheFile); if ((externalLists != null) && (latestChangeList == externalLists.first.longValue())) { - newLists.addAll(appendLoadedChanges(cacheFile, location, externalLists.second)); + newLists.addAll(appendLoadedChanges(cacheFile, externalLists.second)); myExternallyLoadedChangeLists.clear(); } @@ -484,7 +484,7 @@ public class CommittedChangesCache extends SimplePersistentStateComponent newChanges = provider.getCommittedChanges(defaultSettings, location, maxCount); debug("Loaded " + newChanges.size() + " new changelists"); - newLists.addAll(appendLoadedChanges(cacheFile, location, newChanges)); + newLists.addAll(appendLoadedChanges(cacheFile, newChanges)); return newLists; } @@ -493,11 +493,11 @@ public class CommittedChangesCache extends SimplePersistentStateComponent appendLoadedChanges(final ChangesCacheFile cacheFile, final RepositoryLocation location, + private List appendLoadedChanges(@NotNull ChangesCacheFile cacheFile, @NotNull List newChanges) throws IOException { final List savedChanges = writeChangesInReadAction(cacheFile, newChanges); if (savedChanges.size() > 0) { - fireChangesLoaded(location, savedChanges); + fireChangesLoaded(cacheFile.getLocation(), savedChanges); } return savedChanges; } @@ -629,8 +629,7 @@ public class CommittedChangesCache extends SimplePersistentStateComponent { final ChangesCacheFile file = myCachesHolder.haveCache(location); if (file != null) { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesListener.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesListener.java index ba5dfbedba90..12f94f1fee12 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesListener.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesListener.java @@ -1,34 +1,27 @@ -/* - * Copyright 2000-2009 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. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.vcs.changes.committed; import com.intellij.openapi.vcs.RepositoryLocation; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; -/** - * @author yole - */ public interface CommittedChangesListener { - void changesLoaded(RepositoryLocation location, List changes); - void incomingChangesUpdated(@Nullable final List receivedChanges); - void changesCleared(); - void presentationChanged(); - void refreshErrorStatusChanged(@Nullable VcsException lastError); + default void changesLoaded(@NotNull RepositoryLocation location, @NotNull List changes) { + } + + default void incomingChangesUpdated(@Nullable List receivedChanges) { + } + + default void changesCleared() { + } + + default void presentationChanged() { + } + + default void refreshErrorStatusChanged(@Nullable VcsException lastError) { + } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesViewManager.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesViewManager.java index 8d67cfb63037..56b958c0629c 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesViewManager.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesViewManager.java @@ -12,6 +12,7 @@ import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.messages.MessageBus; import com.intellij.util.messages.MessageBusConnection; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -83,9 +84,9 @@ public class CommittedChangesViewManager implements ChangesViewContentProvider { } } - private class MyCommittedChangesListener extends CommittedChangesAdapter { + private class MyCommittedChangesListener implements CommittedChangesListener { @Override - public void changesLoaded(RepositoryLocation location, List changes) { + public void changesLoaded(@NotNull RepositoryLocation location, @NotNull List changes) { presentationChanged(); } @@ -99,7 +100,7 @@ public class CommittedChangesViewManager implements ChangesViewContentProvider { } @Override - public void refreshErrorStatusChanged(@Nullable final VcsException lastError) { + public void refreshErrorStatusChanged(@Nullable VcsException lastError) { if (lastError != null) { VcsBalloonProblemNotifier.showOverChangesView(myProject, lastError.getMessage(), MessageType.ERROR); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/IncomingChangesIndicator.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/IncomingChangesIndicator.java index 5cc973ec0bad..c1f433b5b941 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/IncomingChangesIndicator.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/IncomingChangesIndicator.java @@ -42,9 +42,9 @@ public class IncomingChangesIndicator { myProject = project; myCache = cache; final MessageBusConnection connection = bus.connect(); - connection.subscribe(CommittedChangesCache.COMMITTED_TOPIC, new CommittedChangesAdapter() { + connection.subscribe(CommittedChangesCache.COMMITTED_TOPIC, new CommittedChangesListener() { @Override - public void incomingChangesUpdated(@Nullable final List receivedChanges) { + public void incomingChangesUpdated(@Nullable List receivedChanges) { ApplicationManager.getApplication().invokeLater(() -> refreshIndicator()); } }); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/IncomingChangesViewProvider.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/IncomingChangesViewProvider.java index c3121ac34a30..ccad58e13f50 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/IncomingChangesViewProvider.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/IncomingChangesViewProvider.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.vcs.changes.committed; import com.intellij.openapi.actionSystem.ActionGroup; @@ -18,6 +18,7 @@ import com.intellij.util.Consumer; import com.intellij.util.messages.MessageBus; import com.intellij.util.messages.MessageBusConnection; import com.intellij.util.ui.UIUtil; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -92,14 +93,14 @@ public class IncomingChangesViewProvider implements ChangesViewContentProvider { }); } - private class MyCommittedChangesListener extends CommittedChangesAdapter { + private class MyCommittedChangesListener implements CommittedChangesListener { @Override - public void changesLoaded(final RepositoryLocation location, final List changes) { + public void changesLoaded(@NotNull RepositoryLocation location, @NotNull List changes) { updateModel(true, true); } @Override - public void incomingChangesUpdated(final List receivedChanges) { + public void incomingChangesUpdated(@Nullable List receivedChanges) { updateModel(true, true); } @@ -115,7 +116,7 @@ public class IncomingChangesViewProvider implements ChangesViewContentProvider { } @Override - public void refreshErrorStatusChanged(@Nullable final VcsException lastError) { + public void refreshErrorStatusChanged(@Nullable VcsException lastError) { if (lastError != null) { VcsBalloonProblemNotifier.showOverChangesView(myProject, lastError.getMessage(), MessageType.ERROR); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/OutdatedVersionNotifier.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/OutdatedVersionNotifier.java index 04cacae0164e..86af92550e9b 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/OutdatedVersionNotifier.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/OutdatedVersionNotifier.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.vcs.changes.committed; import com.intellij.openapi.application.ApplicationManager; @@ -44,9 +44,9 @@ public class OutdatedVersionNotifier { myCache = cache; myProject = project; MessageBusConnection busConnection = messageBus.connect(); - busConnection.subscribe(CommittedChangesCache.COMMITTED_TOPIC, new CommittedChangesAdapter() { + busConnection.subscribe(CommittedChangesCache.COMMITTED_TOPIC, new CommittedChangesListener() { @Override - public void incomingChangesUpdated(@Nullable final List receivedChanges) { + public void incomingChangesUpdated(@Nullable List receivedChanges) { if (myCache.getCachedIncomingChanges() == null) { requestLoadIncomingChanges(); } diff --git a/platform/vcs-tests/testSrc/com/intellij/openapi/vcs/changes/committed/CommittedChangesCacheTest.java b/platform/vcs-tests/testSrc/com/intellij/openapi/vcs/changes/committed/CommittedChangesCacheTest.java index 683d992543cb..401dd9d7227a 100644 --- a/platform/vcs-tests/testSrc/com/intellij/openapi/vcs/changes/committed/CommittedChangesCacheTest.java +++ b/platform/vcs-tests/testSrc/com/intellij/openapi/vcs/changes/committed/CommittedChangesCacheTest.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.vcs.changes.committed; import com.intellij.openapi.application.ApplicationManager; @@ -21,6 +21,8 @@ import com.intellij.testFramework.PsiTestUtil; import com.intellij.testFramework.RunAll; import com.intellij.util.messages.MessageBusConnection; import com.intellij.vcsUtil.VcsUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.IOException; @@ -338,17 +340,17 @@ public class CommittedChangesCacheTest extends HeavyPlatformTestCase { return MockCommittedChangesProvider.createMockChange(new File(myContentRoot.getPath(), path).toString(), revision); } - private static class MockListener extends CommittedChangesAdapter { + private static class MockListener implements CommittedChangesListener { private final List myLoadedChanges = new ArrayList<>(); private final List> myIncomingChangesUpdates = new ArrayList<>(); @Override - public void changesLoaded(RepositoryLocation location, List changes) { + public void changesLoaded(@NotNull RepositoryLocation location, @NotNull List changes) { myLoadedChanges.addAll(changes); } @Override - public void incomingChangesUpdated(final List receivedChanges) { + public void incomingChangesUpdated(@Nullable List receivedChanges) { myIncomingChangesUpdates.add(receivedChanges); } diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/history/LoadedRevisionsCache.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/history/LoadedRevisionsCache.java index 48c00f04924b..c1e8eced2426 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/history/LoadedRevisionsCache.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/history/LoadedRevisionsCache.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.idea.svn.history; import com.intellij.openapi.Disposable; @@ -8,8 +8,8 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.RepositoryLocation; import com.intellij.openapi.vcs.changes.committed.ChangesBunch; -import com.intellij.openapi.vcs.changes.committed.CommittedChangesAdapter; import com.intellij.openapi.vcs.changes.committed.CommittedChangesCache; +import com.intellij.openapi.vcs.changes.committed.CommittedChangesListener; import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.messages.MessageBusConnection; @@ -36,10 +36,9 @@ public class LoadedRevisionsCache implements Disposable { myMap = (ApplicationManager.getApplication().isUnitTestMode()) ? new HashMap<>() : ContainerUtil.createSoftMap(); myConnection = project.getMessageBus().connect(); - myConnection.subscribe(CommittedChangesCache.COMMITTED_TOPIC, new CommittedChangesAdapter() { - + myConnection.subscribe(CommittedChangesCache.COMMITTED_TOPIC, new CommittedChangesListener() { @Override - public void changesLoaded(final RepositoryLocation location, final List changes) { + public void changesLoaded(@NotNull RepositoryLocation location, @NotNull List changes) { ApplicationManager.getApplication().invokeLater(() -> { myMap.clear(); setRefreshTime(System.currentTimeMillis()); diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/history/SvnEditCommitMessageAction.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/history/SvnEditCommitMessageAction.java index bc314a6f7029..4bcbd8b3f158 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/history/SvnEditCommitMessageAction.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/history/SvnEditCommitMessageAction.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.idea.svn.history; import com.intellij.openapi.actionSystem.AnActionEvent; @@ -141,7 +141,7 @@ public class SvnEditCommitMessageAction extends DumbAwareAction { myListener.consume(myNewMessage); } if (! myProject.isDefault()) { - CommittedChangesCache.getInstance(myProject).commitMessageChanged(myVcs, myLocation, myNumber, myNewMessage); + CommittedChangesCache.getInstance(myProject).commitMessageChanged(myLocation, myNumber, myNewMessage); } if (myFromVersionControl) { VcsBalloonProblemNotifier.showOverVersionControlView(myProject, "Revision #" + myNumber + " comment " +