aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJonas Herzig <me@johni0702.de>2022-05-27 08:46:47 +0200
committerJonas Herzig <me@johni0702.de>2022-05-27 08:55:50 +0200
commit5504b2ff877609d3800d5fce4fbc36a3b01911a5 (patch)
treefdc4da602d2604eab6f63acd7703b856cfa3d776 /src
parentcde89808e3d9730fe784597bd6bbfc51753663a1 (diff)
downloadRemap-5504b2ff877609d3800d5fce4fbc36a3b01911a5.tar.gz
Remap-5504b2ff877609d3800d5fce4fbc36a3b01911a5.tar.bz2
Remap-5504b2ff877609d3800d5fce4fbc36a3b01911a5.zip
Fix nested pattern matching
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/com/replaymod/gradle/remap/PsiPattern.kt3
-rw-r--r--src/test/kotlin/com/replaymod/gradle/remap/pattern/TestFieldReference.kt40
2 files changed, 41 insertions, 2 deletions
diff --git a/src/main/kotlin/com/replaymod/gradle/remap/PsiPattern.kt b/src/main/kotlin/com/replaymod/gradle/remap/PsiPattern.kt
index c1cdf0f..8573560 100644
--- a/src/main/kotlin/com/replaymod/gradle/remap/PsiPattern.kt
+++ b/src/main/kotlin/com/replaymod/gradle/remap/PsiPattern.kt
@@ -18,9 +18,8 @@ internal class PsiPattern(
val matcher = Matcher(element)
if (matcher.match(pattern)) {
result.add(matcher)
- } else {
- super.visitElement(element)
}
+ super.visitElement(element)
}
})
}
diff --git a/src/test/kotlin/com/replaymod/gradle/remap/pattern/TestFieldReference.kt b/src/test/kotlin/com/replaymod/gradle/remap/pattern/TestFieldReference.kt
new file mode 100644
index 0000000..a3a6efc
--- /dev/null
+++ b/src/test/kotlin/com/replaymod/gradle/remap/pattern/TestFieldReference.kt
@@ -0,0 +1,40 @@
+package com.replaymod.gradle.remap.pattern
+
+import com.replaymod.gradle.remap.util.TestData
+import io.kotest.matchers.shouldBe
+import org.junit.jupiter.api.Test
+
+class TestFieldReference {
+ @Test
+ fun `should match field on left side of assignment when replaced by field`() {
+ TestData.remap("test/Test.java", """
+ class Test {
+ Test field;
+ private void test() {
+ field = field;
+ this.field = this.field;
+ this.field.field = this.field.field;
+ }
+ }
+ """.trimIndent(), """
+ @remap.Pattern
+ private test.Test pattern(test.Test obj) {
+ return obj.field;
+ }
+ """.trimIndent(), """
+ @remap.Pattern
+ private test.Test pattern(test.Test obj) {
+ return obj.matched;
+ }
+ """.trimIndent()) shouldBe """
+ class Test {
+ Test field;
+ private void test() {
+ field = field;
+ this.matched = this.matched;
+ this.matched.matched = this.matched.matched;
+ }
+ }
+ """.trimIndent()
+ }
+} \ No newline at end of file