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
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.vfilefinder
|
||||
|
||||
import com.intellij.openapi.components.ServiceManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.kotlin.load.kotlin.VirtualFileFinder
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
interface JsVirtualFileFinder : VirtualFileFinder {
|
||||
fun hasPackage(fqName: FqName): Boolean
|
||||
|
||||
object SERVICE {
|
||||
@JvmStatic fun getInstance(project: Project): JsVirtualFileFinder =
|
||||
ServiceManager.getService(project, JsVirtualFileFinderFactory::class.java).create(GlobalSearchScope.allScope(project))
|
||||
}
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.vfilefinder
|
||||
|
||||
import com.intellij.openapi.components.ServiceManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.kotlin.load.kotlin.VirtualFileFinderFactory
|
||||
|
||||
interface JsVirtualFileFinderFactory : VirtualFileFinderFactory {
|
||||
override fun create(scope: GlobalSearchScope): JsVirtualFileFinder
|
||||
|
||||
object SERVICE {
|
||||
@JvmStatic fun getInstance(project: Project): JsVirtualFileFinderFactory =
|
||||
ServiceManager.getService(project, JsVirtualFileFinderFactory::class.java)
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,3 @@ import org.jetbrains.kotlin.load.kotlin.JvmVirtualFileFinderFactory
|
||||
class JvmIDEVirtualFileFinderFactory : JvmVirtualFileFinderFactory {
|
||||
override fun create(scope: GlobalSearchScope): JvmVirtualFileFinder = JvmIDEVirtualFileFinder(scope)
|
||||
}
|
||||
|
||||
class JsIDEVirtualFileFinderFactory : JsVirtualFileFinderFactory {
|
||||
override fun create(scope: GlobalSearchScope): JsVirtualFileFinder = JsIDEVirtualFileFinder(scope)
|
||||
}
|
||||
|
||||
@@ -27,56 +27,34 @@ import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import java.io.InputStream
|
||||
|
||||
private fun checkScopeForFinder(scope: GlobalSearchScope, logger: Logger) {
|
||||
if (scope != GlobalSearchScope.EMPTY_SCOPE && scope.project == null) {
|
||||
logger.warn("Scope with null project " + scope)
|
||||
}
|
||||
}
|
||||
|
||||
private fun findVirtualFileWithHeader(classId: ClassId, key: ID<FqName, Void>, scope: GlobalSearchScope, logger: Logger): VirtualFile? {
|
||||
val files = FileBasedIndex.getInstance().getContainingFiles<FqName, Void>(key, classId.asSingleFqName(), scope)
|
||||
if (files.isEmpty()) return null
|
||||
|
||||
if (files.size > 1) {
|
||||
logger.warn("There are " + files.size + " classes with same fqName: " + classId + " found.")
|
||||
}
|
||||
return files.iterator().next()
|
||||
}
|
||||
|
||||
// TODO: drop this implementation, replace with a much simpler service
|
||||
class JsIDEVirtualFileFinder(private val scope: GlobalSearchScope) : JsVirtualFileFinder {
|
||||
|
||||
init { checkScopeForFinder(scope, LOG) }
|
||||
|
||||
override fun findVirtualFileWithHeader(classId: ClassId): VirtualFile? =
|
||||
throw UnsupportedOperationException("This method should not be called. (classId = $classId)")
|
||||
|
||||
override fun hasPackage(fqName: FqName): Boolean = KotlinJavaScriptMetaFileIndex.hasPackage(fqName, scope)
|
||||
|
||||
companion object {
|
||||
private val LOG = Logger.getInstance(JsIDEVirtualFileFinder::class.java)
|
||||
}
|
||||
}
|
||||
|
||||
class JvmIDEVirtualFileFinder(private val scope: GlobalSearchScope) : VirtualFileKotlinClassFinder(), JvmVirtualFileFinder {
|
||||
override fun findMetadata(classId: ClassId): InputStream? {
|
||||
return findVirtualFileWithHeader(classId, KotlinMetadataFileIndex.KEY, scope, LOG)?.inputStream
|
||||
return findVirtualFileWithHeader(classId, KotlinMetadataFileIndex.KEY)?.inputStream
|
||||
}
|
||||
|
||||
override fun hasMetadataPackage(fqName: FqName): Boolean = KotlinMetadataFilePackageIndex.hasPackage(fqName, scope)
|
||||
override fun hasMetadataPackage(fqName: FqName): Boolean = KotlinMetadataFilePackageIndex.hasSomethingInPackage(fqName, scope)
|
||||
|
||||
// TODO: load built-ins metadata from scope
|
||||
override fun findBuiltInsData(packageFqName: FqName): InputStream? = null
|
||||
|
||||
init { checkScopeForFinder(scope, LOG) }
|
||||
init {
|
||||
if (scope != GlobalSearchScope.EMPTY_SCOPE && scope.project == null) {
|
||||
LOG.warn("Scope with null project $scope")
|
||||
}
|
||||
}
|
||||
|
||||
override fun findVirtualFileWithHeader(classId: ClassId): VirtualFile? =
|
||||
findVirtualFileWithHeader(classId, KotlinClassFileIndex.KEY, scope, LOG)
|
||||
findVirtualFileWithHeader(classId, KotlinClassFileIndex.KEY)
|
||||
|
||||
private fun findVirtualFileWithHeader(classId: ClassId, key: ID<FqName, Void>): VirtualFile? {
|
||||
val files = FileBasedIndex.getInstance().getContainingFiles<FqName, Void>(key, classId.asSingleFqName(), scope)
|
||||
if (files.size > 1) {
|
||||
LOG.warn("There are ${files.size} classes with same fqName: $classId found.")
|
||||
}
|
||||
return files.firstOrNull()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val LOG = Logger.getInstance(JvmIDEVirtualFileFinder::class.java)
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T> KotlinFileIndexBase<T>.hasPackage(fqName: FqName, scope: GlobalSearchScope): Boolean =
|
||||
!FileBasedIndex.getInstance().processValues(name, fqName, null, { _, _ -> false }, scope)
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea.vfilefinder
|
||||
|
||||
import com.intellij.ide.highlighter.JavaClassFileType
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.util.indexing.*
|
||||
import com.intellij.util.io.IOUtil
|
||||
import com.intellij.util.io.KeyDescriptor
|
||||
@@ -76,6 +77,9 @@ abstract class KotlinFileIndexBase<T>(classOfIndex: Class<T>) : ScalarIndexExten
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> KotlinFileIndexBase<T>.hasSomethingInPackage(fqName: FqName, scope: GlobalSearchScope): Boolean =
|
||||
!FileBasedIndex.getInstance().processValues(name, fqName, null, { _, _ -> false }, scope)
|
||||
|
||||
object KotlinClassFileIndex : KotlinFileIndexBase<KotlinClassFileIndex>(KotlinClassFileIndex::class.java) {
|
||||
|
||||
override fun getIndexer() = INDEXER
|
||||
|
||||
@@ -238,9 +238,6 @@
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.load.kotlin.JvmVirtualFileFinderFactory"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.vfilefinder.JvmIDEVirtualFileFinderFactory"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.idea.vfilefinder.JsVirtualFileFinderFactory"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.vfilefinder.JsIDEVirtualFileFinderFactory"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.kotlin.load.kotlin.ModuleVisibilityManager"
|
||||
serviceImplementation="org.jetbrains.kotlin.idea.util.IdeModuleVisibilityManagerImpl"/>
|
||||
|
||||
|
||||
@@ -51,13 +51,13 @@ import org.jetbrains.kotlin.idea.framework.*
|
||||
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
||||
import org.jetbrains.kotlin.idea.util.projectStructure.allModules
|
||||
import org.jetbrains.kotlin.idea.util.runWithAlternativeResolveEnabled
|
||||
import org.jetbrains.kotlin.idea.vfilefinder.JsVirtualFileFinderFactory
|
||||
import org.jetbrains.kotlin.idea.vfilefinder.KotlinJavaScriptMetaFileIndex
|
||||
import org.jetbrains.kotlin.idea.vfilefinder.hasSomethingInPackage
|
||||
import org.jetbrains.kotlin.load.kotlin.JvmMetadataVersion
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.serialization.deserialization.BinaryVersion
|
||||
import org.jetbrains.kotlin.utils.JsMetadataVersion
|
||||
import org.jetbrains.kotlin.utils.PathUtil
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.constant
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
|
||||
@@ -167,7 +167,7 @@ fun findAllUsedLibraries(project: Project): MultiMap<Library, Module> {
|
||||
return libraries
|
||||
}
|
||||
|
||||
private enum class LibraryJarDescriptor private constructor(val jarName: String, val shouldExist: Boolean) {
|
||||
private enum class LibraryJarDescriptor(val jarName: String, val shouldExist: Boolean) {
|
||||
RUNTIME_JAR(PathUtil.KOTLIN_JAVA_RUNTIME_JAR, true),
|
||||
REFLECT_JAR(PathUtil.KOTLIN_JAVA_REFLECT_JAR, false),
|
||||
SCRIPT_RUNTIME_JAR(PathUtil.KOTLIN_JAVA_SCRIPT_RUNTIME_JAR, true),
|
||||
@@ -288,10 +288,12 @@ fun getKotlinJvmRuntimeMarkerClass(project: Project, scope: GlobalSearchScope):
|
||||
}
|
||||
}
|
||||
|
||||
private val KOTLIN_JS_FQ_NAME = FqName("kotlin.js")
|
||||
|
||||
fun hasKotlinJsKjsmFile(project: Project, scope: GlobalSearchScope): Boolean {
|
||||
return runReadAction {
|
||||
project.runWithAlternativeResolveEnabled {
|
||||
JsVirtualFileFinderFactory.SERVICE.getInstance(project).create(scope).hasPackage(constant { FqName("kotlin.js") })
|
||||
KotlinJavaScriptMetaFileIndex.hasSomethingInPackage(KOTLIN_JS_FQ_NAME, scope)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user