From 13f1da25fb9908c3d775a24a42185f8762a348e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Carpenter=E2=84=A2=EF=B8=8F?= Date: Fri, 28 Jun 2024 16:49:17 +0000 Subject: [PATCH] refactor: Migrate to Java 21 Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.java.migrate.UpgradeToJava21?organizationId=T3BlblJld3JpdGU%3D Co-authored-by: Moderne --- .../org/openrewrite/micrometer/TimerToObservation.java | 8 ++++---- .../micrometer/misk/MigrateEmptyLabelMiskCounter.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/openrewrite/micrometer/TimerToObservation.java b/src/main/java/org/openrewrite/micrometer/TimerToObservation.java index d30f688..5cc6f91 100644 --- a/src/main/java/org/openrewrite/micrometer/TimerToObservation.java +++ b/src/main/java/org/openrewrite/micrometer/TimerToObservation.java @@ -80,7 +80,7 @@ public J.CompilationUnit visitCompilationUnit(J.CompilationUnit compilationUnit, public J.MethodInvocation visitMethodInvocation(J.MethodInvocation mi, ExecutionContext ctx) { if (registerMatcher.matches(mi)) { Expression timerName = null; - Expression registry = mi.getArguments().get(0); + Expression registry = mi.getArguments().getFirst(); List builder = new ArrayList<>(); List parameters = new ArrayList<>(); @@ -89,11 +89,11 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation mi, Execution while (maybeBuilder instanceof J.MethodInvocation) { J.MethodInvocation builderMethod = (J.MethodInvocation) maybeBuilder; if (builderMatcher.matches(maybeBuilder)) { - timerName = builderMethod.getArguments().get(0); + timerName = builderMethod.getArguments().getFirst(); } else if (tagMatcher.matches(maybeBuilder)) { builder.add("\n.highCardinalityKeyValue(#{any(String)}, #{any(String)})"); - parameters.add(builderMethod.getArguments().get(0)); + parameters.add(builderMethod.getArguments().getFirst()); parameters.add(builderMethod.getArguments().get(1)); } else if (tagsIterableMatcher.matches(maybeBuilder)) { @@ -112,7 +112,7 @@ else if (tagsMatcher.matches(maybeBuilder)) { maybeBuilder = ((J.MethodInvocation) maybeBuilder).getSelect(); } if (timerName != null) { - parameters.add(0, timerName); + parameters.addFirst(timerName); parameters.add(1, registry); maybeAddImport("io.micrometer.observation.Observation"); diff --git a/src/main/java/org/openrewrite/micrometer/misk/MigrateEmptyLabelMiskCounter.java b/src/main/java/org/openrewrite/micrometer/misk/MigrateEmptyLabelMiskCounter.java index 39b9ceb..4ed7495 100644 --- a/src/main/java/org/openrewrite/micrometer/misk/MigrateEmptyLabelMiskCounter.java +++ b/src/main/java/org/openrewrite/micrometer/misk/MigrateEmptyLabelMiskCounter.java @@ -74,7 +74,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu (String name, String help) -> Counter.builder(name).description(help).register(Metrics.globalRegistry) ).build().apply(getCursor(), method.getCoordinates().replace(), - method.getArguments().get(0), + method.getArguments().getFirst(), method.getArguments().get(1)); maybeRemoveImport("misk.metrics.v2.Metrics");