From 2bf31ae3c302278dc9e8c5fad75f2fc7700552d3 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 10 Jun 2020 21:55:52 +0200 Subject: [PATCH] IR: minor reformat of IdSignature --- .../jetbrains/kotlin/ir/util/IdSignature.kt | 43 +++++++++---------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IdSignature.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IdSignature.kt index ab675d1c77f..4f0d5ceff7a 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IdSignature.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IdSignature.kt @@ -20,10 +20,9 @@ sealed class IdSignature { fun decode(flags: Long): Boolean = (flags and (1L shl ordinal) != 0L) } - abstract val isPublic: Boolean - open fun isPackageSignature() = false + open fun isPackageSignature(): Boolean = false abstract fun topLevelSignature(): IdSignature abstract fun nearestPublicSig(): IdSignature @@ -42,9 +41,8 @@ sealed class IdSignature { val isLocal: Boolean get() = !isPublic - override fun toString(): String { - return "${if (isPublic) "public" else "private"} ${render()}" - } + override fun toString(): String = + "${if (isPublic) "public" else "private"} ${render()}" class PublicSignature(val packageFqName: String, val declarationFqName: String, val id: Long?, val mask: Long) : IdSignature() { override val isPublic: Boolean get() = true @@ -57,12 +55,11 @@ sealed class IdSignature { val nameSegments: List get() = declarationFqName.split('.') - private fun adaptMask(old: Long): Long { - return old xor Flags.values().fold(0L) { a, f -> + private fun adaptMask(old: Long): Long = + old xor Flags.values().fold(0L) { a, f -> if (!f.recursive) a or (old and (1L shl f.ordinal)) else a } - } override fun topLevelSignature(): IdSignature { if (declarationFqName.isEmpty()) { @@ -98,24 +95,23 @@ sealed class IdSignature { class AccessorSignature(val propertySignature: IdSignature, val accessorSignature: PublicSignature) : IdSignature() { override val isPublic: Boolean get() = true - override fun topLevelSignature() = propertySignature.topLevelSignature() + override fun topLevelSignature(): IdSignature = propertySignature.topLevelSignature() - override fun nearestPublicSig() = this + override fun nearestPublicSig(): IdSignature = this - override fun packageFqName() = propertySignature.packageFqName() + override fun packageFqName(): FqName = propertySignature.packageFqName() override fun render(): String = accessorSignature.render() - override fun equals(other: Any?): Boolean { - if (other is AccessorSignature) return accessorSignature == other.accessorSignature - return accessorSignature == other - } - override fun flags(): Long = accessorSignature.mask - override fun hashCode(): Int = accessorSignature.hashCode() - override fun asPublic(): PublicSignature? = accessorSignature + + override fun equals(other: Any?): Boolean = + if (other is AccessorSignature) accessorSignature == other.accessorSignature + else accessorSignature == other + + override fun hashCode(): Int = accessorSignature.hashCode() } class FileLocalSignature(val container: IdSignature, val id: Long) : IdSignature() { @@ -138,8 +134,10 @@ sealed class IdSignature { override fun render(): String = "${container.render()}:$id" + override fun equals(other: Any?): Boolean = + other is FileLocalSignature && id == other.id + override fun hashCode(): Int = id.toInt() - override fun equals(other: Any?): Boolean = other is FileLocalSignature && id == other.id } // Used to reference local variable and value parameters in function @@ -156,9 +154,8 @@ sealed class IdSignature { override fun render(): String = "#$id" - override fun equals(other: Any?): Boolean { - return other is ScopeLocalDeclaration && id == other.id - } + override fun equals(other: Any?): Boolean = + other is ScopeLocalDeclaration && id == other.id override fun hashCode(): Int = id } @@ -167,4 +164,4 @@ sealed class IdSignature { interface IdSignatureComposer { fun composeSignature(descriptor: DeclarationDescriptor): IdSignature? fun composeEnumEntrySignature(descriptor: ClassDescriptor): IdSignature? -} \ No newline at end of file +}