-
-
Save mike-solomon/3b49a5d19c8824776bcc4ee871b87cdd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.yourorg; | |
import org.openrewrite.ExecutionContext; | |
import org.openrewrite.Preconditions; | |
import org.openrewrite.Recipe; | |
import org.openrewrite.TreeVisitor; | |
import org.openrewrite.internal.lang.NonNullApi; | |
import org.openrewrite.java.JavaIsoVisitor; | |
import org.openrewrite.java.MethodMatcher; | |
import org.openrewrite.java.search.UsesMethod; | |
import org.openrewrite.java.tree.J; | |
import org.openrewrite.marker.SearchResult; | |
@NonNullApi | |
public class FindSysOutPrint extends Recipe { | |
@Override | |
public String getDisplayName() { | |
return "My recipe"; | |
} | |
@Override | |
public String getDescription() { | |
return "This is a description of what the recipe does."; | |
} | |
@Override | |
public TreeVisitor<?, ExecutionContext> getVisitor() { | |
MethodMatcher matcher = new MethodMatcher("java.io.PrintStream#println(java.lang.String)"); | |
return Preconditions.check(new UsesMethod<>(matcher), new JavaIsoVisitor<ExecutionContext>() { | |
@Override | |
public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) { | |
if (matcher.matches(method)) { | |
// TODO do something other than just mark the method as found? | |
return SearchResult.found(method); | |
} | |
return super.visitMethodInvocation(method, ctx); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment