-
Notifications
You must be signed in to change notification settings - Fork 8
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
Translate existing refactoring rules from Jackpot #6
Comments
Thanks for chiming in here @jglick ! Refaster recipesI've had a quick look at the .hint files in Jenkins, and it appears to me like quite a few of those would be a candidate for our simplified recipe definitions using the Refaster annotations. See for example UseStringIsEmpty.java: import com.google.errorprone.refaster.annotation.AfterTemplate;
import com.google.errorprone.refaster.annotation.BeforeTemplate;
public class UseStringIsEmpty {
@BeforeTemplate
boolean before(String s) {
return s.length() > 0;
}
@AfterTemplate
boolean after(String s) {
return !s.isEmpty();
}
} We allow you to write tests for such recipes as well, as seen in UseStringIsEmptyTest.java @Test
void lengthGreaterZero() {
rewriteRun(
java( // before
"""
class Test {
void m(String s) {
boolean b = s.length() > 0;
}
}
""", // after
"""
class Test {
void m(String s) {
boolean b = !s.isEmpty();
}
}
"""
)
);
} I don't think it requires a lot of creativity to see how that could serve to similarly convert for instance the use of Declarative recipesOther simpler one to one replacements can be achieved with a declarative yaml recipe only, such that you can achieve these replacements with three lines of yaml; for instance for META-INF/upgrade/JSR-305.hint
In this case, the change type recipe is likely what you need. type: specs.openrewrite.org/v1beta/recipe
name: com.yourorg.ChangeTypeExample
displayName: Change type example
recipeList:
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: javax.annotation.CheckForNull
newFullyQualifiedTypeName: edu.umd.cs.findbugs.annotations.CheckForNull
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: javax.annotation.Nonnull
newFullyQualifiedTypeName: edu.umd.cs.findbugs.annotations.NonNull
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: javax.annotation.Nullable
newFullyQualifiedTypeName: edu.umd.cs.findbugs.annotations.Nullable Hope that helps get you started! If you have any questions feel free to chime in here or on our public Slack. |
I had not seen refaster recipes before - this is great! Wanted to quickly note that the JSR-305 hint is implemented as |
Jenkins core already contains some Jackpot-based rules in the
META-INF/upgrade
pseudo-package. These are offered automatically to plugin developers using the NetBeans IDE. It would be better to delete that and create analogous rules in this repo that anyone could use.The text was updated successfully, but these errors were encountered: