From 5b9805a803d193ac5ae68ac758ed847bf15efca7 Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Sat, 2 Nov 2019 01:07:30 +0100 Subject: Support remapping in mixins with string-typed targets i.e. Fields and methods in @Mixin("package.SomeClass$Inner") but not the class string itself --- .../kotlin/com/replaymod/gradle/remap/PsiMapper.kt | 25 +++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt b/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt index 6a7424b..6065cbe 100644 --- a/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt +++ b/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt @@ -208,16 +208,22 @@ internal class PsiMapper(private val map: MappingSet, private val file: PsiFile) } } - // Note: Supports only Mixins with a single target (ignores others) and only ones specified via class literals - private fun getMixinTarget(annotation: PsiAnnotation): PsiClass? { + // Note: Supports only Mixins with a single target (ignores others) + private fun getMixinTarget(annotation: PsiAnnotation): String? { for (pair in annotation.parameterList.attributes) { val name = pair.name - if (name != null && "value" != name) continue - val value = pair.value - if (value !is PsiClassObjectAccessExpression) continue - val type = value.operand - val reference = type.innermostComponentReferenceElement ?: continue - return reference.resolve() as PsiClass? + if (name == null || "value" == name) { + val value = pair.value + if (value !is PsiClassObjectAccessExpression) continue + val type = value.operand + val reference = type.innermostComponentReferenceElement ?: continue + return (reference.resolve() as PsiClass?)?.dollarQualifiedName + } + if ("targets" == name) { + val value = pair.value + if (value !is PsiLiteral) continue + return value.value as? String ?: continue + } } return null } @@ -396,8 +402,7 @@ internal class PsiMapper(private val map: MappingSet, private val file: PsiFile) remapAtTargets() - val target = getMixinTarget(annotation) ?: return - val qualifiedName = target.dollarQualifiedName ?: return + val qualifiedName = getMixinTarget(annotation) ?: return val mapping = map.findClassMapping(qualifiedName) ?: return -- cgit