From 8d8fbf3c87bdb8dae7251c1a2f35578f26e8b46a Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sat, 23 Nov 2024 15:03:10 +0100 Subject: [PATCH] Fix build following stricter validations from upstream --- .../micrometer/misk/NoExplicitEmptyLabelList.java | 13 +++++++++++-- .../misk/MigrateEmptyLabelMiskCounterTest.java | 4 ++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/openrewrite/micrometer/misk/NoExplicitEmptyLabelList.java b/src/main/java/org/openrewrite/micrometer/misk/NoExplicitEmptyLabelList.java index 09b4d1b..b971c8b 100644 --- a/src/main/java/org/openrewrite/micrometer/misk/NoExplicitEmptyLabelList.java +++ b/src/main/java/org/openrewrite/micrometer/misk/NoExplicitEmptyLabelList.java @@ -23,11 +23,14 @@ import org.openrewrite.java.JavaParser; import org.openrewrite.java.JavaTemplate; import org.openrewrite.java.tree.J; +import org.openrewrite.java.tree.JavaType; import org.openrewrite.java.tree.TypeUtils; import java.util.Arrays; import java.util.List; +import static java.util.Collections.emptyList; + public class NoExplicitEmptyLabelList extends Recipe { @Override @@ -42,7 +45,6 @@ public String getDescription() { @Override public TreeVisitor getVisitor() { - return new JavaIsoVisitor() { final List hasEmptyLabel = Arrays.asList( JavaTemplate.builder("#{m:any(misk.metrics.v2.Metrics)}.counter(#{s:any(java.lang.String)}, #{s1:any(java.lang.String)}, listOf())") @@ -63,7 +65,14 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu if (method.getSelect() != null && TypeUtils.isOfClassType(method.getSelect().getType(), "misk.metrics.v2.Metrics") && hasEmptyLabel.stream().anyMatch(tmpl -> tmpl.matches(getCursor()))) { - return method.withArguments(ListUtils.map(method.getArguments(), (i, a) -> i == 2 ? null : a)); + JavaType.Method methodType = method.getMethodType(); + if (methodType != null) { + methodType = methodType.withParameterNames(emptyList()).withParameterTypes(emptyList()); + } + return method + .withArguments(ListUtils.map(method.getArguments(), (i, a) -> i == 2 ? null : a)) + .withMethodType(methodType) + .withName(method.getName().withType(methodType)); } return super.visitMethodInvocation(method, ctx); } diff --git a/src/test/java/org/openrewrite/micrometer/misk/MigrateEmptyLabelMiskCounterTest.java b/src/test/java/org/openrewrite/micrometer/misk/MigrateEmptyLabelMiskCounterTest.java index a3f6f05..2db30cc 100644 --- a/src/test/java/org/openrewrite/micrometer/misk/MigrateEmptyLabelMiskCounterTest.java +++ b/src/test/java/org/openrewrite/micrometer/misk/MigrateEmptyLabelMiskCounterTest.java @@ -41,7 +41,7 @@ void migrateEmptyLabel() { """ import misk.metrics.v2.Metrics; import static kotlin.collections.CollectionsKt.listOf; - + class Test { void test(Metrics metrics) { metrics.counter("counter", "description", listOf()); @@ -52,7 +52,7 @@ void test(Metrics metrics) { import io.micrometer.core.instrument.Counter; import misk.metrics.v2.Metrics; import static kotlin.collections.CollectionsKt.listOf; - + class Test { void test(Metrics metrics) { Counter.builder("counter").description("description").register(Metrics.globalRegistry);