|
32 | 32 | import static org.openrewrite.Validated.invalid; |
33 | 33 |
|
34 | 34 | @RequiredArgsConstructor |
35 | | -public class DeclarativeRecipe extends ScanningRecipe<DeclarativeRecipe.Accumulator> { |
| 35 | +public class DeclarativeRecipe extends ScanningRecipe<DeclarativeRecipe.Accumulator> implements RecipePreconditions { |
36 | 36 | @Getter |
37 | 37 | private final String name; |
38 | 38 |
|
@@ -187,7 +187,6 @@ private void registerNestedScanningRecipes(Recipe recipe, Accumulator acc, Execu |
187 | 187 | @Override |
188 | 188 | public TreeVisitor<?, ExecutionContext> getScanner(Accumulator acc) { |
189 | 189 | return new TreeVisitor<Tree, ExecutionContext>() { |
190 | | - @SuppressWarnings({"rawtypes", "unchecked"}) |
191 | 190 | @Override |
192 | 191 | public @Nullable Tree visit(@Nullable Tree tree, ExecutionContext ctx) { |
193 | 192 | for (Recipe precondition : preconditions) { |
@@ -251,7 +250,7 @@ public boolean isAcceptable(SourceFile sourceFile, ExecutionContext ctx) { |
251 | 250 |
|
252 | 251 | @EqualsAndHashCode(callSuper = false) |
253 | 252 | @Value |
254 | | - static class BellwetherDecoratedRecipe extends Recipe implements DelegatingRecipe { |
| 253 | + static class BellwetherDecoratedRecipe extends Recipe implements DelegatingRecipe, RecipePreconditions { |
255 | 254 |
|
256 | 255 | DeclarativeRecipe.PreconditionBellwether bellwether; |
257 | 256 | Recipe delegate; |
@@ -350,11 +349,19 @@ public Validated<Object> validate(ExecutionContext ctx) { |
350 | 349 | public Collection<Validated<Object>> validateAll(ExecutionContext ctx, Collection<Validated<Object>> acc) { |
351 | 350 | return delegate.validateAll(ctx, acc); |
352 | 351 | } |
| 352 | + |
| 353 | + @Override |
| 354 | + public List<Recipe> getPreconditions() { |
| 355 | + if (delegate instanceof RecipePreconditions) { |
| 356 | + return ((RecipePreconditions) delegate).getPreconditions(); |
| 357 | + } |
| 358 | + return emptyList(); |
| 359 | + } |
353 | 360 | } |
354 | 361 |
|
355 | 362 | @Value |
356 | 363 | @EqualsAndHashCode(callSuper = false) |
357 | | - static class BellwetherDecoratedScanningRecipe<T> extends ScanningRecipe<T> implements DelegatingRecipe { |
| 364 | + static class BellwetherDecoratedScanningRecipe<T> extends ScanningRecipe<T> implements DelegatingRecipe, RecipePreconditions { |
358 | 365 |
|
359 | 366 | DeclarativeRecipe.PreconditionBellwether bellwether; |
360 | 367 | ScanningRecipe<T> delegate; |
@@ -468,6 +475,14 @@ public Validated<Object> validate(ExecutionContext ctx) { |
468 | 475 | public Collection<Validated<Object>> validateAll(ExecutionContext ctx, Collection<Validated<Object>> acc) { |
469 | 476 | return delegate.validateAll(ctx, acc); |
470 | 477 | } |
| 478 | + |
| 479 | + @Override |
| 480 | + public List<Recipe> getPreconditions() { |
| 481 | + if (delegate instanceof RecipePreconditions) { |
| 482 | + return ((RecipePreconditions) delegate).getPreconditions(); |
| 483 | + } |
| 484 | + return emptyList(); |
| 485 | + } |
471 | 486 | } |
472 | 487 |
|
473 | 488 | @Override |
@@ -589,13 +604,17 @@ private static class LazyLoadedRecipe extends Recipe { |
589 | 604 |
|
590 | 605 | @Override |
591 | 606 | protected RecipeDescriptor createRecipeDescriptor() { |
592 | | - List<RecipeDescriptor> recipeList = new ArrayList<>(); |
593 | | - for (Recipe childRecipe : this.recipeList) { |
594 | | - recipeList.add(childRecipe.getDescriptor()); |
| 607 | + List<RecipeDescriptor> preconditionDescriptors = new ArrayList<>(); |
| 608 | + for (Recipe childRecipe : preconditions) { |
| 609 | + preconditionDescriptors.add(childRecipe.getDescriptor()); |
| 610 | + } |
| 611 | + List<RecipeDescriptor> recipeDescriptors = new ArrayList<>(); |
| 612 | + for (Recipe childRecipe : recipeList) { |
| 613 | + recipeDescriptors.add(childRecipe.getDescriptor()); |
595 | 614 | } |
596 | 615 | return new RecipeDescriptor(getName(), getDisplayName(), getInstanceName(), getDescription() != null ? getDescription() : "", |
597 | 616 | getTags(), getEstimatedEffortPerOccurrence(), |
598 | | - emptyList(), recipeList, getDataTableDescriptors(), getMaintainers(), getContributors(), |
| 617 | + emptyList(), preconditionDescriptors, recipeDescriptors, getDataTableDescriptors(), getMaintainers(), getContributors(), |
599 | 618 | getExamples(), source); |
600 | 619 | } |
601 | 620 |
|
|
0 commit comments