aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/replaymod/gradle/remap
diff options
context:
space:
mode:
authorJonas Herzig <me@johni0702.de>2022-05-27 08:47:10 +0200
committerJonas Herzig <me@johni0702.de>2022-05-27 08:55:53 +0200
commit97d6082a172ca1c3872f81470bf64c6a42d1a571 (patch)
tree2878d74abf154be3ab6f5daf2ced825a495457c3 /src/main/kotlin/com/replaymod/gradle/remap
parent5504b2ff877609d3800d5fce4fbc36a3b01911a5 (diff)
downloadRemap-97d6082a172ca1c3872f81470bf64c6a42d1a571.tar.gz
Remap-97d6082a172ca1c3872f81470bf64c6a42d1a571.tar.bz2
Remap-97d6082a172ca1c3872f81470bf64c6a42d1a571.zip
Fix pattern applying non-field to left side of assignment
Diffstat (limited to 'src/main/kotlin/com/replaymod/gradle/remap')
-rw-r--r--src/main/kotlin/com/replaymod/gradle/remap/PsiPattern.kt11
-rw-r--r--src/main/kotlin/com/replaymod/gradle/remap/PsiPatterns.kt4
2 files changed, 12 insertions, 3 deletions
diff --git a/src/main/kotlin/com/replaymod/gradle/remap/PsiPattern.kt b/src/main/kotlin/com/replaymod/gradle/remap/PsiPattern.kt
index 8573560..4e3a60a 100644
--- a/src/main/kotlin/com/replaymod/gradle/remap/PsiPattern.kt
+++ b/src/main/kotlin/com/replaymod/gradle/remap/PsiPattern.kt
@@ -10,7 +10,8 @@ internal class PsiPattern(
private val parameters: Set<PsiParameter>,
private val varArgs: Boolean,
private val pattern: PsiStatement,
- private val replacement: List<String>
+ private val replacement: List<String>,
+ private val replacementCanBeAssigned: Boolean,
) {
private fun find(pattern: PsiElement, tree: PsiElement, result: MutableList<Matcher>) {
tree.accept(object : JavaRecursiveElementVisitor() {
@@ -66,7 +67,13 @@ internal class PsiPattern(
return changes.filterNot { it.first.isEmpty && it.second.isEmpty() }
}
- fun match(pattern: PsiElement): Boolean = match(pattern, root)
+ fun match(pattern: PsiElement): Boolean {
+ val parent = root.parent
+ if (parent is PsiAssignmentExpression && parent.lExpression == root && !replacementCanBeAssigned) {
+ return false
+ }
+ return match(pattern, root)
+ }
private fun match(pattern: PsiElement?, expr: PsiElement?): Boolean = when (pattern) {
null -> expr == null
diff --git a/src/main/kotlin/com/replaymod/gradle/remap/PsiPatterns.kt b/src/main/kotlin/com/replaymod/gradle/remap/PsiPatterns.kt
index fe6040c..ac5ea10 100644
--- a/src/main/kotlin/com/replaymod/gradle/remap/PsiPatterns.kt
+++ b/src/main/kotlin/com/replaymod/gradle/remap/PsiPatterns.kt
@@ -72,7 +72,9 @@ internal class PsiPatterns(private val annotationFQN: String) {
replacement.push(replacementFile.slice(start until replacementExpression.endOffset))
}
- patterns.add(PsiPattern(parameters, varArgs, body.statements.last(), replacement))
+ val replacementCanBeAssigned = replacementExpression is PsiReferenceExpression
+
+ patterns.add(PsiPattern(parameters, varArgs, body.statements.last(), replacement, replacementCanBeAssigned))
}
fun find(block: PsiCodeBlock): MutableList<Matcher> {