Skip to content
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

Recipe for replacing StringUtils#isBlank(CharSequence) and StringUtils#isNotBlank(CharSequence) #7

Open
DevDavido opened this issue Mar 15, 2024 · 1 comment
Labels

Comments

@DevDavido
Copy link

What problem are you trying to solve?

Similar to the recipe which replaces the StringUtils#isEmpty(String) and StringUtils#isNotEmpty(String) [1], a recipe would be helpful which replaces StringUtils#isBlank(CharSequence) and StringUtils#isNotBlank(CharSequence) with its plain Java equivalent too.

What precondition(s) should be checked before applying this recipe?

At least Java 11 is required due to the availability of java.lang.String#isBlank().

Describe the situation before applying the recipe

class A {
    void foo(String bar) {
        boolean isBlankBar = StringUtils.isBlank(bar);
        boolean isNotBlankBar = StringUtils.isNotBlank(bar);
    }
}

Describe the situation after applying the recipe

class A {
    void foo(String bar) {
        boolean isBlankBar = (bar == null || bar.isBlank());
        boolean isNotBlankBar = (bar != null && !bar.isBlank());
    }
}
@timtebeek
Copy link
Contributor

Good suggestion indeed @DevDavido ; The Java 11 requirement might be tricky to work around; we have the same issue in this PR

Might be worth following that one as well as any fix there would unlock this one as well.

@timtebeek timtebeek moved this to Recipes Wanted in OpenRewrite Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Recipes Wanted
Development

No branches or pull requests

2 participants