From b969b95659338860bc99a2b6c3b64167242147f0 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Sun, 28 Jan 2024 18:21:04 +0100 Subject: [PATCH] Test overload support --- .../ExhaustiveRefasterTypeMigration.java | 6 ++++-- .../ExhaustiveRefasterTypeMigrationTest.java | 19 +++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ExhaustiveRefasterTypeMigration.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ExhaustiveRefasterTypeMigration.java index 3ea288eb66..78f539d26a 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ExhaustiveRefasterTypeMigration.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ExhaustiveRefasterTypeMigration.java @@ -9,7 +9,6 @@ import static com.google.errorprone.matchers.Matchers.annotations; import static com.google.errorprone.matchers.Matchers.isType; import static java.util.Comparator.comparing; -import static java.util.Comparator.naturalOrder; import static java.util.stream.Collectors.toCollection; import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL; @@ -194,7 +193,10 @@ private static Comparator signatureOrder(ImmutableList existingO knownEntries.putIfAbsent(existingOrder.get(i), i); } - return comparing((String v) -> knownEntries.getOrDefault(v, -1)).thenComparing(naturalOrder()); + // XXX: The lexicographical order applied to unknown entries aims to match the order applied by + // the `LexicographicalAnnotationAttributeListing` check; consider deduplicating this logic. + return comparing((String v) -> knownEntries.getOrDefault(v, -1)) + .thenComparing(String.CASE_INSENSITIVE_ORDER); } /** diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ExhaustiveRefasterTypeMigrationTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ExhaustiveRefasterTypeMigrationTest.java index 0030a63c70..f684d28593 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ExhaustiveRefasterTypeMigrationTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ExhaustiveRefasterTypeMigrationTest.java @@ -165,6 +165,10 @@ void replacement() { " public String publicStringMethodWithArg(int arg) {", " return String.valueOf(arg);", " }", + "", + " public String publicStringMethodWithArg(String arg) {", + " return arg;", + " }", "}") .expectUnchanged() .addInputLines( @@ -191,6 +195,7 @@ void replacement() { " class AnnotatedWithIncorrectMethodReference {", " @BeforeTemplate", " void before() {", + " new Util().publicStringMethodWithArg(\"1\");", " Util.publicStaticVoidMethod();", " Util.publicStaticIntMethod2();", " }", @@ -203,6 +208,7 @@ void replacement() { " @BeforeTemplate", " void before() {", " new Util().publicStringMethodWithArg(1);", + " new Util().publicStringMethodWithArg(\"1\");", " Util.publicStaticIntMethod2();", " }", " }", @@ -214,7 +220,12 @@ void replacement() { "", "class A {", " @TypeMigration(", - " unmigratedMethods = {\"Util()\", \"publicStaticVoidMethod()\", \"publicStringMethodWithArg(int)\"},", + " unmigratedMethods = {", + " \"publicStaticVoidMethod()\",", + " \"publicStringMethodWithArg(int)\",", + " \"publicStringMethodWithArg(String)\",", + " \"Util()\"", + " },", " of = Util.class)", " class AnnotatedWithoutMethodListing {", " {", @@ -227,12 +238,11 @@ void replacement() { " }", " }", "", - " @TypeMigration(", - " of = Util.class,", - " unmigratedMethods = {\"Util()\", \"publicStringMethodWithArg(int)\"})", + " @TypeMigration(of = Util.class, unmigratedMethods = \"publicStringMethodWithArg(int)\")", " class AnnotatedWithIncorrectMethodReference {", " @BeforeTemplate", " void before() {", + " new Util().publicStringMethodWithArg(\"1\");", " Util.publicStaticVoidMethod();", " Util.publicStaticIntMethod2();", " }", @@ -243,6 +253,7 @@ void replacement() { " @BeforeTemplate", " void before() {", " new Util().publicStringMethodWithArg(1);", + " new Util().publicStringMethodWithArg(\"1\");", " Util.publicStaticIntMethod2();", " }", " }",