-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support nested classes with static inner classes (#13)
Fixes #12
- Loading branch information
Showing
9 changed files
with
87 additions
and
15 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
18 changes: 18 additions & 0 deletions
18
src/test/resources/recipes/ShouldSupportNestedClasses.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,18 @@ | ||
package foo; | ||
|
||
import com.google.errorprone.refaster.annotation.AfterTemplate; | ||
import com.google.errorprone.refaster.annotation.BeforeTemplate; | ||
|
||
public class ShouldSupportNestedClasses { | ||
public static class NestedClass { | ||
@BeforeTemplate | ||
boolean before(String s) { | ||
return s.length() > 0; | ||
} | ||
|
||
@AfterTemplate | ||
boolean after(String s) { | ||
return !s.isEmpty(); | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/test/resources/recipes/ShouldSupportNestedClassesRecipes.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,43 @@ | ||
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 ShouldSupportNestedClassesRecipes { | ||
public static final class NestedClassRecipe extends Recipe { | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Refaster template `ShouldSupportNestedClasses.NestedClass`"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Recipe created for the following Refaster template:\n```java\npublic static class NestedClass {\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); | ||
} | ||
|
||
}; | ||
} | ||
} | ||
|
||
} |
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