Skip to content

Commit

Permalink
Use method matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurens-W committed Oct 4, 2024
1 parent 2e55442 commit 34553b4
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class MigrateWebMvcTagsToObservationConvention extends Recipe {
private static final MethodMatcher TAGS_OF_TAG_ITERABLE = new MethodMatcher("io.micrometer.core.instrument.Tags of(java.lang.Iterable)");
private static final MethodMatcher TAGS_OF_ANY = new MethodMatcher("io.micrometer.core.instrument.Tags of(..)");
private static final MethodMatcher TAG_OF = new MethodMatcher("io.micrometer.core.instrument.Tag of(java.lang.String, java.lang.String)");
private static final MethodMatcher GET_TAGS = new MethodMatcher("* getTags(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse, java.lang.Object, java.lang.Throwable)");

@Override
public String getDisplayName() {
Expand All @@ -74,7 +75,7 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex
for (Statement stmt : classDecl.getBody().getStatements()) {
if (stmt instanceof J.MethodDeclaration) {
J.MethodDeclaration md = (J.MethodDeclaration) stmt;
if (md.getSimpleName().equals("getTags")) {
if (GET_TAGS.matches(md, classDecl)) {
getTagsMethod = md;
if (getTagsMethod.getBody() != null) {
getTagsBodyStatements.addAll(getTagsMethod.getBody().getStatements().subList(0, getTagsMethod.getBody().getStatements().size() - 1));
Expand Down

0 comments on commit 34553b4

Please sign in to comment.