aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/kotlin/com/replaymod/gradle/remap/PsiPattern.kt2
-rw-r--r--src/test/kotlin/com/replaymod/gradle/remap/pattern/TestNewExpression.kt69
-rw-r--r--src/testA/java/a/pkg/AParent.java3
3 files changed, 74 insertions, 0 deletions
diff --git a/src/main/kotlin/com/replaymod/gradle/remap/PsiPattern.kt b/src/main/kotlin/com/replaymod/gradle/remap/PsiPattern.kt
index 9a067da..9bf1e90 100644
--- a/src/main/kotlin/com/replaymod/gradle/remap/PsiPattern.kt
+++ b/src/main/kotlin/com/replaymod/gradle/remap/PsiPattern.kt
@@ -84,6 +84,8 @@ internal class PsiPattern(
is PsiParenthesizedExpression -> expr is PsiParenthesizedExpression
&& match(pattern.expression, expr.expression)
is PsiNewExpression -> expr is PsiNewExpression
+ && pattern.classReference?.resolve() == expr.classReference?.resolve()
+ && match(pattern.qualifier, expr.qualifier)
&& match(pattern.argumentList, expr.argumentList)
is PsiLiteralExpression -> expr is PsiLiteralExpression
&& pattern.text == expr.text
diff --git a/src/test/kotlin/com/replaymod/gradle/remap/pattern/TestNewExpression.kt b/src/test/kotlin/com/replaymod/gradle/remap/pattern/TestNewExpression.kt
new file mode 100644
index 0000000..669cffb
--- /dev/null
+++ b/src/test/kotlin/com/replaymod/gradle/remap/pattern/TestNewExpression.kt
@@ -0,0 +1,69 @@
+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 TestNewExpression {
+ @Test
+ fun `should find regular constructor`() {
+ TestData.remap("""
+ class Test {
+ private void test() {
+ new a.pkg.A(null);
+ new a.pkg.A().new a.pkg.A.Inner();
+ new a.pkg.AParent(null);
+ }
+ }
+ """.trimIndent(), """
+ @remap.Pattern
+ private a.pkg.A matchNew(a.pkg.A arg) {
+ return new a.pkg.A(arg);
+ }
+ """.trimIndent(), """
+ @remap.Pattern
+ private b.pkg.B matchNew(b.pkg.B arg) {
+ return arg;
+ }
+ """.trimIndent()) shouldBe """
+ class Test {
+ private void test() {
+ null;
+ new b.pkg.B().new b.pkg.B.Inner();
+ new b.pkg.BParent(null);
+ }
+ }
+ """.trimIndent()
+ }
+
+ @Test
+ fun `should find inner class constructor`() {
+ TestData.remap("""
+ class Test {
+ private void test() {
+ new a.pkg.A(null);
+ new a.pkg.A().new Inner();
+ new a.pkg.AParent(null);
+ }
+ }
+ """.trimIndent(), """
+ @remap.Pattern
+ private a.pkg.A.Inner matchNew(a.pkg.A arg) {
+ return arg.new a.pkg.A.Inner();
+ }
+ """.trimIndent(), """
+ @remap.Pattern
+ private b.pkg.B matchNew(b.pkg.B arg) {
+ return arg;
+ }
+ """.trimIndent()) shouldBe """
+ class Test {
+ private void test() {
+ new b.pkg.B(null);
+ new b.pkg.B();
+ new b.pkg.BParent(null);
+ }
+ }
+ """.trimIndent()
+ }
+} \ No newline at end of file
diff --git a/src/testA/java/a/pkg/AParent.java b/src/testA/java/a/pkg/AParent.java
index ac0ea7c..3edf2a9 100644
--- a/src/testA/java/a/pkg/AParent.java
+++ b/src/testA/java/a/pkg/AParent.java
@@ -4,4 +4,7 @@ public class AParent {
public AParent aParentMethod() {
return this;
}
+
+ public AParent() {}
+ public AParent(A arg) {}
}