diff options
author | Jonas Herzig <me@johni0702.de> | 2019-11-01 02:07:08 +0100 |
---|---|---|
committer | Jonas Herzig <me@johni0702.de> | 2019-11-01 02:07:08 +0100 |
commit | 3b79c8d6d30228887edd17455f9d2b6aa8841ddf (patch) | |
tree | 8b18141c63cba189ddcd63f7182694edfd58324e | |
parent | 423c59be1aff5460b6c36bbb8e2cfdcd13de6863 (diff) | |
download | Remap-3b79c8d6d30228887edd17455f9d2b6aa8841ddf.tar.gz Remap-3b79c8d6d30228887edd17455f9d2b6aa8841ddf.tar.bz2 Remap-3b79c8d6d30228887edd17455f9d2b6aa8841ddf.zip |
Fix remapping when inner classes are in play
Lorenz requires inner classes to be separated from their parents by a
dollar sign (i.e. bytecode format), intellij instead by default gives
you source format (i.e. separated by dot, indistinguishable from
packages).
-rw-r--r-- | src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt | 17 | ||||
-rw-r--r-- | src/main/kotlin/com/replaymod/gradle/remap/PsiUtils.kt | 10 |
2 files changed, 18 insertions, 9 deletions
diff --git a/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt b/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt index 7d4c054..1109a01 100644 --- a/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt +++ b/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt @@ -67,8 +67,8 @@ internal class PsiMapper(private val map: MappingSet, private val file: PsiFile) private fun map(expr: PsiElement, field: PsiField) { val fieldName = field.name ?: return val declaringClass = field.containingClass ?: return - val name = declaringClass.qualifiedName ?: return - var mapping: ClassMapping<*, *>? = this.mixinMappings[name] + val name = declaringClass.dollarQualifiedName ?: return + var mapping: ClassMapping<*, *>? = this.mixinMappings[declaringClass.qualifiedName ?: return] if (mapping == null) { mapping = map.findClassMapping(name) } @@ -168,7 +168,7 @@ internal class PsiMapper(private val map: MappingSet, private val file: PsiFile) parentQueue.offer(anInterface) } - name = declaringClass.qualifiedName + name = declaringClass.dollarQualifiedName if (name == null) continue mapping = map.findClassMapping(name) } @@ -177,10 +177,11 @@ internal class PsiMapper(private val map: MappingSet, private val file: PsiFile) private fun map(expr: PsiElement, resolved: PsiQualifiedNamedElement) { val name = resolved.qualifiedName ?: return - val mapping = map.findClassMapping(name) ?: return - var mapped = mapping.deobfuscatedName - if (mapped == name) return - mapped = mapped.replace('/', '.') + val dollarName = (if (resolved is PsiClass) resolved.dollarQualifiedName else name) ?: return + val mapping = map.findClassMapping(dollarName) ?: return + var mapped = mapping.fullDeobfuscatedName + if (mapped == dollarName) return + mapped = mapped.replace('/', '.').replace('$', '.') if (expr.text == name) { replace(expr, mapped) @@ -391,7 +392,7 @@ internal class PsiMapper(private val map: MappingSet, private val file: PsiFile) remapAtTargets() val target = getMixinTarget(annotation) ?: return - val qualifiedName = target.qualifiedName ?: return + val qualifiedName = target.dollarQualifiedName ?: return val mapping = map.findClassMapping(qualifiedName) ?: return diff --git a/src/main/kotlin/com/replaymod/gradle/remap/PsiUtils.kt b/src/main/kotlin/com/replaymod/gradle/remap/PsiUtils.kt index 4a435b9..63f0e76 100644 --- a/src/main/kotlin/com/replaymod/gradle/remap/PsiUtils.kt +++ b/src/main/kotlin/com/replaymod/gradle/remap/PsiUtils.kt @@ -8,8 +8,16 @@ import org.cadixdev.bombe.type.Type import org.cadixdev.bombe.type.VoidType import org.cadixdev.bombe.type.signature.MethodSignature import org.jetbrains.kotlin.com.intellij.psi.* +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 + val parentName = parent.dollarQualifiedName ?: return qualifiedName + val selfName = name ?: return qualifiedName + return "$parentName$$selfName" +} + internal object PsiUtils { fun getSignature(method: PsiMethod): MethodSignature = MethodSignature(method.name, getDescriptor(method)) @@ -26,7 +34,7 @@ internal object PsiUtils { } is PsiClassType -> { val resolved = erasedType.resolve() ?: throw NullPointerException("Failed to resolve type $erasedType") - val qualifiedName = resolved.qualifiedName + val qualifiedName = resolved.dollarQualifiedName ?: throw NullPointerException("Type $erasedType has no qualified name.") ObjectType(qualifiedName) } |