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

Feature/3156 lombok utility class #3306

Closed

Conversation

coiouhkc
Copy link

@coiouhkc coiouhkc commented Jun 11, 2023

What's changed?

What's your motivation?

Closes openrewrite/rewrite-migrate-java#512

Anything in particular you'd like reviewers to focus on?

Anyone you would like to review specifically?

Have you considered any alternatives or workarounds?

Any additional context

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)

@coiouhkc
Copy link
Author

WIP (sommer camp) together with @lukas-poos-openvalue

@timtebeek timtebeek added the recipe Requested Recipe label Jun 12, 2023

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
return new ChangeVisitor();
Copy link
Contributor

Choose a reason for hiding this comment

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

You could look at using Precondition.check here to first verify that a class is a utility class candidate, before applying the visitor that adds the annotation.

@timtebeek
Copy link
Contributor

Looking good already; thanks for getting started on this! Since you still have TODO items in the code I only posted some quick suggestions. Let me know when you'd like a more thorough review.

@kunli2
Copy link
Contributor

kunli2 commented Jun 21, 2023

nice work! looks good to me besides a few comments from Tim and todo items.

Comment on lines +32 to +39
@Nested
class ShouldApplyLombokUtility implements RewriteTest {

@Test
void givenOneStaticMethod() {
rewriteRun(
recipeSpec -> recipeSpec.recipe(new LombokUtilityClass()),
java(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest to

  1. override defaults to define the recipe only once; spec.recipe(Recipe) calls can be removed from all other tests too
  2. nested classes don't have a to also implement RewriteTest
Suggested change
@Nested
class ShouldApplyLombokUtility implements RewriteTest {
@Test
void givenOneStaticMethod() {
rewriteRun(
recipeSpec -> recipeSpec.recipe(new LombokUtilityClass()),
java(
@Override
public void defaults(RecipeSpec spec) {
spec.recipe(new LombokUtilityClass());
}
@Nested
class ShouldApplyLombokUtility {
@Test
void givenOneStaticMethod() {
rewriteRun(
java(

Comment on lines +30 to +44
* TODO: Check the following criteria:
* - Lombok in dependencies +
* - All methods of class are static +
* - No instances of given class +
* - All static attributes are final +
* <p>
* TODO: Perform the transformation:
* - Add the annotation +
* - Remove static from all attributes and methods +
* <p>
* TODO: Features to consider:
* - Transformation: Add Lombok config if not present + supported configuration options for utility class
* - Transformation: Replace instantiation with static calls to methods --> na
* - Anonymous classes ???
* - Reflection ???
Copy link
Contributor

Choose a reason for hiding this comment

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

These comments and the failing test give me pause in reviewing this further; could you tell us your plans on these?

* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openrewrite.java;
Copy link
Collaborator

@JLLeitschuh JLLeitschuh Jan 25, 2024

Choose a reason for hiding this comment

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

Suggested change
package org.openrewrite.java;
package org.openrewrite.java.lombok;

Put this in a lombok sub package? Maybe? @timtebeek thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

It might fit in best with https://github.com/openrewrite/rewrite-migrate-java/tree/main/src/main/java/org/openrewrite/java/migrate/lombok , since we've rearchitectured openrewrite/rewrite a bit to have less recipes in there, and more in specific modules

@timtebeek
Copy link
Contributor

As indicated I suggest we move this over to the lombok package on rewrite-migrate-java. I didn't want to just copy over the content here, as we use Git history to give credit to our contributors. Would you mind opening a PR there @coiouhkc ?

@blipper
Copy link
Contributor

blipper commented Oct 10, 2024

I am a big confused on the state here?

@timtebeek
Copy link
Contributor

I am a big confused on the state here?

This PR was opened against openrewrite/rewrite, but is a better fit for openrewrite/rewrite-migrate-java, given that we already have a few other Lombok recipes there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
recipe Requested Recipe
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Auto Lombok @UtilityClass
6 participants