diff --git a/generator/accessor/src/main/kotlin/me/kcra/takenaka/generator/accessor/context/impl/AbstractGenerationContext.kt b/generator/accessor/src/main/kotlin/me/kcra/takenaka/generator/accessor/context/impl/AbstractGenerationContext.kt index 66473a05902..04b7f8c1582 100644 --- a/generator/accessor/src/main/kotlin/me/kcra/takenaka/generator/accessor/context/impl/AbstractGenerationContext.kt +++ b/generator/accessor/src/main/kotlin/me/kcra/takenaka/generator/accessor/context/impl/AbstractGenerationContext.kt @@ -443,9 +443,10 @@ abstract class AbstractGenerationContext( * Groups the generator's mappings by version. * * @param node the ancestry node + * @param exact whether descriptors should be matched exactly or without return types * @return the grouped method mappings */ - protected open fun groupMethodNames(node: MethodAncestryNode): Map> = buildMap> { + protected open fun groupMethodNames(node: MethodAncestryNode, exact: Boolean = false): Map> = buildMap> { node.forEach { (version, method) -> val nmsVersion = method.tree.craftBukkitNmsVersion @@ -453,7 +454,7 @@ abstract class AbstractGenerationContext( method.getDesc(ns)?.let { desc -> val name = method.getName(ns) ?: method.srcName - getOrPut(MethodKey(ns, name, desc.replaceCraftBukkitNMSVersion(nmsVersion)), ::mutableListOf) += version + getOrPut(MethodKey(ns, name, desc.replaceCraftBukkitNMSVersion(nmsVersion), exact), ::mutableListOf) += version } } } diff --git a/generator/accessor/src/main/kotlin/me/kcra/takenaka/generator/accessor/context/impl/TracingGenerationContext.kt b/generator/accessor/src/main/kotlin/me/kcra/takenaka/generator/accessor/context/impl/TracingGenerationContext.kt index f94cd920cc4..fd1cd0844ef 100644 --- a/generator/accessor/src/main/kotlin/me/kcra/takenaka/generator/accessor/context/impl/TracingGenerationContext.kt +++ b/generator/accessor/src/main/kotlin/me/kcra/takenaka/generator/accessor/context/impl/TracingGenerationContext.kt @@ -130,7 +130,7 @@ open class TracingGenerationContext( output.println(header) output.printNodeHistory(mergedAccessor.mergedNode) - groupMethodNames(mergedAccessor.mergedNode).forEach { (methodKey, versions) -> + groupMethodNames(mergedAccessor.mergedNode, exact = true).forEach { (methodKey, versions) -> val (ns, name, desc) = methodKey output.println("namespace: $ns, mapping: $name, descriptor: $desc, versions: [${versions.joinToString(transform = Version::id)}]") diff --git a/generator/accessor/src/main/kotlin/me/kcra/takenaka/generator/accessor/context/impl/elementKeys.kt b/generator/accessor/src/main/kotlin/me/kcra/takenaka/generator/accessor/context/impl/elementKeys.kt index 940d883b7c9..3d1ce1b0906 100644 --- a/generator/accessor/src/main/kotlin/me/kcra/takenaka/generator/accessor/context/impl/elementKeys.kt +++ b/generator/accessor/src/main/kotlin/me/kcra/takenaka/generator/accessor/context/impl/elementKeys.kt @@ -54,22 +54,17 @@ data class ConstructorKey(override val namespace: String, val descriptor: String /** * A method mapping key. * - * *The method return type is not used when checking equality, mimicking reflective lookups.* - * * @property namespace the mapping namespace * @property name the mapped method name * @property descriptor the mapped method descriptor + * @property exact whether descriptors should be matched exactly or without return types */ -data class MethodKey(override val namespace: String, val name: String, val descriptor: String) : NamespacedKey { +data class MethodKey(override val namespace: String, val name: String, val descriptor: String, val exact: Boolean) : NamespacedKey { /** - * [descriptor], but with the return type removed. + * The descriptor used for matching. */ - private val partialDescriptor: String - - init { - val parenthesisIndex = descriptor.lastIndexOf(')') - this.partialDescriptor = if (parenthesisIndex != -1) descriptor.substring(0, parenthesisIndex + 1) else descriptor - } + private val matchableDescriptor: String = descriptor.takeIf { exact } + ?: descriptor.substringBeforeLast(')') override fun equals(other: Any?): Boolean { if (this === other) return true @@ -79,7 +74,7 @@ data class MethodKey(override val namespace: String, val name: String, val descr if (namespace != other.namespace) return false if (name != other.name) return false - if (partialDescriptor != other.partialDescriptor) return false + if (matchableDescriptor != other.matchableDescriptor) return false return true } @@ -87,7 +82,7 @@ data class MethodKey(override val namespace: String, val name: String, val descr override fun hashCode(): Int { var result = namespace.hashCode() result = 31 * result + name.hashCode() - result = 31 * result + partialDescriptor.hashCode() + result = 31 * result + matchableDescriptor.hashCode() return result } }