Skip to content

Commit f2bf71f

Browse files
Extract documentation examples from tests
Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.recipes.rewrite.OpenRewriteRecipeBestPractices?organizationId=QUxML09wZW4gU291cmNlL09wZW5SZXdyaXRl Co-authored-by: Moderne <team@moderne.io>
1 parent fe67c05 commit f2bf71f

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

src/main/resources/META-INF/rewrite/examples.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,73 @@ examples:
392392
language: java
393393
---
394394
type: specs.openrewrite.org/v1beta/example
395+
recipeName: org.openrewrite.java.recipes.RemoveImportBeforeAddImport
396+
examples:
397+
- description: '`RemoveImportBeforeAddImportTest#swapMaybeAddBeforeMaybeRemove`'
398+
sources:
399+
- before: |
400+
import org.openrewrite.ExecutionContext;
401+
import org.openrewrite.Recipe;
402+
import org.openrewrite.TreeVisitor;
403+
import org.openrewrite.java.JavaIsoVisitor;
404+
import org.openrewrite.java.tree.J;
405+
406+
public class SampleRecipe extends Recipe {
407+
@Override
408+
public String getDisplayName() {
409+
return "Sample";
410+
}
411+
412+
@Override
413+
public String getDescription() {
414+
return "Sample recipe.";
415+
}
416+
417+
@Override
418+
public TreeVisitor<?, ExecutionContext> getVisitor() {
419+
return new JavaIsoVisitor<ExecutionContext>() {
420+
@Override
421+
public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) {
422+
maybeAddImport("com.example.NewClass");
423+
maybeRemoveImport("com.example.OldClass");
424+
return super.visitMethodInvocation(method, ctx);
425+
}
426+
};
427+
}
428+
}
429+
after: |
430+
import org.openrewrite.ExecutionContext;
431+
import org.openrewrite.Recipe;
432+
import org.openrewrite.TreeVisitor;
433+
import org.openrewrite.java.JavaIsoVisitor;
434+
import org.openrewrite.java.tree.J;
435+
436+
public class SampleRecipe extends Recipe {
437+
@Override
438+
public String getDisplayName() {
439+
return "Sample";
440+
}
441+
442+
@Override
443+
public String getDescription() {
444+
return "Sample recipe.";
445+
}
446+
447+
@Override
448+
public TreeVisitor<?, ExecutionContext> getVisitor() {
449+
return new JavaIsoVisitor<ExecutionContext>() {
450+
@Override
451+
public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) {
452+
maybeRemoveImport("com.example.OldClass");
453+
maybeAddImport("com.example.NewClass");
454+
return super.visitMethodInvocation(method, ctx);
455+
}
456+
};
457+
}
458+
}
459+
language: java
460+
---
461+
type: specs.openrewrite.org/v1beta/example
395462
recipeName: org.openrewrite.java.recipes.ReorderTestMethods
396463
examples:
397464
- description: '`ReorderTestMethodsTest#reorderTestMethods`'

0 commit comments

Comments
 (0)