From 4080f662b0709e94ebeb347bedeca0f96f11a394 Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Sat, 4 May 2024 03:22:18 +0200 Subject: [PATCH] [lvcs] cleanup: gateway property can be not-null GitOrigin-RevId: c7813c2ba95a9bbb0d8e95118bf2acb126a7daea --- .../history/integration/LocalHistoryImpl.kt | 18 ++++++++---------- .../ui/actions/LocalHistoryAction.java | 11 ++++------- .../ui/actions/ShowHistoryAction.java | 2 +- .../openapi/command/impl/FileUndoProvider.java | 4 ++-- .../impl/actions/ChangeSetSelectionAction.kt | 2 +- .../impl/actions/RevertDifferencesAction.kt | 2 +- .../CreateIncrementalCompilationBackup.kt | 2 +- 7 files changed, 18 insertions(+), 23 deletions(-) diff --git a/platform/lvcs-impl/src/com/intellij/history/integration/LocalHistoryImpl.kt b/platform/lvcs-impl/src/com/intellij/history/integration/LocalHistoryImpl.kt index 961690371eab..27e82403365b 100644 --- a/platform/lvcs-impl/src/com/intellij/history/integration/LocalHistoryImpl.kt +++ b/platform/lvcs-impl/src/com/intellij/history/integration/LocalHistoryImpl.kt @@ -55,8 +55,7 @@ class LocalHistoryImpl(private val coroutineScope: CoroutineScope) : LocalHistor var facade: LocalHistoryFacade? = null private set - var gateway: IdeaGateway? = null - private set + val gateway: IdeaGateway = IdeaGateway() private var flusherTask: Job? = null private val initialFlush = AtomicBoolean(true) @@ -122,8 +121,7 @@ class LocalHistoryImpl(private val coroutineScope: CoroutineScope) : LocalHistor storage = InMemoryChangeListStorage() } facade = LocalHistoryFacade(ChangeList(storage)) - gateway = IdeaGateway() - eventDispatcher = LocalHistoryEventDispatcher(facade!!, gateway!!) + eventDispatcher = LocalHistoryEventDispatcher(facade!!, gateway) } override fun dispose() { @@ -186,7 +184,7 @@ class LocalHistoryImpl(private val coroutineScope: CoroutineScope) : LocalHistor return Label.NULL_INSTANCE } - gateway!!.registerUnsavedDocuments(facade!!) + gateway.registerUnsavedDocuments(facade!!) return label(facade!!.putSystemLabel(name, getProjectId(project), color)) } @@ -203,7 +201,7 @@ class LocalHistoryImpl(private val coroutineScope: CoroutineScope) : LocalHistor override fun getByteContent(path: String): ByteContent { return ApplicationManager.getApplication().runReadAction(Computable { - label.getByteContent(gateway!!.createTransientRootEntryForPath(path, false), path) + label.getByteContent(gateway.createTransientRootEntryForPath(path, false), path) }) } } @@ -215,7 +213,7 @@ class LocalHistoryImpl(private val coroutineScope: CoroutineScope) : LocalHistor } return ApplicationManager.getApplication().runReadAction(Computable { - if (gateway!!.areContentChangesVersioned(virtualFile)) { + if (gateway.areContentChangesVersioned(virtualFile)) { ByteContentRetriever(gateway, facade, virtualFile, condition).getResult() } else { @@ -224,13 +222,13 @@ class LocalHistoryImpl(private val coroutineScope: CoroutineScope) : LocalHistor }) } - override fun isUnderControl(file: VirtualFile): Boolean = isInitialized() && gateway!!.isVersioned(file) + override fun isUnderControl(file: VirtualFile): Boolean = isInitialized() && gateway.isVersioned(file) private fun isInitialized(): Boolean = isInitialized.get() @Throws(LocalHistoryException::class) private fun revertToLabel(project: Project, f: VirtualFile, label: LabelImpl) { - val path = gateway!!.getPathOrUrl(f) + val path = gateway.getPathOrUrl(f) var targetChangeSet: ChangeSet? = null var targetChange: Change? = null @@ -248,7 +246,7 @@ class LocalHistoryImpl(private val coroutineScope: CoroutineScope) : LocalHistor throw LocalHistoryException("Couldn't find label") } - val rootEntry = runReadAction { gateway!!.createTransientRootEntryForPaths(targetPaths, true) } + val rootEntry = runReadAction { gateway.createTransientRootEntryForPaths(targetPaths, true) } val leftEntry = facade!!.findEntry(rootEntry, RevisionId.ChangeSet(targetChangeSet!!.id), path, /*do not revert the change itself*/false) val rightEntry = rootEntry.findEntry(path) diff --git a/platform/lvcs-impl/src/com/intellij/history/integration/ui/actions/LocalHistoryAction.java b/platform/lvcs-impl/src/com/intellij/history/integration/ui/actions/LocalHistoryAction.java index 2c4fcdb3a41f..4375864b1fe9 100644 --- a/platform/lvcs-impl/src/com/intellij/history/integration/ui/actions/LocalHistoryAction.java +++ b/platform/lvcs-impl/src/com/intellij/history/integration/ui/actions/LocalHistoryAction.java @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.history.integration.ui.actions; @@ -15,8 +15,6 @@ import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Objects; - @ApiStatus.Internal public abstract class LocalHistoryAction extends AnAction implements DumbAware { @Override @@ -28,9 +26,8 @@ public abstract class LocalHistoryAction extends AnAction implements DumbAware { Project project = e.getProject(); LocalHistoryFacade vcs = getVcs(); - IdeaGateway gateway = getGateway(); - e.getPresentation().setEnabled(project != null && vcs != null && gateway != null); + e.getPresentation().setEnabled(project != null && vcs != null); e.getPresentation().setVisible(project != null); } @@ -43,7 +40,7 @@ public abstract class LocalHistoryAction extends AnAction implements DumbAware { public void actionPerformed(@NotNull AnActionEvent e) { Project project = e.getData(CommonDataKeys.PROJECT); if (project == null) return; - actionPerformed(project, Objects.requireNonNull(getGateway()), e); + actionPerformed(project, getGateway(), e); } protected abstract void actionPerformed(@NotNull Project p, @NotNull IdeaGateway gw, @NotNull AnActionEvent e); @@ -52,7 +49,7 @@ public abstract class LocalHistoryAction extends AnAction implements DumbAware { return LocalHistoryImpl.getInstanceImpl().getFacade(); } - protected @Nullable IdeaGateway getGateway() { + protected @NotNull IdeaGateway getGateway() { return LocalHistoryImpl.getInstanceImpl().getGateway(); } } diff --git a/platform/lvcs-impl/src/com/intellij/history/integration/ui/actions/ShowHistoryAction.java b/platform/lvcs-impl/src/com/intellij/history/integration/ui/actions/ShowHistoryAction.java index b9aca954f829..48c7e74bbfd0 100644 --- a/platform/lvcs-impl/src/com/intellij/history/integration/ui/actions/ShowHistoryAction.java +++ b/platform/lvcs-impl/src/com/intellij/history/integration/ui/actions/ShowHistoryAction.java @@ -27,7 +27,7 @@ public class ShowHistoryAction extends LocalHistoryAction { if (presentation.isEnabled()) { IdeaGateway gateway = getGateway(); Collection files = getFiles(e); - presentation.setEnabled(gateway != null && isActionEnabled(gateway, files)); + presentation.setEnabled(isActionEnabled(gateway, files)); } } diff --git a/platform/lvcs-impl/src/com/intellij/openapi/command/impl/FileUndoProvider.java b/platform/lvcs-impl/src/com/intellij/openapi/command/impl/FileUndoProvider.java index 9dc230e67f02..f74b9bb2ed1a 100644 --- a/platform/lvcs-impl/src/com/intellij/openapi/command/impl/FileUndoProvider.java +++ b/platform/lvcs-impl/src/com/intellij/openapi/command/impl/FileUndoProvider.java @@ -1,4 +1,4 @@ -// 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. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.command.impl; import com.intellij.configurationStore.StorageManagerFileWriteRequestor; @@ -49,7 +49,7 @@ public final class FileUndoProvider implements UndoProvider, BulkFileListener { if (!(localHistory instanceof LocalHistoryImpl)) return; myLocalHistory = ((LocalHistoryImpl)localHistory).getFacade(); myGateway = ((LocalHistoryImpl)localHistory).getGateway(); - if (myLocalHistory == null || myGateway == null) return; // local history was not initialized (e.g. in headless environment) + if (myLocalHistory == null) return; // local history was not initialized (e.g. in headless environment) ((LocalHistoryImpl)localHistory).addVFSListenerAfterLocalHistoryOne(this, project); myLocalHistory.addListener(new LocalHistoryFacade.Listener() { diff --git a/platform/lvcs-impl/src/com/intellij/platform/lvcs/impl/actions/ChangeSetSelectionAction.kt b/platform/lvcs-impl/src/com/intellij/platform/lvcs/impl/actions/ChangeSetSelectionAction.kt index 807b43e79dc9..6833d114d0b0 100644 --- a/platform/lvcs-impl/src/com/intellij/platform/lvcs/impl/actions/ChangeSetSelectionAction.kt +++ b/platform/lvcs-impl/src/com/intellij/platform/lvcs/impl/actions/ChangeSetSelectionAction.kt @@ -41,7 +41,7 @@ abstract class ChangeSetSelectionAction : DumbAwareAction() { val localHistoryImpl = LocalHistoryImpl.getInstanceImpl() val facade = localHistoryImpl.facade ?: return - val gateway = localHistoryImpl.gateway ?: return + val gateway = localHistoryImpl.gateway val selection = activitySelection.toChangeSetSelection() ?: return diff --git a/platform/lvcs-impl/src/com/intellij/platform/lvcs/impl/actions/RevertDifferencesAction.kt b/platform/lvcs-impl/src/com/intellij/platform/lvcs/impl/actions/RevertDifferencesAction.kt index 1fd1fc12c5ee..b9765524dfb7 100644 --- a/platform/lvcs-impl/src/com/intellij/platform/lvcs/impl/actions/RevertDifferencesAction.kt +++ b/platform/lvcs-impl/src/com/intellij/platform/lvcs/impl/actions/RevertDifferencesAction.kt @@ -39,7 +39,7 @@ internal class RevertDifferencesAction : DumbAwareAction() { val localHistoryImpl = LocalHistoryImpl.getInstanceImpl() val facade = localHistoryImpl.facade ?: return - val gateway = localHistoryImpl.gateway ?: return + val gateway = localHistoryImpl.gateway LocalHistoryCounter.logActionInvoked(LocalHistoryCounter.ActionKind.RevertChanges, activityScope) diff --git a/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/internal/makeBackup/CreateIncrementalCompilationBackup.kt b/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/internal/makeBackup/CreateIncrementalCompilationBackup.kt index 1fb901ecbb8f..8693a7d88144 100644 --- a/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/internal/makeBackup/CreateIncrementalCompilationBackup.kt +++ b/plugins/kotlin/jvm/src/org/jetbrains/kotlin/idea/internal/makeBackup/CreateIncrementalCompilationBackup.kt @@ -72,7 +72,7 @@ class CreateIncrementalCompilationBackup : AnAction(KotlinJvmBundle.message("cre private fun createPatches(backupDir: File, project: Project, indicator: ProgressIndicator) { runReadAction { val localHistoryImpl = LocalHistoryImpl.getInstanceImpl()!! - val gateway = localHistoryImpl.gateway!! + val gateway = localHistoryImpl.gateway val localHistoryFacade = localHistoryImpl.facade val revisions = RevisionsCollector.collect(