-
Notifications
You must be signed in to change notification settings - Fork 180
feat: add new migration recipes #2135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9b50db9
feat: add new recipe for score classes
zepfred 149aa30
feat: improve the recipe
zepfred 0debd13
feat: add more recipes
zepfred 46451ee
feat: add more recipes
zepfred 8ed35bc
feat: add more recipes
zepfred d428b82
chore: minor fix
zepfred 3695201
chore: address comments
zepfred 4eb8a00
chore: address comments
zepfred 65c7ed5
chore: formatting
zepfred File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
...migration/src/main/java/ai/timefold/solver/migration/ConstraintStreamMigrationRecipe.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package ai.timefold.solver.migration; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.openrewrite.Recipe; | ||
| import org.openrewrite.java.ChangeMethodName; | ||
|
|
||
| public class ConstraintStreamMigrationRecipe extends AbstractRecipe { | ||
| @Override | ||
| public String getDisplayName() { | ||
| return "Migrate legacy constraint stream code to the new methods"; | ||
| } | ||
|
|
||
| @Override | ||
| public String getDescription() { | ||
| return "Migrate all legacy constraint stream methods to the new methods."; | ||
| } | ||
|
|
||
| @Override | ||
| public List<Recipe> getRecipeList() { | ||
| return List.of( | ||
| new ChangeMethodName( | ||
| "ai.timefold.solver.core.api.score.stream.uni.UniConstraintStream penalizeLong(..)", | ||
| "penalize", true, false), | ||
| new ChangeMethodName( | ||
| "ai.timefold.solver.core.api.score.stream.uni.UniConstraintStream rewardLong(..)", | ||
| "reward", true, false), | ||
| new ChangeMethodName( | ||
| "ai.timefold.solver.core.api.score.stream.uni.UniConstraintStream impactLong(..)", | ||
| "impact", true, false), | ||
| new ChangeMethodName( | ||
| "ai.timefold.solver.core.api.score.stream.bi.BiConstraintStream penalizeLong(..)", | ||
| "penalize", true, false), | ||
| new ChangeMethodName( | ||
| "ai.timefold.solver.core.api.score.stream.bi.BiConstraintStream rewardLong(..)", | ||
| "reward", true, false), | ||
| new ChangeMethodName( | ||
| "ai.timefold.solver.core.api.score.stream.bi.BiConstraintStream impactLong(..)", | ||
| "impact", true, false), | ||
| new ChangeMethodName( | ||
| "ai.timefold.solver.core.api.score.stream.tri.TriConstraintStream penalizeLong(..)", | ||
| "penalize", true, false), | ||
| new ChangeMethodName( | ||
| "ai.timefold.solver.core.api.score.stream.tri.TriConstraintStream rewardLong(..)", | ||
| "reward", true, false), | ||
| new ChangeMethodName( | ||
| "ai.timefold.solver.core.api.score.stream.tri.TriConstraintStream impactLong(..)", | ||
| "impact", true, false), | ||
| new ChangeMethodName( | ||
| "ai.timefold.solver.core.api.score.stream.quad.QuadConstraintStream penalizeLong(..)", | ||
| "penalize", true, false), | ||
| new ChangeMethodName( | ||
| "ai.timefold.solver.core.api.score.stream.quad.QuadConstraintStream rewardLong(..)", | ||
| "reward", true, false), | ||
| new ChangeMethodName( | ||
| "ai.timefold.solver.core.api.score.stream.quad.QuadConstraintStream impactLong(..)", | ||
| "impact", true, false)); | ||
| } | ||
| } |
58 changes: 58 additions & 0 deletions
58
...igration/src/main/java/ai/timefold/solver/migration/GeneralChangeTypeMigrationRecipe.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package ai.timefold.solver.migration; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.openrewrite.Recipe; | ||
| import org.openrewrite.java.ChangeType; | ||
|
|
||
| public class GeneralChangeTypeMigrationRecipe extends AbstractRecipe { | ||
| @Override | ||
| public String getDisplayName() { | ||
| return "Migrate legacy code to the new class structure"; | ||
| } | ||
|
|
||
| @Override | ||
| public String getDescription() { | ||
| return "Migrate all legacy classes to the new class structure."; | ||
| } | ||
|
|
||
| @Override | ||
| public List<Recipe> getRecipeList() { | ||
| return List.of( | ||
| // Planning Id | ||
| new ChangeType("ai.timefold.solver.core.api.domain.lookup.PlanningId", | ||
| "ai.timefold.solver.core.api.domain.common.PlanningId", true), | ||
| // Score classes | ||
| new ChangeType("ai.timefold.solver.core.api.score.buildin.simple.SimpleScore", | ||
| "ai.timefold.solver.core.api.score.SimpleScore", true), | ||
| new ChangeType("ai.timefold.solver.core.api.score.buildin.simplelong.SimpleLongScore", | ||
| "ai.timefold.solver.core.api.score.SimpleScore", true), | ||
| new ChangeType("ai.timefold.solver.core.api.score.buildin.simplebigdecimal.SimpleBigDecimalScore", | ||
| "ai.timefold.solver.core.api.score.SimpleBigDecimalScore", true), | ||
|
|
||
| new ChangeType("ai.timefold.solver.core.api.score.buildin.hardsoft.HardSoftScore", | ||
| "ai.timefold.solver.core.api.score.HardSoftScore", true), | ||
| new ChangeType("ai.timefold.solver.core.api.score.buildin.hardsoftlong.HardSoftLongScore", | ||
| "ai.timefold.solver.core.api.score.HardSoftScore", true), | ||
| new ChangeType("ai.timefold.solver.core.api.score.buildin.hardsoftbigdecimal.HardSoftBigDecimalScore", | ||
| "ai.timefold.solver.core.api.score.HardSoftBigDecimalScore", true), | ||
|
|
||
| new ChangeType("ai.timefold.solver.core.api.score.buildin.hardmediumsoft.HardMediumSoftScore", | ||
| "ai.timefold.solver.core.api.score.HardMediumSoftScore", true), | ||
| new ChangeType("ai.timefold.solver.core.api.score.buildin.hardmediumsoftlong.HardMediumSoftLongScore", | ||
| "ai.timefold.solver.core.api.score.HardMediumSoftScore", true), | ||
| new ChangeType( | ||
| "ai.timefold.solver.core.api.score.buildin.hardmediumsoftbigdecimal.HardMediumSoftBigDecimalScore", | ||
| "ai.timefold.solver.core.api.score.HardMediumSoftBigDecimalScore", true), | ||
|
|
||
| new ChangeType("ai.timefold.solver.core.api.score.buildin.bendable.BendableScore", | ||
| "ai.timefold.solver.core.api.score.BendableScore", true), | ||
| new ChangeType("ai.timefold.solver.core.api.score.buildin.bendablelong.BendableLongScore", | ||
| "ai.timefold.solver.core.api.score.BendableScore", true), | ||
| new ChangeType("ai.timefold.solver.core.api.score.buildin.bendablebigdecimal.BendableBigDecimalScore", | ||
| "ai.timefold.solver.core.api.score.BendableBigDecimalScore", true), | ||
| // Problem fact | ||
| new ChangeType("ai.timefold.solver.core.api.solver.ProblemFactChange", | ||
| "ai.timefold.solver.core.api.solver.change.ProblemChange", true)); | ||
| } | ||
| } | ||
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
153 changes: 153 additions & 0 deletions
153
...ation/src/test/java/ai/timefold/solver/migration/ConstraintStreamMigrationRecipeTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| package ai.timefold.solver.migration; | ||
|
|
||
| import static org.openrewrite.java.Assertions.java; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.parallel.Execution; | ||
| import org.junit.jupiter.api.parallel.ExecutionMode; | ||
| import org.openrewrite.java.JavaParser; | ||
| import org.openrewrite.java.search.FindMissingTypes; | ||
| import org.openrewrite.test.RecipeSpec; | ||
| import org.openrewrite.test.RewriteTest; | ||
|
|
||
| @Execution(ExecutionMode.CONCURRENT) | ||
| class ConstraintStreamMigrationRecipeTest implements RewriteTest { | ||
|
|
||
| @Override | ||
| public void defaults(RecipeSpec spec) { | ||
| spec.recipes(new FindMissingTypes(false), new ConstraintStreamMigrationRecipe()) | ||
| .parser(JavaParser.fromJavaVersion() | ||
| // We must add all old classes as stubs to the JavaTemplate | ||
| .dependsOn( | ||
| """ | ||
| package ai.timefold.solver.core.api.score.stream.uni; | ||
|
|
||
| import java.util.function.ToLongFunction; | ||
|
|
||
| public class UniConstraintStream { | ||
| public void penalizeLong(Object constraintWeight) {} | ||
| public void penalizeLong(Object constraintWeight, ToLongFunction matchWeigher) {} | ||
| public void rewardLong(Object constraintWeight) {} | ||
| public void rewardLong(Object constraintWeight, ToLongFunction matchWeigher) {} | ||
| public void impactLong(Object constraintWeight) {} | ||
| public void impactLong(Object constraintWeight, ToLongFunction matchWeigher) {} | ||
| }""", | ||
| """ | ||
| package ai.timefold.solver.core.api.score.stream.bi; | ||
|
|
||
| import java.util.function.ToLongFunction; | ||
|
|
||
| public class BiConstraintStream { | ||
| public void penalizeLong(Object constraintWeight) {} | ||
| public void penalizeLong(Object constraintWeight, ToLongFunction matchWeigher) {} | ||
| public void rewardLong(Object constraintWeight) {} | ||
| public void rewardLong(Object constraintWeight, ToLongFunction matchWeigher) {} | ||
| public void impactLong(Object constraintWeight) {} | ||
| public void impactLong(Object constraintWeight, ToLongFunction matchWeigher) {} | ||
| }""", | ||
| """ | ||
| package ai.timefold.solver.core.api.score.stream.tri; | ||
|
|
||
| import java.util.function.ToLongFunction; | ||
|
|
||
| public class TriConstraintStream { | ||
| public void penalizeLong(Object constraintWeight) {} | ||
| public void penalizeLong(Object constraintWeight, ToLongFunction matchWeigher) {} | ||
| public void rewardLong(Object constraintWeight) {} | ||
| public void rewardLong(Object constraintWeight, ToLongFunction matchWeigher) {} | ||
| public void impactLong(Object constraintWeight) {} | ||
| public void impactLong(Object constraintWeight, ToLongFunction matchWeigher) {} | ||
| }""", | ||
| """ | ||
| package ai.timefold.solver.core.api.score.stream.quad; | ||
|
|
||
| import java.util.function.ToLongFunction; | ||
|
|
||
| public class QuadConstraintStream { | ||
| public void penalizeLong(Object constraintWeight) {} | ||
| public void penalizeLong(Object constraintWeight, ToLongFunction matchWeigher) {} | ||
| public void rewardLong(Object constraintWeight) {} | ||
| public void rewardLong(Object constraintWeight, ToLongFunction matchWeigher) {} | ||
| public void impactLong(Object constraintWeight) {} | ||
| public void impactLong(Object constraintWeight, ToLongFunction matchWeigher) {} | ||
| }""")); | ||
| } | ||
|
|
||
| @Test | ||
| void migrate() { | ||
| rewriteRun(java( | ||
| """ | ||
| package timefold; | ||
|
|
||
| import ai.timefold.solver.core.api.score.stream.uni.UniConstraintStream; | ||
| import ai.timefold.solver.core.api.score.stream.bi.BiConstraintStream; | ||
| import ai.timefold.solver.core.api.score.stream.tri.TriConstraintStream; | ||
| import ai.timefold.solver.core.api.score.stream.quad.QuadConstraintStream; | ||
|
|
||
| public class Test { | ||
| void validate(UniConstraintStream stream, BiConstraintStream stream2, TriConstraintStream stream3, QuadConstraintStream stream4) { | ||
| stream.penalizeLong(null); | ||
| stream.penalizeLong(null, null); | ||
| stream.rewardLong(null); | ||
| stream.rewardLong(null, null); | ||
| stream.impactLong(null); | ||
| stream.impactLong(null, null); | ||
| stream2.penalizeLong(null); | ||
| stream2.penalizeLong(null, null); | ||
| stream2.rewardLong(null); | ||
| stream2.rewardLong(null, null); | ||
| stream2.impactLong(null); | ||
| stream2.impactLong(null, null); | ||
| stream3.penalizeLong(null); | ||
| stream3.penalizeLong(null, null); | ||
| stream3.rewardLong(null); | ||
| stream3.rewardLong(null, null); | ||
| stream3.impactLong(null); | ||
| stream3.impactLong(null, null); | ||
| stream4.penalizeLong(null); | ||
| stream4.penalizeLong(null, null); | ||
| stream4.rewardLong(null); | ||
| stream4.rewardLong(null, null); | ||
| stream4.impactLong(null); | ||
| stream4.impactLong(null, null); | ||
| } | ||
| }""", | ||
| """ | ||
| package timefold; | ||
|
|
||
| import ai.timefold.solver.core.api.score.stream.uni.UniConstraintStream; | ||
| import ai.timefold.solver.core.api.score.stream.bi.BiConstraintStream; | ||
| import ai.timefold.solver.core.api.score.stream.tri.TriConstraintStream; | ||
| import ai.timefold.solver.core.api.score.stream.quad.QuadConstraintStream; | ||
|
|
||
| public class Test { | ||
| void validate(UniConstraintStream stream, BiConstraintStream stream2, TriConstraintStream stream3, QuadConstraintStream stream4) { | ||
| stream.penalize(null); | ||
| stream.penalize(null, null); | ||
| stream.reward(null); | ||
| stream.reward(null, null); | ||
| stream.impact(null); | ||
| stream.impact(null, null); | ||
| stream2.penalize(null); | ||
| stream2.penalize(null, null); | ||
| stream2.reward(null); | ||
| stream2.reward(null, null); | ||
| stream2.impact(null); | ||
| stream2.impact(null, null); | ||
| stream3.penalize(null); | ||
| stream3.penalize(null, null); | ||
| stream3.reward(null); | ||
| stream3.reward(null, null); | ||
| stream3.impact(null); | ||
| stream3.impact(null, null); | ||
| stream4.penalize(null); | ||
| stream4.penalize(null, null); | ||
| stream4.reward(null); | ||
| stream4.reward(null, null); | ||
| stream4.impact(null); | ||
| stream4.impact(null, null); | ||
| } | ||
| }""")); | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.