Add InvalidModuleNotifier capability
Relates to #KT-48977
This commit is contained in:
@@ -16,4 +16,17 @@
|
||||
|
||||
package org.jetbrains.kotlin.descriptors
|
||||
|
||||
class InvalidModuleException(message: String) : IllegalStateException(message)
|
||||
class InvalidModuleException(message: String) : IllegalStateException(message)
|
||||
|
||||
interface InvalidModuleNotifier {
|
||||
fun notifyModuleInvalidated(moduleDescriptor: ModuleDescriptor)
|
||||
}
|
||||
|
||||
fun ModuleDescriptor.moduleInvalidated() {
|
||||
val capability = getCapability(INVALID_MODULE_NOTIFIER_CAPABILITY)
|
||||
capability?.notifyModuleInvalidated(this) ?: run {
|
||||
throw InvalidModuleException("Accessing invalid module descriptor $this")
|
||||
}
|
||||
}
|
||||
|
||||
val INVALID_MODULE_NOTIFIER_CAPABILITY = ModuleCapability<InvalidModuleNotifier>("InvalidModuleNotifier")
|
||||
@@ -56,7 +56,7 @@ class ModuleDescriptorImpl @JvmOverloads constructor(
|
||||
|
||||
override fun assertValid() {
|
||||
if (!isValid) {
|
||||
throw InvalidModuleException("Accessing invalid module descriptor $this")
|
||||
moduleInvalidated()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,6 +90,7 @@ class ModuleDescriptorImpl @JvmOverloads constructor(
|
||||
private val packageFragmentProviderForWholeModuleWithDependencies by lazy {
|
||||
val moduleDependencies = dependencies.sure { "Dependencies of module $id were not set before querying module content" }
|
||||
val dependenciesDescriptors = moduleDependencies.allDependencies
|
||||
assertValid()
|
||||
assert(this in dependenciesDescriptors) { "Module $id is not contained in its own dependencies, this is probably a misconfiguration" }
|
||||
dependenciesDescriptors.forEach { dependency ->
|
||||
assert(dependency.isInitialized) {
|
||||
|
||||
Reference in New Issue
Block a user