shared-indexes: reduce nesting in the code (minor)

GitOrigin-RevId: 03d9bf18f3d276672914ed79746330d7290d999a
This commit is contained in:
Eugene Petrenko
2020-05-04 19:44:52 +00:00
committed by intellij-monorepo-bot
parent 7186d41f33
commit 66118cc40e
@@ -1,3 +1,4 @@
// Copyright 2000-2020 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.util.indexing.diagnostic.dump.paths.providers
import com.intellij.openapi.project.Project
@@ -11,21 +12,20 @@ import com.intellij.util.indexing.diagnostic.dump.paths.PortableFilePath
object JdkPortableFilePathProvider : PortableFilePathProvider {
override fun getRelativePortableFilePath(project: Project, virtualFile: VirtualFile): PortableFilePath.RelativePath? {
val orderEntry = LibraryUtil.findLibraryEntry(virtualFile, project)
if (orderEntry is JdkOrderEntry) {
val jdkName = orderEntry.jdkName
if (jdkName != null) {
for (rootType in listOf(OrderRootType.CLASSES, OrderRootType.SOURCES)) {
val inClassFiles = rootType == OrderRootType.CLASSES
val jdkRoots = orderEntry.getRootFiles(rootType)
for ((rootIndex, rootFile) in jdkRoots.withIndex()) {
val relativePath = VfsUtilCore.getRelativePath(virtualFile, rootFile)
if (relativePath != null) {
return PortableFilePath.RelativePath(PortableFilePath.JdkRoot(jdkName, rootIndex, inClassFiles), relativePath)
}
}
}
if (orderEntry !is JdkOrderEntry) return null
val jdkName = orderEntry.jdkName
if (jdkName == null) return null
for (rootType in listOf(OrderRootType.CLASSES, OrderRootType.SOURCES)) {
val inClassFiles = rootType == OrderRootType.CLASSES
val jdkRoots = orderEntry.getRootFiles(rootType)
for ((rootIndex, rootFile) in jdkRoots.withIndex()) {
val relativePath = VfsUtilCore.getRelativePath(virtualFile, rootFile)
if (relativePath == null) continue
return PortableFilePath.RelativePath(PortableFilePath.JdkRoot(jdkName, rootIndex, inClassFiles), relativePath)
}
}
return null
}
}
}