Load definitions of symbols from .kotlin_metadata files
Extract AbstractDeserializedPackageFragmentProvider out of JvmBuiltInsPackageFragmentProvider and implement it a little bit differently in MetadataPackageFragmentProvider. The main difference is in how the package fragment scope is constructed: for built-ins, it's just a single scope that loads everything from one protobuf message. For metadata, package scope can consist of many files, some of which store information about classes and others are similar to package parts on JVM, so a ChainedMemberScope instance is created. Introduce a bunch of interfaces/methods to deliver the needed behavior to the 'deserialization' module which is not JVM-specific and does not depend on the compiler code: MetadataFinderFactory, PackagePartProvider#findMetadataPackageParts, KotlinMetadataFinder#findMetadata. Note that these declarations are currently only implemented in the compiler; no metadata package parts/fragments will be found in IDE or reflection
This commit is contained in:
+9
-6
@@ -18,14 +18,17 @@ package org.jetbrains.kotlin.idea.caches.resolve
|
||||
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.util.indexing.FileBasedIndex
|
||||
import org.jetbrains.kotlin.idea.vfilefinder.KotlinModuleMappingIndex
|
||||
import org.jetbrains.kotlin.descriptors.PackagePartProvider
|
||||
import org.jetbrains.kotlin.idea.vfilefinder.KotlinModuleMappingIndex
|
||||
import org.jetbrains.kotlin.load.kotlin.PackageParts
|
||||
|
||||
class IDEPackagePartProvider(val scope: GlobalSearchScope) : PackagePartProvider {
|
||||
override fun findPackageParts(packageFqName: String): List<String> =
|
||||
getPackageParts(packageFqName).flatMap(PackageParts::parts).distinct()
|
||||
|
||||
override fun findPackageParts(packageFqName: String): List<String> {
|
||||
val values: MutableList<PackageParts> = FileBasedIndex.getInstance().getValues(KotlinModuleMappingIndex.KEY, packageFqName, scope)
|
||||
return values.flatMap { it.parts }.distinct()
|
||||
}
|
||||
}
|
||||
override fun findMetadataPackageParts(packageFqName: String): List<String> =
|
||||
getPackageParts(packageFqName).flatMap(PackageParts::metadataParts).distinct()
|
||||
|
||||
private fun getPackageParts(packageFqName: String): MutableList<PackageParts> =
|
||||
FileBasedIndex.getInstance().getValues(KotlinModuleMappingIndex.KEY, packageFqName, scope)
|
||||
}
|
||||
|
||||
+3
@@ -116,6 +116,9 @@ class DirectoryBasedClassFinder(
|
||||
return null
|
||||
}
|
||||
|
||||
// TODO
|
||||
override fun findMetadata(classId: ClassId): InputStream? = null
|
||||
|
||||
// TODO: load built-ins from packageDirectory?
|
||||
override fun findBuiltInsData(packageFqName: FqName): InputStream? = null
|
||||
}
|
||||
|
||||
@@ -56,6 +56,9 @@ class JsIDEVirtualFileFinder(private val scope: GlobalSearchScope) : JsVirtualFi
|
||||
}
|
||||
|
||||
class JvmIDEVirtualFileFinder(private val scope: GlobalSearchScope) : VirtualFileKotlinClassFinder(), JvmVirtualFileFinder {
|
||||
// TODO
|
||||
override fun findMetadata(classId: ClassId): InputStream? = null
|
||||
|
||||
// TODO: load built-ins metadata from scope
|
||||
override fun findBuiltInsData(packageFqName: FqName): InputStream? = null
|
||||
|
||||
|
||||
Reference in New Issue
Block a user