diff --git a/compiler/container/src/org/jetbrains/kotlin/container/Registry.kt b/compiler/container/src/org/jetbrains/kotlin/container/Registry.kt index e060cd3bff4..69e16ed1b16 100644 --- a/compiler/container/src/org/jetbrains/kotlin/container/Registry.kt +++ b/compiler/container/src/org/jetbrains/kotlin/container/Registry.kt @@ -30,17 +30,44 @@ internal class ComponentRegistry { return registrationMap } - private var registrationMap = MultiMap.createLinkedSet() + private val registrationMap = hashMapOf() fun addAll(descriptors: Collection) { - registrationMap.putAllValues(buildRegistrationMap(descriptors)) + val newRegistrationMap = buildRegistrationMap(descriptors) + for (entry in newRegistrationMap.entrySet()) { + val oldEntries = registrationMap[entry.key] + if (oldEntries != null || entry.value.size > 1) { + val list = mutableListOf() + if (oldEntries is Collection<*>) { + @Suppress("UNCHECKED_CAST") + list.addAll(oldEntries as Collection) + } + else if (oldEntries != null) { + list.add(oldEntries as ComponentDescriptor) + } + list.addAll(entry.value) + registrationMap[entry.key] = list.singleOrNull() ?: list + } + else { + registrationMap[entry.key] = entry.value.single() + } + } } fun tryGetEntry(request: Type): Collection { - return registrationMap.get(request) + val value = registrationMap[request] + @Suppress("UNCHECKED_CAST") + return when(value) { + is Collection<*> -> value as Collection + null -> emptyList() + else -> listOf(value as ComponentDescriptor) + } } fun addAll(other: ComponentRegistry) { - registrationMap.putAllValues(other.registrationMap) + if (!registrationMap.isEmpty()) { + throw IllegalStateException("Can only copy entries from another component registry into an empty component registry") + } + registrationMap += other.registrationMap } } \ No newline at end of file