-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more internal test clean ups remove Datastore.ensure*() calls
- Loading branch information
1 parent
35374b4
commit 0041760
Showing
4 changed files
with
115 additions
and
4 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
rewrite/src/main/java/dev/morphia/rewrite/recipes/internal/RemoveMethodDeclaration.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package dev.morphia.rewrite.recipes.internal; | ||
|
||
import org.openrewrite.ExecutionContext; | ||
import org.openrewrite.Option; | ||
import org.openrewrite.Recipe; | ||
import org.openrewrite.TreeVisitor; | ||
import org.openrewrite.java.JavaVisitor; | ||
import org.openrewrite.java.MethodMatcher; | ||
import org.openrewrite.java.tree.J; | ||
import org.openrewrite.java.tree.J.MethodDeclaration; | ||
|
||
public class RemoveMethodDeclaration extends Recipe { | ||
@Option(displayName = "Method pattern", description = "A pattern to match method declarations for removal.", example = "java.lang.StringBuilder append(java.lang.String)") | ||
private String methodPattern; | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Remove method declarations"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Remove method declarations."; | ||
} | ||
|
||
public String getMethodPattern() { | ||
return methodPattern; | ||
} | ||
|
||
public void setMethodPattern(String methodPattern) { | ||
this.methodPattern = methodPattern; | ||
} | ||
|
||
@Override | ||
public TreeVisitor<?, ExecutionContext> getVisitor() { | ||
return new RemoveMethodDeclarationVisitor(methodPattern); | ||
} | ||
|
||
private class RemoveMethodDeclarationVisitor extends JavaVisitor<ExecutionContext> { | ||
private final MethodMatcher matcher; | ||
|
||
public RemoveMethodDeclarationVisitor(MethodMatcher matcher) { | ||
this.matcher = matcher; | ||
} | ||
|
||
public RemoveMethodDeclarationVisitor(String pattern) { | ||
this(new MethodMatcher(pattern)); | ||
} | ||
|
||
@Override | ||
public J visitMethodDeclaration(MethodDeclaration method, ExecutionContext executionContext) { | ||
return matcher.matches(method.getMethodType()) ? null : super.visitMethodDeclaration(method, executionContext); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
41 changes: 41 additions & 0 deletions
41
.../src/test/java/dev/morphia/rewrite/recipes/test/internal/RemoveMethodDeclarationTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package dev.morphia.rewrite.recipes.test.internal; | ||
|
||
import dev.morphia.rewrite.recipes.internal.RemoveMethodDeclaration; | ||
import dev.morphia.rewrite.recipes.test.MorphiaRewriteTest; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.junit.jupiter.api.Test; | ||
import org.openrewrite.Recipe; | ||
|
||
import static org.openrewrite.java.Assertions.java; | ||
|
||
class RemoveMethodDeclarationTest extends MorphiaRewriteTest { | ||
|
||
@Override | ||
protected @NotNull Recipe getRecipe() { | ||
RemoveMethodDeclaration declaration = new RemoveMethodDeclaration(); | ||
declaration.setMethodPattern("Test deleteMe(String)"); | ||
return declaration; | ||
} | ||
|
||
@Test | ||
public void testRemoveMethod() { | ||
rewriteRun(java(""" | ||
public class Test { | ||
public String deleteMe() { | ||
return "Not today!"; | ||
} | ||
public void deleteMe(String param) { | ||
} | ||
} | ||
""", | ||
""" | ||
public class Test { | ||
public String deleteMe() { | ||
return "Not today!"; | ||
} | ||
} | ||
""")); | ||
} | ||
} |