Modifying code only on certain variable values. #5620
Replies: 3 comments 7 replies
-
|
We have something similar in rewrite-analysis, which is perhaps best illustrated with the example here:
Note that it's not an exact match with your use case, nor do I know if it'll support the get method indirection you have, but it's worth exploring for your use. |
Beta Was this translation helpful? Give feedback.
-
|
I would like to add field initializer values to the JavaType model for static final fields where the value can be evaluated at compile time (primitive types, enums, and strings). But it will probably be a while until I get to this. |
Beta Was this translation helpful? Give feedback.
-
|
Going to close this. We very much limited our use-cases and used a hacky-ish, static variable in the recipe. @timtebeek has pointed us to a new dataflow package, and we'll look into that next time we have needs similar to this. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I need to change
foo(someString)tobar(someString)ifsomeStringis known to be numeric at compile time. Seems easy to do, at least in some cases, ifsomeStringcomes from a literal contained within SourceFile. Even if it resolves to a constant or an enum in other files, this seems doable, but significantly more complex, via a Scanning recipe creating some kind of map of literals or something. But I'm betting this will get really complicated if there are layers of indirection spread across the entire project, e.g.There is nothing like
evaluateIfCan(MethodInvocation)is there? Where I could do something like:If
evaluateIfCanfunctionality exists in OpenRewrite's Java support, I'm missing it:).Update: I created this rewrite-analysis issue.
Beta Was this translation helpful? Give feedback.
All reactions