aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/replaymod/gradle/remap/PsiUtils.kt
diff options
context:
space:
mode:
authorJonas Herzig <me@johni0702.de>2020-11-22 14:14:14 +0100
committerJonas Herzig <me@johni0702.de>2020-11-22 14:27:51 +0100
commit6073541e763da17de3d51db0e9ee30ddafc01bb9 (patch)
tree7e69a921155aa83bdc66d81da7ddc8c0d2f50e53 /src/main/kotlin/com/replaymod/gradle/remap/PsiUtils.kt
parente49dc899920dce06383cb7f9bd3cba5316cda09b (diff)
downloadRemap-6073541e763da17de3d51db0e9ee30ddafc01bb9.tar.gz
Remap-6073541e763da17de3d51db0e9ee30ddafc01bb9.tar.bz2
Remap-6073541e763da17de3d51db0e9ee30ddafc01bb9.zip
Support remapping of mixin targets declared in static fields
String literals in annotations can be specified in a static final field instead of inline (so you can e.g. use the same literal in multiple places). This commit adds support for remapping those external literals.
Diffstat (limited to 'src/main/kotlin/com/replaymod/gradle/remap/PsiUtils.kt')
-rw-r--r--src/main/kotlin/com/replaymod/gradle/remap/PsiUtils.kt14
1 files changed, 14 insertions, 0 deletions
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))