From 5e9ae5e3956657ca3734191d393132566d9ac491 Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Mon, 11 Sep 2023 09:19:18 -0700 Subject: [PATCH] Fix finding batching in SameNameButDifferent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up to https://github.com/google/error-prone/commit/a87b281fcabef73baa4bd40537d0c008b4fe1e1d. The batching mode was only breaking out of an inner loop 🤦 PiperOrigin-RevId: 564407277 --- .../bugpatterns/SameNameButDifferent.java | 19 ++++++++++--------- .../bugpatterns/SameNameButDifferentTest.java | 1 - 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/SameNameButDifferent.java b/core/src/main/java/com/google/errorprone/bugpatterns/SameNameButDifferent.java index fccb79c97a5..9669aded089 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/SameNameButDifferent.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/SameNameButDifferent.java @@ -185,15 +185,16 @@ private void handle(Tree tree) { .map(t -> t.getQualifiedName().toString()) .collect(joining(", ", "[", "]"))); SuggestedFix fix = fixBuilder.build(); - for (List treePaths : trimmedTable.row(simpleName).values()) { - for (TreePath treePath : treePaths) { - state.reportMatch( - buildDescription(treePath.getLeaf()).setMessage(message).addFix(fix).build()); - if (batchFindings) { - break; - } - } - } + trimmedTable.row(simpleName).values().stream() + .flatMap(List::stream) + .limit(batchFindings ? 1 : Long.MAX_VALUE) + .forEach( + treePath -> + state.reportMatch( + buildDescription(treePath.getLeaf()) + .setMessage(message) + .addFix(fix) + .build())); } } return NO_MATCH; diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/SameNameButDifferentTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/SameNameButDifferentTest.java index 184c086e6f6..66633c57068 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/SameNameButDifferentTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/SameNameButDifferentTest.java @@ -224,7 +224,6 @@ public void ungroupedOverloadsPositiveCasesCoveringOnlyFirstOverload() { " }", " class Two {", " class Clash {}", - " // BUG: Diagnostic contains:", " Clash a;", " Clash b;", " }",