Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jkschneider authored Sep 30, 2023
1 parent 4dc955c commit a5bba99
Showing 1 changed file with 0 additions and 43 deletions.
43 changes: 0 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,46 +28,3 @@ public class UseStringIsEmpty {
### Output

This results in a recipe that can be used to transform code that matches the `@BeforeTemplate` to the `@AfterTemplate`.

```java
package foo;

import org.openrewrite.ExecutionContext;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.java.JavaTemplate;
import org.openrewrite.java.JavaVisitor;
import org.openrewrite.java.template.Primitive;
import org.openrewrite.java.tree.*;

public final class UseStringIsEmptyRecipe extends Recipe {

@Override
public String getDisplayName() {
return "Refaster template `UseStringIsEmpty`";
}

@Override
public String getDescription() {
return "Recipe created for the following Refaster template:\n```java\npublic class UseStringIsEmpty {\n \n @BeforeTemplate()\n boolean before(String s) {\n return s.length() > 0;\n }\n \n @AfterTemplate()\n boolean after(String s) {\n return !s.isEmpty();\n }\n}\n```\n.";
}

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
return new JavaVisitor<ExecutionContext>() {
final JavaTemplate before = JavaTemplate.compile(this, "before", (String s) -> s.length() > 0).build();
final JavaTemplate after = JavaTemplate.compile(this, "after", (String s) -> !s.isEmpty()).build();

@Override
public J visitBinary(J.Binary elem, ExecutionContext ctx) {
JavaTemplate.Matcher matcher;
if ((matcher = before.matcher(getCursor())).find()) {
return after.apply(getCursor(), elem.getCoordinates().replace(), matcher.parameter(0));
}
return super.visitBinary(elem, ctx);
}

};
}
}
```

0 comments on commit a5bba99

Please sign in to comment.