Add InvalidModuleNotifier capability

Relates to #KT-48977
This commit is contained in:
Vladimir Dolzhenko
2021-09-30 16:28:56 +02:00
parent 48a26204a7
commit b2afb602c5
2 changed files with 16 additions and 2 deletions
@@ -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) {