Skip to content

Commit ee0874a

Browse files
committed
Drop JsVirtualFileFinder and its factory, refactor nearby
The only remaining usage was in KotlinRuntimeLibraryUtil.kt where we only needed to check whether there's at least one file in a given package indexed by KotlinJavaScriptMetaFileIndex. Move that logic to a public extension, drop everything else
1 parent 67699bf commit ee0874a

File tree

7 files changed

+26
-112
lines changed

7 files changed

+26
-112
lines changed

idea/idea-analysis/src/org/jetbrains/kotlin/idea/vfilefinder/JsVirtualFileFinder.kt

Lines changed: 0 additions & 32 deletions
This file was deleted.

idea/idea-analysis/src/org/jetbrains/kotlin/idea/vfilefinder/JsVirtualFileFinderFactory.kt

Lines changed: 0 additions & 31 deletions
This file was deleted.

idea/idea-analysis/src/org/jetbrains/kotlin/idea/vfilefinder/factories.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,3 @@ import org.jetbrains.kotlin.load.kotlin.JvmVirtualFileFinderFactory
2323
class JvmIDEVirtualFileFinderFactory : JvmVirtualFileFinderFactory {
2424
override fun create(scope: GlobalSearchScope): JvmVirtualFileFinder = JvmIDEVirtualFileFinder(scope)
2525
}
26-
27-
class JsIDEVirtualFileFinderFactory : JsVirtualFileFinderFactory {
28-
override fun create(scope: GlobalSearchScope): JsVirtualFileFinder = JsIDEVirtualFileFinder(scope)
29-
}

idea/idea-analysis/src/org/jetbrains/kotlin/idea/vfilefinder/fileFinders.kt

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -27,56 +27,34 @@ import org.jetbrains.kotlin.name.ClassId
2727
import org.jetbrains.kotlin.name.FqName
2828
import java.io.InputStream
2929

30-
private fun checkScopeForFinder(scope: GlobalSearchScope, logger: Logger) {
31-
if (scope != GlobalSearchScope.EMPTY_SCOPE && scope.project == null) {
32-
logger.warn("Scope with null project " + scope)
33-
}
34-
}
35-
36-
private fun findVirtualFileWithHeader(classId: ClassId, key: ID<FqName, Void>, scope: GlobalSearchScope, logger: Logger): VirtualFile? {
37-
val files = FileBasedIndex.getInstance().getContainingFiles<FqName, Void>(key, classId.asSingleFqName(), scope)
38-
if (files.isEmpty()) return null
39-
40-
if (files.size > 1) {
41-
logger.warn("There are " + files.size + " classes with same fqName: " + classId + " found.")
42-
}
43-
return files.iterator().next()
44-
}
45-
46-
// TODO: drop this implementation, replace with a much simpler service
47-
class JsIDEVirtualFileFinder(private val scope: GlobalSearchScope) : JsVirtualFileFinder {
48-
49-
init { checkScopeForFinder(scope, LOG) }
50-
51-
override fun findVirtualFileWithHeader(classId: ClassId): VirtualFile? =
52-
throw UnsupportedOperationException("This method should not be called. (classId = $classId)")
53-
54-
override fun hasPackage(fqName: FqName): Boolean = KotlinJavaScriptMetaFileIndex.hasPackage(fqName, scope)
55-
56-
companion object {
57-
private val LOG = Logger.getInstance(JsIDEVirtualFileFinder::class.java)
58-
}
59-
}
60-
6130
class JvmIDEVirtualFileFinder(private val scope: GlobalSearchScope) : VirtualFileKotlinClassFinder(), JvmVirtualFileFinder {
6231
override fun findMetadata(classId: ClassId): InputStream? {
63-
return findVirtualFileWithHeader(classId, KotlinMetadataFileIndex.KEY, scope, LOG)?.inputStream
32+
return findVirtualFileWithHeader(classId, KotlinMetadataFileIndex.KEY)?.inputStream
6433
}
6534

66-
override fun hasMetadataPackage(fqName: FqName): Boolean = KotlinMetadataFilePackageIndex.hasPackage(fqName, scope)
35+
override fun hasMetadataPackage(fqName: FqName): Boolean = KotlinMetadataFilePackageIndex.hasSomethingInPackage(fqName, scope)
6736

6837
// TODO: load built-ins metadata from scope
6938
override fun findBuiltInsData(packageFqName: FqName): InputStream? = null
7039

71-
init { checkScopeForFinder(scope, LOG) }
40+
init {
41+
if (scope != GlobalSearchScope.EMPTY_SCOPE && scope.project == null) {
42+
LOG.warn("Scope with null project $scope")
43+
}
44+
}
7245

7346
override fun findVirtualFileWithHeader(classId: ClassId): VirtualFile? =
74-
findVirtualFileWithHeader(classId, KotlinClassFileIndex.KEY, scope, LOG)
47+
findVirtualFileWithHeader(classId, KotlinClassFileIndex.KEY)
48+
49+
private fun findVirtualFileWithHeader(classId: ClassId, key: ID<FqName, Void>): VirtualFile? {
50+
val files = FileBasedIndex.getInstance().getContainingFiles<FqName, Void>(key, classId.asSingleFqName(), scope)
51+
if (files.size > 1) {
52+
LOG.warn("There are ${files.size} classes with same fqName: $classId found.")
53+
}
54+
return files.firstOrNull()
55+
}
7556

7657
companion object {
7758
private val LOG = Logger.getInstance(JvmIDEVirtualFileFinder::class.java)
7859
}
7960
}
80-
81-
private fun <T> KotlinFileIndexBase<T>.hasPackage(fqName: FqName, scope: GlobalSearchScope): Boolean =
82-
!FileBasedIndex.getInstance().processValues(name, fqName, null, { _, _ -> false }, scope)

