Skip to content

Commit

Permalink
Fix build following stricter validations from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Nov 23, 2024
1 parent 1bb68bc commit 8d8fbf3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -42,7 +45,6 @@ public String getDescription() {

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {

return new JavaIsoVisitor<ExecutionContext>() {
final List<JavaTemplate> hasEmptyLabel = Arrays.asList(
JavaTemplate.builder("#{m:any(misk.metrics.v2.Metrics)}.counter(#{s:any(java.lang.String)}, #{s1:any(java.lang.String)}, listOf())")
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
Expand Down

0 comments on commit 8d8fbf3

Please sign in to comment.