Closed peterphan closed 1 year ago
Note that doing bytecode analysis of the classpath represents a substantial engineering effort, unlikely to come to fruition anytime soon. But it would be neat, I agree.
Cross-posting from internal discussion: Another option would be to use reflection where possible. For the example above, if we cannot resolve the constant in any of the current source files, we could load the classpath into a ClassLoader and use reflection to find the appropriate class and its constants e.g. like this.
This approach is very specific to the example use-case, and may not scale to broader use-cases so might not belong in OpenRewrite itself, but it may be a useful workaround for users.
This may be a feature we can explore much further down the road when the SaaS supports multi-repository recipes. It is unlikely that work will be done on this in the near term.
Use Case
We use an internal experimentation platform for A/B testing that often has code like
We want to create a recipe to automatically clean up stale experiments, so being able to refactor the code such that it becomes
Problem
In order to do this, we need to be able to detect that the treatment/experiment key being passed in is exactly
my_experiment_key
. This could be a string literal, which is easy to handle, however, if it's a constant that is defined in an external dependency through theclasspath
. E.g.then we currently have no means to resolve this value.