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
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/FluentSetterRecipeTest.java
Show resolved
Hide resolved
greg-at-moderne
left a comment
There was a problem hiding this comment.
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 |
|
This PR is stale because it has been open for 90 days with no activity. Remove |
What's changed?
Added new
FluentSetterRecipeto convert void setter methods (and optionally other void methods) into fluent-style methods that returnthis.What's your motivation?
thisto allow for fluent interfaces #623Anything in particular you'd like reviewers to focus on?
return this;statement.Innerinstead ofOuter.Inner)Checklist