Skip to content

Commit

Permalink
Walk all parent methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed Jan 4, 2024
1 parent aaafa31 commit ade35bf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ internal class PsiMapper(
?.findMethodMapping(getSignature(method))
?.let { return it }

for (superMethod in method.findSuperMethods()) {
for (superMethod in method.findAllSuperMethods()) {
superMethod.containingClass
?.dollarQualifiedName
?.let(map::findClassMapping)
Expand Down Expand Up @@ -711,9 +711,6 @@ internal class PsiMapper(
}

override fun visitMethod(method: PsiMethod) {
if (method.name == "craft") {
Unit
}
if (valid(method)) {
map(method, method)
}
Expand Down
23 changes: 23 additions & 0 deletions src/main/kotlin/com/replaymod/gradle/remap/PsiUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,29 @@ internal inline fun <T> Array<T>.moreThan(n: Int, predicate: (T) -> Boolean): Bo
return false
}

fun PsiMethod.findAllSuperMethods() = findAllSuperMethods(this, mutableSetOf(this), null)

private fun findAllSuperMethods(
method: PsiMethod,
set: MutableSet<PsiMethod>,
guard: MutableSet<PsiMethod>?
): Iterator<PsiMethod> = iterator {
if (guard != null && !guard.add(method)) return@iterator
val supers = method.findSuperMethods()

if (set.add(method)) {
yield(method)
}

var useGuard = guard
for (superMethod in supers) {
if (useGuard == null) {
useGuard = mutableSetOf(method)
}
yieldAll(findAllSuperMethods(superMethod, set, useGuard))
}
}

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

Expand Down

0 comments on commit ade35bf

Please sign in to comment.