Support injecting custom module into KotlinBuiltIns

Provide a command-line option to load built-ins from the module and its
dependencies instead of looking for them in kotlin-compiler.jar; built-ins must
be found this way, or an error will be reported (or, most likely at this
moment, an exception will be thrown).

Note that this does not affect whether built-ins (loaded from one place or the
other) are added to the _dependencies_ of the module, this is controlled by
another option. The option added in this commit only makes the KotlinBuiltIns
instance which is used via ModuleDescriptor throughout the compiler front-end
(and also injected in a bunch of places) a sort of "helper" which always goes
to that same module to find descriptors for built-in classes
This commit is contained in:
Alexander Udalov
2016-11-07 19:01:42 +03:00
parent 7898e2447d
commit 8c65379711
12 changed files with 121 additions and 32 deletions
@@ -31,7 +31,7 @@ class JvmBuiltInClassDescriptorFactory(
) : ClassDescriptorFactory {
private val cloneable by storageManager.createLazyValue {
ClassDescriptorImpl(
moduleDescriptor.getPackage(KOTLIN_FQ_NAME).fragments.filterIsInstance<BuiltInsPackageFragment>().single(),
moduleDescriptor.getPackage(KOTLIN_FQ_NAME).fragments.filterIsInstance<BuiltInsPackageFragment>().first(),
CLONEABLE_NAME, Modality.ABSTRACT, ClassKind.INTERFACE, listOf(moduleDescriptor.builtIns.anyType),
SourceElement.NO_SOURCE
).apply {
@@ -26,7 +26,10 @@ import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.storage.getValue
import org.jetbrains.kotlin.utils.sure
class JvmBuiltIns(storageManager: StorageManager) : KotlinBuiltIns(storageManager) {
class JvmBuiltIns @JvmOverloads constructor(
storageManager: StorageManager,
loadBuiltInsFromCurrentClassLoader: Boolean = true
) : KotlinBuiltIns(storageManager) {
// Module containing JDK classes or having them among dependencies
private var ownerModuleDescriptor: ModuleDescriptor? = null
private var isAdditionalBuiltInsFeatureSupported: Boolean = true
@@ -46,7 +49,9 @@ class JvmBuiltIns(storageManager: StorageManager) : KotlinBuiltIns(storageManage
}
init {
createBuiltInsModule()
if (loadBuiltInsFromCurrentClassLoader) {
createBuiltInsModule()
}
}
override fun getPlatformDependentDeclarationFilter(): PlatformDependentDeclarationFilter = settings