-
Notifications
You must be signed in to change notification settings - Fork 89
Add FluentSetterRecipe #646
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
base: main
Are you sure you want to change the base?
Conversation
src/main/java/org/openrewrite/staticanalysis/FluentSetterRecipe.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/FluentSetterRecipe.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/FluentSetterRecipe.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/FluentSetterRecipe.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/FluentSetterRecipeTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/FluentSetterRecipeTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation and inner classes look fine.
Having seen your run
example, for both the default mode and the includeAllVoidMethods
as well - I think a check should be added whether the method is not an override of some super method. In this case, I think it's probably wrong to change the return type. And now, I am not sure how feasible this check would be in all cases. Wdyt?
…-analysis into fluent-setter-recipe
Thanks for the review @greg-at-moderne - that's good point, I will have a look. |
Sorry for the delay, I didn't have much time lately.
In this situation, I see two options:
|
Thanks both! Wondering a bit indeed how we can make this safe; we don't immediately have a way to know if a method might be overridden, unless we use a ScanningRecipe, and even then we might miss cases where it's a library. Perhaps the safe thing to do would be to limit this to either the provided method pattern (opt in), or We can optionally and separately expand FinalClass to make it a scanning recipe that adds that modifier to any classes not extended, that way the combination of these two recipes would achieve the safe results we're after. |
Thanks for the feedback @timtebeek, that's good suggestion. I've updated the recipe, now by default it converts methods only in final classes. When the pattern is provided, it converts methods in any class. Your idea about expanding |
What's changed?
Added new
FluentSetterRecipe
to convert void setter methods (and optionally other void methods) into fluent-style methods that returnthis
.What's your motivation?
this
to allow for fluent interfaces #623Anything in particular you'd like reviewers to focus on?
return this;
statement.Inner
instead ofOuter.Inner
)Checklist