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

Add Apache Commons StringUtils refaster template replacements #271

Merged
merged 44 commits into from
Aug 18, 2023

Conversation

AlekSimpson
Copy link
Contributor

@AlekSimpson AlekSimpson commented Aug 11, 2023

What's changed?

Refaster rule recipes to replace Apache Commons StringUtils methods with JDK internals where possible.

What's your motivation?

Fixes #267

Anyone you would like to review specifically?

@timtebeek

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've added the license header to any new files through ./gradlew licenseFormat
  • I've used the IntelliJ auto-formatter on affected files
  • I've updated the documentation (if applicable)

Copy link
Contributor

@knutwannheden knutwannheden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a first set of review comments.

@timtebeek timtebeek self-requested a review August 11, 2023 22:15
@timtebeek timtebeek changed the base branch from main to apache_commons_string_utils_refaster_templates August 11, 2023 22:30
…/ApacheCommonsStringUtils.java

Co-authored-by: Tim te Beek <tim@moderne.io>
@timtebeek timtebeek added the recipe Recipe requested label Aug 14, 2023
@AlekSimpson
Copy link
Contributor Author

Ok the latest commit has all the changes made based off of the feedback given.

@AlekSimpson
Copy link
Contributor Author

I am still seeing errors when I run the tests. It tells me that an enclosing instance that contains org.openrewrite.java.migrate.apache.commons.lang.ApacheCommonsStringUtilsRecipes.DefaultStringRecipe is required. I'm not to sure what that error is saying to be honest.

@knutwannheden
Copy link
Contributor

I am still seeing errors when I run the tests. It tells me that an enclosing instance that contains org.openrewrite.java.migrate.apache.commons.lang.ApacheCommonsStringUtilsRecipes.DefaultStringRecipe is required. I'm not to sure what that error is saying to be honest.

You probably need to declare the Refaster template classes as static.

@AlekSimpson
Copy link
Contributor Author

I have made them all static. I think the issue could be because I have the a local version of rewrite-templating to get some fixes earlier so I could make some progress while I waited for the fixes to make it to the main branch.

@knutwannheden
Copy link
Contributor

Meanwhile quite a few fixes have been integrated. I suggest you try with the latest integration build.

@timtebeek timtebeek marked this pull request as draft August 14, 2023 16:20
@timtebeek
Copy link
Contributor

We need a merge of this one to fix the parentheses cases:


class Foo {
void test(String s) {
String test = StringUtils.strip(bar()).toString();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@knutwannheden A more interesting failure: here I would not want to make a change when the input is a method call itself; I suspect that's harder to fix quickly; would this need changes to JavaTemplateSemanticallyEqual.matchesTemplate either in the matcher, or in the TemplateMatchResult? Curious to hear your thoughts, as I have no experience there yet.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A perhaps better troublesome case is when people pass in iterator.next(); then you definitely don't want that called twice.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timtebeek timtebeek marked this pull request as ready for review August 18, 2023 13:30
build.gradle.kts Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
recipe Recipe requested
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

StringUtils.defaultString -> Objects.toString
3 participants