aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin
diff options
context:
space:
mode:
authorJonas Herzig <jonas@spark-squared.com>2021-11-11 16:52:27 +0100
committerJonas Herzig <jonas@spark-squared.com>2021-11-11 21:38:47 +0100
commit982982c63027e416bd78ca40708c7238e7eed26b (patch)
tree509517275b8664157f0cfc58e20675527fcc9ce8 /src/main/kotlin
parentb4462eb6030f8e5a072ad4b6508d7a93d574522f (diff)
downloadRemap-982982c63027e416bd78ca40708c7238e7eed26b.tar.gz
Remap-982982c63027e416bd78ca40708c7238e7eed26b.tar.bz2
Remap-982982c63027e416bd78ca40708c7238e7eed26b.zip
Fix remapping of qualified inner class reference in Kotlin code
When we used to remap `a.pkg.A.Inner` we would apply both mappings (the one for the inner class and the one for the outer class) at the same time, resulting in `b.pkg.B.Inner.Inner`. The direct cause being that we only checked conflicts for the range of the respective expression (which is just `A` and `Inner` for Kotlin, and therefore not conflicting) instead of the parent as we should have. With that fixed, it now also becomes apparent that we need to apply mappings for dot qualified expressions back to front (otherwise the outer class takes priority), so that is the second thing this commit change.
Diffstat (limited to 'src/main/kotlin')
-rw-r--r--src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt b/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt
index 07d7d1d..f7b50ba 100644
--- a/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt
+++ b/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt
@@ -219,7 +219,9 @@ internal class PsiMapper(
}
val parent: PsiElement? = expr.parent
if ((parent is KtUserType || parent is KtQualifiedExpression) && parent.text == name) {
- replace(parent, mapped)
+ if (valid(parent)) {
+ replace(parent, mapped)
+ }
return
}
// FIXME this incorrectly filters things like "Packet<?>" and doesn't filter same-name type aliases
@@ -549,6 +551,24 @@ internal class PsiMapper(
return super.visitNamedFunction(function, data)
}
+ override fun visitDotQualifiedExpression(expression: KtDotQualifiedExpression, data: Void?): Void? {
+ // Dot qualified expressions such as "a.pkg.A.Inner" we want to remap back to front because the
+ // latter parts are more specific.
+ // I.e. we start with the inner class, and only if there is no mapping for that, do we try to remap
+ // the outer class.
+ expression.selectorExpression?.accept(this)
+ expression.receiverExpression.accept(this)
+ return null
+ }
+
+ override fun visitUserType(type: KtUserType, data: Void?): Void? {
+ // Same as visitDotQualifiedExpression but for typealias declarations
+ type.referenceExpression?.accept(this)
+ type.qualifier?.accept(this)
+ type.typeArgumentList?.accept(this)
+ return null
+ }
+
override fun visitReferenceExpression(expression: KtReferenceExpression, data: Void?): Void? {
if (valid(expression)) {
val target = bindingContext[BindingContext.REFERENCE_TARGET, expression]