aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/com')
-rw-r--r--src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt8
-rw-r--r--src/main/kotlin/com/replaymod/gradle/remap/PsiUtils.kt14
2 files changed, 17 insertions, 5 deletions
diff --git a/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt b/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt
index 9ddb78a..b131478 100644
--- a/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt
+++ b/src/main/kotlin/com/replaymod/gradle/remap/PsiMapper.kt
@@ -298,7 +298,7 @@ internal class PsiMapper(private val map: MappingSet, private val file: PsiFile)
for (attribute in annotation.parameterList.attributes) {
if ("method" != attribute.name) continue
// Note: mixin supports multiple targets, we do not (yet)
- val literalValue = attribute.literalValue ?: continue
+ val (literalExpr, literalValue) = attribute.resolvedLiteralValue ?: continue
val methodMapping = if ('(' in literalValue) {
val signature = MethodSignature.of(literalValue)
// mapping.findMethodMapping(signature)
@@ -323,8 +323,7 @@ internal class PsiMapper(private val map: MappingSet, private val file: PsiFile)
}
if (mapped != literalValue) {
- val value = attribute.value!!
- replace(value, '"'.toString() + mapped + '"'.toString())
+ replace(literalExpr, '"'.toString() + mapped + '"'.toString())
}
}
}
@@ -418,10 +417,9 @@ internal class PsiMapper(private val map: MappingSet, private val file: PsiFile)
for (attribute in annotation.parameterList.attributes) {
if ("target" != attribute.name) continue
- val signature = attribute.literalValue ?: continue
+ val (value, signature) = attribute.resolvedLiteralValue ?: continue
val newSignature = remapMixinTarget(signature)
if (newSignature != signature) {
- val value = attribute.value!!
replace(value, "\"$newSignature\"")
}
}
diff --git a/src/main/kotlin/com/replaymod/gradle/remap/PsiUtils.kt b/src/main/kotlin/com/replaymod/gradle/remap/PsiUtils.kt
index 63f0e76..936ab89 100644
--- a/src/main/kotlin/com/replaymod/gradle/remap/PsiUtils.kt
+++ b/src/main/kotlin/com/replaymod/gradle/remap/PsiUtils.kt
@@ -7,6 +7,7 @@ import org.cadixdev.bombe.type.ObjectType
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.openapi.util.text.StringUtil
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
@@ -18,6 +19,19 @@ internal val PsiClass.dollarQualifiedName: String? get() {
return "$parentName$$selfName"
}
+internal val PsiNameValuePair.resolvedLiteralValue: Pair<PsiLiteralExpression, String>? get () {
+ var value: PsiElement? = value
+ while (value is PsiReferenceExpression) {
+ val resolved = value.resolve()
+ value = when (resolved) {
+ is PsiField -> resolved.initializer
+ else -> resolved
+ }
+ }
+ val literal = value as? PsiLiteralExpression ?: return null
+ return Pair(literal, StringUtil.unquoteString(literal.text))
+}
+
internal object PsiUtils {
fun getSignature(method: PsiMethod): MethodSignature = MethodSignature(method.name, getDescriptor(method))