Skip to content

Commit

Permalink
Prevent replacement of $ with . in more places, fixes #2282
Browse files Browse the repository at this point in the history
  • Loading branch information
Earthcomputer committed Jul 28, 2024
1 parent 7d1cd3a commit 88a475a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/main/kotlin/platform/mixin/reference/DescReference.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package com.demonwav.mcdev.platform.mixin.reference

import com.demonwav.mcdev.platform.mixin.util.MixinConstants.Annotations.DESC
import com.demonwav.mcdev.platform.mixin.util.canonicalName
import com.demonwav.mcdev.platform.mixin.util.findClassNodeByQualifiedName
import com.demonwav.mcdev.util.MemberReference
import com.demonwav.mcdev.util.findModule
Expand Down Expand Up @@ -114,11 +115,11 @@ object DescReference : AbstractMethodReference() {
val argTypes = Type.getArgumentTypes(desc)
if (argTypes.isNotEmpty()) {
val argsText = if (argTypes.size == 1) {
"${argTypes[0].className.replace('$', '.')}.class"
"${argTypes[0].canonicalName}.class"
} else {
"{${
argTypes.joinToString(", ") { type ->
"${type.className.replace('$', '.')}.class"
"${type.canonicalName}.class"
}
}}"
}
Expand All @@ -134,7 +135,7 @@ object DescReference : AbstractMethodReference() {
descAnnotation.setDeclaredAttributeValue(
"ret",
elementFactory.createAnnotationMemberValueFromText(
"${returnType.className.replace('$', '.')}.class",
"${returnType.canonicalName}.class",
descAnnotation,
),
)
Expand Down
11 changes: 6 additions & 5 deletions src/main/kotlin/platform/mixin/util/AsmUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,17 @@ fun Type.toPsiType(elementFactory: PsiElementFactory, context: PsiElement? = nul
if (this == ExpressionASMUtils.INTLIKE_TYPE) {
return PsiTypes.intType()
}
val javaClassName = className.replace("(\\$)(\\D)".toRegex()) { "." + it.groupValues[2] }
return elementFactory.createTypeFromText(javaClassName, context)
return elementFactory.createTypeFromText(canonicalName, context)
}

val Type.canonicalName get() = computeCanonicalName(this)

private val DOLLAR_TO_DOT_REGEX = "\\$(?!\\d)".toRegex()

private fun computeCanonicalName(type: Type): String {
return when (type.sort) {
Type.ARRAY -> computeCanonicalName(type.elementType) + "[]".repeat(type.dimensions)
Type.OBJECT -> type.className.replace('$', '.')
Type.OBJECT -> type.className.replace(DOLLAR_TO_DOT_REGEX, ".")
else -> type.className
}
}
Expand Down Expand Up @@ -817,7 +818,7 @@ fun MethodNode.findOrConstructSourceMethod(
}
append(name)
} else {
append(returnType.className.replace('$', '.'))
append(returnType.canonicalName)
append(' ')
append(this@findOrConstructSourceMethod.name.toJavaIdentifier())
}
Expand All @@ -827,7 +828,7 @@ fun MethodNode.findOrConstructSourceMethod(
if (index != 0) {
append(", ")
}
var typeName = param.className.replace('$', '.')
var typeName = param.canonicalName
if (index == params.size - 1 && hasAccess(Opcodes.ACC_VARARGS) && typeName.endsWith("[]")) {
typeName = typeName.replaceRange(typeName.length - 2, typeName.length, "...")
}
Expand Down

0 comments on commit 88a475a

Please sign in to comment.