idea/idea-analysis/src/org/jetbrains/kotlin/idea/vfilefinder/fileIndexes.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea.vfilefinder
1818

1919
import com.intellij.ide.highlighter.JavaClassFileType
2020
import com.intellij.openapi.diagnostic.Logger
21+
import com.intellij.psi.search.GlobalSearchScope
2122
import com.intellij.util.indexing.*
2223
import com.intellij.util.io.IOUtil
2324
import com.intellij.util.io.KeyDescriptor
@@ -76,6 +77,9 @@ abstract class KotlinFileIndexBase<T>(classOfIndex: Class<T>) : ScalarIndexExten
7677
}
7778
}
7879

80+
fun <T> KotlinFileIndexBase<T>.hasSomethingInPackage(fqName: FqName, scope: GlobalSearchScope): Boolean =
81+
!FileBasedIndex.getInstance().processValues(name, fqName, null, { _, _ -> false }, scope)
82+
7983
object KotlinClassFileIndex : KotlinFileIndexBase<KotlinClassFileIndex>(KotlinClassFileIndex::class.java) {
8084

8185
override fun getIndexer() = INDEXER

idea/src/META-INF/plugin.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,6 @@
238238
<projectService serviceInterface="org.jetbrains.kotlin.load.kotlin.JvmVirtualFileFinderFactory"
239239
serviceImplementation="org.jetbrains.kotlin.idea.vfilefinder.JvmIDEVirtualFileFinderFactory"/>
240240

241-
<projectService serviceInterface="org.jetbrains.kotlin.idea.vfilefinder.JsVirtualFileFinderFactory"
242-
serviceImplementation="org.jetbrains.kotlin.idea.vfilefinder.JsIDEVirtualFileFinderFactory"/>
243-
244241
<projectService serviceInterface="org.jetbrains.kotlin.load.kotlin.ModuleVisibilityManager"
245242
serviceImplementation="org.jetbrains.kotlin.idea.util.IdeModuleVisibilityManagerImpl"/>
246243

idea/src/org/jetbrains/kotlin/idea/versions/KotlinRuntimeLibraryUtil.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ import org.jetbrains.kotlin.idea.framework.*
5151
import org.jetbrains.kotlin.idea.util.application.runReadAction
5252
import org.jetbrains.kotlin.idea.util.projectStructure.allModules
5353
import org.jetbrains.kotlin.idea.util.runWithAlternativeResolveEnabled
54-
import org.jetbrains.kotlin.idea.vfilefinder.JsVirtualFileFinderFactory
54+
import org.jetbrains.kotlin.idea.vfilefinder.KotlinJavaScriptMetaFileIndex
55+
import org.jetbrains.kotlin.idea.vfilefinder.hasSomethingInPackage
5556
import org.jetbrains.kotlin.load.kotlin.JvmMetadataVersion
5657
import org.jetbrains.kotlin.name.FqName
5758
import org.jetbrains.kotlin.serialization.deserialization.BinaryVersion
5859
import org.jetbrains.kotlin.utils.JsMetadataVersion
5960
import org.jetbrains.kotlin.utils.PathUtil
60-
import org.jetbrains.kotlin.utils.addToStdlib.constant
6161
import java.io.File
6262
import java.io.IOException
6363

@@ -167,7 +167,7 @@ fun findAllUsedLibraries(project: Project): MultiMap<Library, Module> {
167167
return libraries
168168
}
169169

170-
private enum class LibraryJarDescriptor private constructor(val jarName: String, val shouldExist: Boolean) {
170+
private enum class LibraryJarDescriptor(val jarName: String, val shouldExist: Boolean) {
171171
RUNTIME_JAR(PathUtil.KOTLIN_JAVA_RUNTIME_JAR, true),
172172
REFLECT_JAR(PathUtil.KOTLIN_JAVA_REFLECT_JAR, false),
173173
SCRIPT_RUNTIME_JAR(PathUtil.KOTLIN_JAVA_SCRIPT_RUNTIME_JAR, true),
@@ -288,10 +288,12 @@ fun getKotlinJvmRuntimeMarkerClass(project: Project, scope: GlobalSearchScope):
288288
}
289289
}
290290

291+
private val KOTLIN_JS_FQ_NAME = FqName("kotlin.js")
292+
291293
fun hasKotlinJsKjsmFile(project: Project, scope: GlobalSearchScope): Boolean {
292294
return runReadAction {
293295
project.runWithAlternativeResolveEnabled {
294-
JsVirtualFileFinderFactory.SERVICE.getInstance(project).create(scope).hasPackage(constant { FqName("kotlin.js") })
296+
KotlinJavaScriptMetaFileIndex.hasSomethingInPackage(KOTLIN_JS_FQ_NAME, scope)
295297
}
296298
}
297299
}

0 commit comments

Comments
 (0)