From a7cbe46394e5ada23a58c2340202008a817fd77a Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Mon, 8 Jul 2019 16:54:54 +0300 Subject: [PATCH] vcs: remove unnecessary nullability checks GitOrigin-RevId: c111201e1318f48bc196b31fcc48787aba34fc91 --- .../org/jetbrains/ide/OpenFileHttpService.kt | 11 ++++----- .../dvcs/repo/VcsRepositoryManager.java | 2 +- .../vcs/actions/CommonCheckinProjectAction.kt | 2 +- .../vcs/changes/VcsDirtyScopeImpl.java | 24 +++++++++---------- .../vcs/changes/VcsDirtyScopeManagerImpl.java | 2 +- .../openapi/vcs/impl/VcsRootIterator.java | 9 +++---- .../vcs/roots/VcsRootErrorsFinder.java | 7 +----- .../vcs/statistics/VcsUsagesCollector.kt | 2 +- .../vcs/commit/AmendCommitHandlerImpl.kt | 2 +- .../intellij/vcs/log/impl/VcsLogManager.java | 2 +- .../vcs/roots/VcsIntegrationEnablerTest.kt | 5 ++-- .../src/com/jetbrains/changeReminder/util.kt | 5 +--- .../git4idea/src/git4idea/actions/GitAdd.java | 5 +--- .../checkin/GitCheckinHandlerFactory.java | 2 +- 14 files changed, 30 insertions(+), 50 deletions(-) diff --git a/platform/built-in-server/src/org/jetbrains/ide/OpenFileHttpService.kt b/platform/built-in-server/src/org/jetbrains/ide/OpenFileHttpService.kt index 52a7ea805ecd..fbf58830f63e 100644 --- a/platform/built-in-server/src/org/jetbrains/ide/OpenFileHttpService.kt +++ b/platform/built-in-server/src/org/jetbrains/ide/OpenFileHttpService.kt @@ -221,13 +221,10 @@ private fun openRelativePath(path: String, request: OpenFileRequest): Boolean { if (virtualFile == null) { for (openedProject in projects) { for (vcsRoot in ProjectLevelVcsManager.getInstance(openedProject).allVcsRoots) { - val root = vcsRoot.path - if (root != null) { - virtualFile = root.findFileByRelativePath(path) - if (virtualFile != null) { - project = openedProject - break - } + virtualFile = vcsRoot.path.findFileByRelativePath(path) + if (virtualFile != null) { + project = openedProject + break } } } diff --git a/platform/dvcs-impl/src/com/intellij/dvcs/repo/VcsRepositoryManager.java b/platform/dvcs-impl/src/com/intellij/dvcs/repo/VcsRepositoryManager.java index 306b1a0d1dd5..12d60aa21857 100644 --- a/platform/dvcs-impl/src/com/intellij/dvcs/repo/VcsRepositoryManager.java +++ b/platform/dvcs-impl/src/com/intellij/dvcs/repo/VcsRepositoryManager.java @@ -264,7 +264,7 @@ public class VcsRepositoryManager implements Disposable, VcsListener { Map newRootsMap = new HashMap<>(); for (VcsRoot root : myVcsManager.getAllVcsRoots()) { VirtualFile rootPath = root.getPath(); - if (rootPath != null && !knownRoots.contains(rootPath)) { + if (!knownRoots.contains(rootPath)) { AbstractVcs vcs = root.getVcs(); VcsRepositoryCreator repositoryCreator = getRepositoryCreator(vcs); if (repositoryCreator == null) continue; diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/CommonCheckinProjectAction.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/CommonCheckinProjectAction.kt index 3f4f58f663a2..476d8c59ce50 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/CommonCheckinProjectAction.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/CommonCheckinProjectAction.kt @@ -9,7 +9,7 @@ open class CommonCheckinProjectAction : AbstractCommonCheckinAction() { override fun getRoots(dataContext: VcsContext): Array = ProjectLevelVcsManager.getInstance(dataContext.project!!).allVcsRoots .filter { it.vcs!!.checkinEnvironment != null } - .map { getFilePath(it.path!!) } + .map { getFilePath(it.path) } .toTypedArray() override fun approximatelyHasRoots(dataContext: VcsContext): Boolean = true diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsDirtyScopeImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsDirtyScopeImpl.java index 06d536fedeaa..dd3d852811ce 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsDirtyScopeImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsDirtyScopeImpl.java @@ -427,19 +427,17 @@ public class VcsDirtyScopeImpl extends VcsModifiableDirtyScope { } final VirtualFile vcsRoot = rootObject.getPath(); - if (vcsRoot != null) { - boolean pathIsRoot = vcsRoot.equals(path.getVirtualFile()); - for (VirtualFile contentRoot : myAffectedContentRoots) { - // since we don't know exact dirty mechanics, maybe we have 3 nested mappings like: - // /root -> vcs1, /root/child -> vcs2, /root/child/inner -> vcs1, and we have file /root/child/inner/file, - // mapping is detected as vcs1 with root /root/child/inner, but we could possibly have in scope - // "affected root" -> /root with scope = /root recursively - boolean strict = pathIsRoot && !myVcs.areDirectoriesVersionedItems(); - if (VfsUtilCore.isAncestor(contentRoot, vcsRoot, strict)) { - THashSet dirsByRoot = myDirtyDirectoriesRecursively.get(contentRoot); - if (dirsByRoot != null && hasAncestor(dirsByRoot, path)) { - return true; - } + boolean pathIsRoot = vcsRoot.equals(path.getVirtualFile()); + for (VirtualFile contentRoot : myAffectedContentRoots) { + // since we don't know exact dirty mechanics, maybe we have 3 nested mappings like: + // /root -> vcs1, /root/child -> vcs2, /root/child/inner -> vcs1, and we have file /root/child/inner/file, + // mapping is detected as vcs1 with root /root/child/inner, but we could possibly have in scope + // "affected root" -> /root with scope = /root recursively + boolean strict = pathIsRoot && !myVcs.areDirectoriesVersionedItems(); + if (VfsUtilCore.isAncestor(contentRoot, vcsRoot, strict)) { + THashSet dirsByRoot = myDirtyDirectoriesRecursively.get(contentRoot); + if (dirsByRoot != null && hasAncestor(dirsByRoot, path)) { + return true; } } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsDirtyScopeManagerImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsDirtyScopeManagerImpl.java index 66bcf09d0f9d..ac4e8ce68281 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsDirtyScopeManagerImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsDirtyScopeManagerImpl.java @@ -240,7 +240,7 @@ public class VcsDirtyScopeManagerImpl extends VcsDirtyScopeManager implements Pr for (VcsRoot root : roots) { AbstractVcs vcs = root.getVcs(); VirtualFile path = root.getPath(); - if (vcs != null && path != null) { + if (vcs != null) { dirtyRoots.putValue(vcs, VcsUtil.getFilePath(path)); } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/VcsRootIterator.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/VcsRootIterator.java index ec1abe59c66b..0ed311820f42 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/VcsRootIterator.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/VcsRootIterator.java @@ -87,12 +87,9 @@ public class VcsRootIterator { for (VcsRoot root : allRoots) { final AbstractVcs vcs = root.getVcs(); if (vcs == null || Comparing.equal(vcs.getName(), myVcsName)) continue; - final VirtualFile path = root.getPath(); - if (path != null) { - final String url = path.getUrl(); - if (url.startsWith(ourPath)) { - myExcludedByOthers.add(url); - } + final String url = root.getPath().getUrl(); + if (url.startsWith(ourPath)) { + myExcludedByOthers.add(url); } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootErrorsFinder.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootErrorsFinder.java index feeb35c3a1dd..a3f1e35adfd5 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootErrorsFinder.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/roots/VcsRootErrorsFinder.java @@ -6,7 +6,6 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.*; -import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -51,11 +50,7 @@ public class VcsRootErrorsFinder { Collection errors = new ArrayList<>(); List mappedPaths = mappingsToPathsWithSelectedVcs(mappings); for (VcsRoot root : vcsRoots) { - VirtualFile virtualFileFromRoot = root.getPath(); - if (virtualFileFromRoot == null) { - continue; - } - String vcsPath = virtualFileFromRoot.getPath(); + String vcsPath = root.getPath().getPath(); if (root.getVcs() != null && !mappedPaths.contains(vcsPath)) { errors.add(new VcsRootErrorImpl(VcsRootError.Type.UNREGISTERED_ROOT, vcsPath, root.getVcs().getName())); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/statistics/VcsUsagesCollector.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/statistics/VcsUsagesCollector.kt index 0a56dd5a63b2..8c89d94087e3 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/statistics/VcsUsagesCollector.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/statistics/VcsUsagesCollector.kt @@ -61,7 +61,7 @@ class VcsUsagesCollector : ProjectUsagesCollector() { val projectMappedRoots = vcsManager.allVcsRoots .filter { it.vcs == defaultVcs } - .filter { it.path != null && !explicitRoots.contains(it.path) } + .filter { !explicitRoots.contains(it.path) } for (vcsRoot in projectMappedRoots) { val metric = newMetric("project.mapped.root") diff --git a/platform/vcs-impl/src/com/intellij/vcs/commit/AmendCommitHandlerImpl.kt b/platform/vcs-impl/src/com/intellij/vcs/commit/AmendCommitHandlerImpl.kt index 4799814fcc25..df61ccb9acb5 100644 --- a/platform/vcs-impl/src/com/intellij/vcs/commit/AmendCommitHandlerImpl.kt +++ b/platform/vcs-impl/src/com/intellij/vcs/commit/AmendCommitHandlerImpl.kt @@ -108,7 +108,7 @@ class AmendCommitHandlerImpl(private val workflowHandler: AbstractCommitWorkflow override fun compute(indicator: ProgressIndicator): List = roots.mapNotNull { vcsRoot -> val amendAware = vcsRoot.vcs?.checkinEnvironment as? AmendCommitAware ?: return@mapNotNull null - vcsRoot.path?.let { amendAware.getLastCommitMessage(it) } + amendAware.getLastCommitMessage(vcsRoot.path) } } } \ No newline at end of file diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogManager.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogManager.java index 44950035d28a..ab2c4dfeaf57 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogManager.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogManager.java @@ -145,7 +145,7 @@ public class VcsLogManager implements Disposable { for (VcsRoot root : roots) { AbstractVcs vcs = root.getVcs(); VirtualFile path = root.getPath(); - if (vcs == null || path == null) { + if (vcs == null) { LOG.debug("Skipping invalid VCS root: " + root); continue; } diff --git a/platform/vcs-tests/testSrc/com/intellij/openapi/vcs/roots/VcsIntegrationEnablerTest.kt b/platform/vcs-tests/testSrc/com/intellij/openapi/vcs/roots/VcsIntegrationEnablerTest.kt index 39eaaea12a5f..8a5038d542b6 100644 --- a/platform/vcs-tests/testSrc/com/intellij/openapi/vcs/roots/VcsIntegrationEnablerTest.kt +++ b/platform/vcs-tests/testSrc/com/intellij/openapi/vcs/roots/VcsIntegrationEnablerTest.kt @@ -70,15 +70,14 @@ class VcsIntegrationEnablerTest : VcsRootBaseTest() { mock_init: String?, vararg vcs_roots: String) { for (vcsRoot in vcsRoots) { - assertTrue(File(vcsRoot.path!!.path, DOT_MOCK).mkdirs()) + assertTrue(File(vcsRoot.path.path, DOT_MOCK).mkdirs()) } val vcsRootsList = mutableListOf(*vcs_roots) //default if (vcsRootsList.isEmpty()) { vcsRootsList.addAll(ContainerUtil.map(vcsRoots) { root -> - assert(root.path != null) - root.path!!.path + root.path.path }) } TestIntegrationEnabler(vcs).enable(vcsRoots) diff --git a/plugins/changeReminder/src/com/jetbrains/changeReminder/util.kt b/plugins/changeReminder/src/com/jetbrains/changeReminder/util.kt index 7448495b65f4..59908bb18a6d 100644 --- a/plugins/changeReminder/src/com/jetbrains/changeReminder/util.kt +++ b/plugins/changeReminder/src/com/jetbrains/changeReminder/util.kt @@ -21,10 +21,7 @@ fun getGitRootFiles(project: Project, files: Collection): Map val fileVcs = projectLevelVcsManager.getVcsRootObjectFor(filePath) if (fileVcs != null && fileVcs.vcs is GitVcs) { - val fileRoot = fileVcs.path - if (fileRoot != null) { - rootFiles.getOrPut(fileRoot) { HashSet() }.add(filePath) - } + rootFiles.getOrPut(fileVcs.path) { HashSet() }.add(filePath) } } return rootFiles diff --git a/plugins/git4idea/src/git4idea/actions/GitAdd.java b/plugins/git4idea/src/git4idea/actions/GitAdd.java index fef3463d000b..1b8ea749977b 100644 --- a/plugins/git4idea/src/git4idea/actions/GitAdd.java +++ b/plugins/git4idea/src/git4idea/actions/GitAdd.java @@ -83,10 +83,7 @@ public class GitAdd extends ScheduleForAdditionAction { try { if (!(vcsRoot.getVcs() instanceof GitVcs)) return; - VirtualFile root = vcsRoot.getPath(); - if (root == null) return; - - GitFileUtils.addPaths(project, root, paths); + GitFileUtils.addPaths(project, vcsRoot.getPath(), paths); VcsFileUtil.markFilesDirty(project, paths); } catch (VcsException ex) { diff --git a/plugins/git4idea/src/git4idea/checkin/GitCheckinHandlerFactory.java b/plugins/git4idea/src/git4idea/checkin/GitCheckinHandlerFactory.java index b29344068353..a9b8b7c360ff 100644 --- a/plugins/git4idea/src/git4idea/checkin/GitCheckinHandlerFactory.java +++ b/plugins/git4idea/src/git4idea/checkin/GitCheckinHandlerFactory.java @@ -366,7 +366,7 @@ public class GitCheckinHandlerFactory extends VcsCheckinHandlerFactory { VcsRoot vcsRoot = vcsManager.getVcsRootObjectFor(path); if (vcsRoot != null) { VirtualFile root = vcsRoot.getPath(); - if (git.equals(vcsRoot.getVcs()) && root != null) { + if (git.equals(vcsRoot.getVcs())) { result.add(root); } }