aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com
diff options
context:
space:
mode:
authorJonas Herzig <me@johni0702.de>2019-12-07 11:31:31 +0100
committerJonas Herzig <me@johni0702.de>2019-12-07 11:31:31 +0100
commit356541c5c2b279d29675e15a9098d5a21d399317 (patch)
tree15e0a2fd7ac65064cfe3705930b22db46e619542 /src/main/kotlin/com
parent64d841acfff4f515173120202172800e1be88f2e (diff)
downloadRemap-356541c5c2b279d29675e15a9098d5a21d399317.tar.gz
Remap-356541c5c2b279d29675e15a9098d5a21d399317.tar.bz2
Remap-356541c5c2b279d29675e15a9098d5a21d399317.zip
Remap non-getter to synthetic property where possible (fixes #2)
Diffstat (limited to 'src/main/kotlin/com')
-rw-r--r--src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt b/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt
index b2be523..e6b5f80 100644
--- a/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt
+++ b/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt
@@ -6,6 +6,7 @@ import org.cadixdev.lorenz.MappingSet
import org.cadixdev.lorenz.model.ClassMapping
import org.jetbrains.kotlin.asJava.getRepresentativeLightMethod
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
+import org.jetbrains.kotlin.com.intellij.lang.jvm.JvmModifier
import org.jetbrains.kotlin.com.intellij.openapi.util.TextRange
import org.jetbrains.kotlin.com.intellij.openapi.util.text.StringUtil
import org.jetbrains.kotlin.com.intellij.psi.*
@@ -97,6 +98,22 @@ internal class PsiMapper(private val map: MappingSet, private val file: PsiFile)
val mapped = findMapping(method)
if (mapped != null && mapped != method.name) {
+ val maybeGetter = propertyNameByGetMethodName(Name.identifier(mapped))
+ if (maybeGetter != null // must have getter-style name
+ && !method.hasParameters() // getters cannot take any arguments
+ && method.returnType != PsiType.VOID // and must return some value
+ && !method.hasModifier(JvmModifier.STATIC) // synthetic properties cannot be static
+ // `super.getDebugInfo()` is a special case which cannot be replaced with a synthetic property
+ && expr.parent.parent.let { it !is KtDotQualifiedExpression || it.firstChild !is KtSuperExpression }
+ // cannot use synthetic properties outside of kotlin files (cause they're a kotlin thing)
+ && expr.containingFile is KtFile) {
+ // E.g. `entity.canUsePortal()` maps to `entity.isNonBoss()` but when we're using kotlin and the target
+ // isn't (as should be the case for remapped names), we can also write that as `entity.isNonBoss` (i.e.
+ // as a synthetic property).
+ // This is the reverse to the operation in [map(PsiElement, SyntheticJavaPropertyDescriptor)].
+ replace(expr.parent, maybeGetter.identifier)
+ return
+ }
replaceIdentifier(expr, mapped)
}
}