Load built-ins from module dependencies in JVM compiler
Introduce a new method KotlinClassFinder#findBuiltInsData, which is only implemented correctly in the JvmCliVirtualFileFinder because it's only used in the compiler code at the moment. Introduce JvmBuiltInsPackageFragmentProvider, the purpose of which is to look for .kotlin_builtins files in the classpath and provide definitions of built-ins from those files. Also exclude script.runtime from compilation because, as other excluded modules, it has no dependency on the stdlib and is no longer compilable from the IDE now, because it cannot resolve built-ins from anywhere
This commit is contained in:
@@ -18,22 +18,36 @@ package org.jetbrains.kotlin.cli.jvm.compiler
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.kotlin.builtins.BuiltInSerializerProtocol
|
||||
import org.jetbrains.kotlin.cli.jvm.index.JavaRoot
|
||||
import org.jetbrains.kotlin.cli.jvm.index.JvmDependenciesIndex
|
||||
import org.jetbrains.kotlin.load.kotlin.VirtualFileKotlinClassFinder
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.check
|
||||
import java.io.InputStream
|
||||
|
||||
class JvmCliVirtualFileFinder(
|
||||
private val index: JvmDependenciesIndex,
|
||||
private val scope: GlobalSearchScope
|
||||
) : VirtualFileKotlinClassFinder() {
|
||||
override fun findVirtualFileWithHeader(classId: ClassId): VirtualFile? {
|
||||
val classFileName = classId.relativeClassName.asString().replace('.', '$')
|
||||
val classFileName = classId.relativeClassName.asString().replace('.', '$') + ".class"
|
||||
return index.findClass(classId, acceptedRootTypes = JavaRoot.OnlyBinary) { dir, rootType ->
|
||||
dir.findChild("$classFileName.class")?.let {
|
||||
if (it.isValid) it else null
|
||||
}
|
||||
dir.findChild(classFileName)?.check(VirtualFile::isValid)
|
||||
}?.check { it in scope }
|
||||
}
|
||||
|
||||
override fun findBuiltInsData(packageFqName: FqName): InputStream? {
|
||||
val fileName = BuiltInSerializerProtocol.getBuiltInsFileName(packageFqName)
|
||||
|
||||
// "<builtins-metadata>" is just a made-up name
|
||||
// JvmDependenciesIndex requires the ClassId of the class which we're searching for, to cache the last request+result
|
||||
val classId = ClassId(packageFqName, Name.special("<builtins-metadata>"))
|
||||
|
||||
return index.findClass(classId, acceptedRootTypes = JavaRoot.OnlyBinary) { dir, rootType ->
|
||||
dir.findChild(fileName)?.check(VirtualFile::isValid)
|
||||
}?.check { it in scope }?.inputStream
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user