-
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.
Merge branch 'master' into tylerbertrand/develocity-local-cache
- Loading branch information
Showing
16 changed files
with
300 additions
and
96 deletions.
There are no files selected for viewing
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
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
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
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
55 changes: 55 additions & 0 deletions
55
rewrite/src/main/java/dev/morphia/rewrite/recipes/PipelineRewriteStage2.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; | ||
|
||
import java.util.ArrayList; | ||
|
||
import org.openrewrite.ExecutionContext; | ||
import org.openrewrite.Preconditions; | ||
import org.openrewrite.Recipe; | ||
import org.openrewrite.TreeVisitor; | ||
import org.openrewrite.java.JavaIsoVisitor; | ||
import org.openrewrite.java.MethodMatcher; | ||
import org.openrewrite.java.search.UsesMethod; | ||
import org.openrewrite.java.tree.J.MethodInvocation; | ||
|
||
public class PipelineRewriteStage2 extends Recipe { | ||
|
||
private static final String AGGREGATION = "dev.morphia.aggregation.Aggregation"; | ||
|
||
private static final MethodMatcher PIPELINE = new MethodMatcher(PipelineRewriteStage2.AGGREGATION + " pipeline(..)"); | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Aggregation pipeline rewrite"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Rewrites an aggregation from using stage-named methods to using pipeline(Stage...)."; | ||
} | ||
|
||
@Override | ||
public TreeVisitor<?, ExecutionContext> getVisitor() { | ||
return Preconditions.check(new UsesMethod<>(PIPELINE), new JavaIsoVisitor<>() { | ||
|
||
public MethodInvocation visitMethodInvocation(MethodInvocation method, ExecutionContext ignored) { | ||
if (!PIPELINE.matches(method.getSelect())) { | ||
return method; | ||
} | ||
|
||
var updated = method; | ||
while (PIPELINE.matches(updated.getSelect()) && PIPELINE.matches(((MethodInvocation) updated.getSelect()).getSelect())) { | ||
var select = updated.getSelect(); | ||
MethodInvocation invocation = (MethodInvocation) select; | ||
if (PIPELINE.matches(invocation.getSelect())) { | ||
MethodInvocation parent = (MethodInvocation) invocation.getSelect(); | ||
var args = new ArrayList<>(parent.getArguments()); | ||
args.addAll(invocation.getArguments()); | ||
updated = updated.withSelect(((MethodInvocation) invocation.getSelect()).withArguments(args)); | ||
} | ||
} | ||
return updated; | ||
} | ||
|
||
}); | ||
} | ||
} |
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
4 changes: 4 additions & 0 deletions
4
rewrite/src/test/java/dev/morphia/rewrite/recipes/test/Morphia2RewriteTest.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,4 @@ | ||
package dev.morphia.rewrite.recipes.test; | ||
|
||
public abstract class Morphia2RewriteTest extends MorphiaRewriteTest { | ||
} |
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
6 changes: 3 additions & 3 deletions
6
...ite/recipes/test/PipelineRewriteTest.java → ...cipes/test/PipelineRewriteStage1Test.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
Oops, something went wrong.