diff options
author | Pavel Kirpichenkov <pavel.kirpichenkov@jetbrains.com> | 2020-10-27 16:43:36 +0300 |
---|---|---|
committer | kotlin-ide-monorepo-bot <kotlin-ide-monorepo-bot-no-reply@jetbrains.com> | 2020-10-27 14:05:19 +0000 |
commit | 3823a6cc96d37c635d664ea8ed2b5143fb59b3af (patch) | |
tree | cbadcd07e3de357ba898efaa5ab0b7cd26761e68 /analysis | |
parent | f9ef0f886f7f9e6c62ab050a5e07584b33557f3a (diff) | |
download | intellij-kotlin-3823a6cc96d37c635d664ea8ed2b5143fb59b3af.tar.gz |
ModuleInfos: assert correct Library type
equals/hashCode cannot be delegated to Library directly
after updates for the new project model. Implementation on
the Kotlin side requires access to properties provided by
the LibraryEx interface. Currently it is supported by all
Library interface implementors. Assertions should help
against missing future inconsistencies for new Library
implementations.
KT-42607
GitOrigin-RevId: ecee63e964ecd12d619e7625d7c41610ad65e2ad
Diffstat (limited to 'analysis')
-rw-r--r-- | analysis/src/org/jetbrains/kotlin/idea/caches/project/IdeaModuleInfos.kt | 14 | ||||
-rw-r--r-- | analysis/src/org/jetbrains/kotlin/idea/caches/project/moduleInfosFromIdeaModel.kt | 19 |
2 files changed, 14 insertions, 19 deletions
diff --git a/analysis/src/org/jetbrains/kotlin/idea/caches/project/IdeaModuleInfos.kt b/analysis/src/org/jetbrains/kotlin/idea/caches/project/IdeaModuleInfos.kt index 9503c0d9cca3..9b31b906d8fb 100644 --- a/analysis/src/org/jetbrains/kotlin/idea/caches/project/IdeaModuleInfos.kt +++ b/analysis/src/org/jetbrains/kotlin/idea/caches/project/IdeaModuleInfos.kt @@ -338,6 +338,10 @@ private class ModuleTestSourceScope(module: Module) : ModuleSourceScope(module) } abstract class LibraryInfo(override val project: Project, val library: Library) : IdeaModuleInfo, LibraryModuleInfo, BinaryModuleInfo { + init { + require(library is LibraryEx) { "Library '${name}' does not implement LibraryEx which is not expected" } + } + override val moduleOrigin: ModuleOrigin get() = ModuleOrigin.LIBRARY @@ -377,16 +381,10 @@ abstract class LibraryInfo(override val project: Project, val library: Library) if (this === other) return true if (other !is LibraryInfo) return false - if (library !is LibraryEx || other.library !is LibraryEx) - return library == other.library - - return library.equalsIgnoreNames(other.library) + return library.asLibraryEx().equalsIgnoreNames(other.library.asLibraryEx()) } - override fun hashCode(): Int = when(library) { - is LibraryEx -> library.rootBasedHashCode() - else -> library.hashCode() - } + override fun hashCode(): Int = library.asLibraryEx().rootBasedHashCode() } data class LibrarySourceInfo(override val project: Project, val library: Library, override val binariesModuleInfo: BinaryModuleInfo) : diff --git a/analysis/src/org/jetbrains/kotlin/idea/caches/project/moduleInfosFromIdeaModel.kt b/analysis/src/org/jetbrains/kotlin/idea/caches/project/moduleInfosFromIdeaModel.kt index fa0f2f666635..a26494d60479 100644 --- a/analysis/src/org/jetbrains/kotlin/idea/caches/project/moduleInfosFromIdeaModel.kt +++ b/analysis/src/org/jetbrains/kotlin/idea/caches/project/moduleInfosFromIdeaModel.kt @@ -63,26 +63,23 @@ class IdeaModelInfosCache( } // Workaround for duplicated libraries, see KT-42607 -private class LibraryWrapper(val library: Library) { +private class LibraryWrapper(val library: LibraryEx) { override fun equals(other: Any?): Boolean { if (this === other) return true if (other !is LibraryWrapper) return false - if (library !is LibraryEx || other.library !is LibraryEx) - return library == other.library - return library.equalsIgnoreNames(other.library) } - override fun hashCode(): Int { - return when(library) { - is LibraryEx -> library.rootBasedHashCode() - else -> library.hashCode() - } - } + override fun hashCode(): Int = library.rootBasedHashCode() +} + +internal fun Library.asLibraryEx(): LibraryEx { + require(this is LibraryEx) { "Library '${name}' does not implement LibraryEx which is not expected" } + return this } -private fun Library.wrap() = LibraryWrapper(this) +private fun Library.wrap() = LibraryWrapper(this.asLibraryEx()) internal val LibraryEx.allRootUrls: Set<String> get() = mutableSetOf<String>().apply { |