diff options
author | Jonas Herzig <me@johni0702.de> | 2019-12-08 10:48:18 +0100 |
---|---|---|
committer | Jonas Herzig <me@johni0702.de> | 2019-12-08 10:48:18 +0100 |
commit | ff84669a02e8ffd3e634db4321dbc199b35effce (patch) | |
tree | de8f4986a08b4928c431939593cf99edcdceb82a /src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt | |
parent | ec5bedf0458bec38c39290be85bafac0ea78f2ad (diff) | |
download | Remap-ff84669a02e8ffd3e634db4321dbc199b35effce.tar.gz Remap-ff84669a02e8ffd3e634db4321dbc199b35effce.tar.bz2 Remap-ff84669a02e8ffd3e634db4321dbc199b35effce.zip |
Disambiguate Inject/Redirect targets where necessary (fixes #5)
This is done on a best-effort basis under the assumption that all
relevant methods are part of the mappings (since we don't actually
have access to the remapped MC jar at this point, so we can only check
for ambiguities with the mappings).
Diffstat (limited to 'src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt')
-rw-r--r-- | src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt b/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt index f999f8f..1e5b5ad 100644 --- a/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt +++ b/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt @@ -297,22 +297,30 @@ internal class PsiMapper(private val map: MappingSet, private val file: PsiFile) if ("method" != attribute.name) continue // Note: mixin supports multiple targets, we do not (yet) val literalValue = attribute.literalValue ?: continue - var mapped: String? - if (literalValue.contains("(")) { - mapped = mapping.findMethodMapping(MethodSignature.of(literalValue))?.deobfuscatedName + val methodMapping = if ('(' in literalValue) { + val signature = MethodSignature.of(literalValue) + // mapping.findMethodMapping(signature) + // TODO for some reason above doesn't work (probably related to legacy mappings) but below does + mapping.methodMappings.find { it.signature == signature } } else { - mapped = null - for (methodMapping in mapping.methodMappings) { - if (methodMapping.obfuscatedName == literalValue) { - val name = methodMapping.deobfuscatedName - if (mapped != null && mapped != name) { - error(attribute, "Ambiguous mixin method \"$literalValue\" maps to \"$mapped\" and \"$name\"") - } - mapped = name - } + val mappings = mapping.methodMappings.filter { it.obfuscatedName == literalValue } + if (mappings.size > 1) { + error(attribute, "Ambiguous mixin method \"$literalValue\" may refer to any of: ${mappings.joinToString { "\"$it\"" }}") } + mappings.firstOrNull() + } ?: continue + + val ambiguousName = mapping.methodMappings.any { + it != methodMapping && it.deobfuscatedName == methodMapping.deobfuscatedName + } + val mappedSignature = methodMapping.deobfuscatedSignature + val mapped = mappedSignature.name + if (ambiguousName) { + mappedSignature.descriptor + } else { + "" } - if (mapped != null && mapped != literalValue) { + + if (mapped != literalValue) { val value = attribute.value!! replace(value, '"'.toString() + mapped + '"'.toString()) } |