Skip to content

Commit

Permalink
Fix findMapping with mixins failing when generics are involved
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed Jan 4, 2024
1 parent 4912c8b commit 445bb7a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,11 @@ internal class PsiMapper(
return null // otherwise, it belongs to the mixin and never gets remapped
}
findPsiClass(mapping.fullObfuscatedName)
?.findMethodBySignature(method, false)
?.let(::findMapping)
?.findMethodsByName(method.name, false)
?.asSequence()
?.filter { it.matchesDescriptor(method) }
?.mapNotNull(::findMapping)
?.firstOrNull()
?.let { return it }
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/main/kotlin/com/replaymod/gradle/remap/PsiUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.jetbrains.kotlin.com.intellij.openapi.util.text.StringUtil
import org.jetbrains.kotlin.com.intellij.psi.*
import org.jetbrains.kotlin.com.intellij.psi.util.ClassUtil
import org.jetbrains.kotlin.com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.com.intellij.psi.util.TypeConversionUtil

internal val PsiClass.dollarQualifiedName: String? get() {
val parent = PsiTreeUtil.getParentOfType<PsiClass>(this, PsiClass::class.java) ?: return qualifiedName
Expand Down Expand Up @@ -109,6 +110,23 @@ fun PsiJavaCodeReferenceElement.smartMultiResolve(): PsiElement? {
return lowestMethodSoFar
}

fun PsiMethod.matchesDescriptor(method: PsiMethod): Boolean {
if (TypeConversionUtil.erasure(returnType) != TypeConversionUtil.erasure(method.returnType)) {
return false
}
val parameters = parameterList.parameters
val otherParameters = method.parameterList.parameters
if (parameters.size != otherParameters.size) {
return false
}
for (i in parameters.indices) {
if (TypeConversionUtil.erasure(parameters[i].type) != TypeConversionUtil.erasure(otherParameters[i].type)) {
return false
}
}
return true
}

internal object PsiUtils {
fun getSignature(method: PsiMethod): MethodSignature = MethodSignature(method.name, getDescriptor(method))

Expand Down

0 comments on commit 445bb7a

Please sign in to comment.