-
Notifications
You must be signed in to change notification settings - Fork 362
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
Use Tree.randomId()
to construct LST elements, not UUID.randomUUID()
#3784
Conversation
Hi @TheMarvelFan , thanks for getting this started! Your current implementation is a bit too broad. We'd only want to replace these method calls when they are an argument to an LST constructor call. |
…ndomId() only when it is used as a parameter in an LST constructor.
@timtebeek |
public J.Literal visitLiteral(J.Literal literal, ExecutionContext ctx) { | ||
J.Literal l = super.visitLiteral(literal, ctx); |
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.
Instead of visitLiteral
you'll want to override visitMethodInvocation
, then use a MethodMatcher to check that it's a LST element constructor call, and if is then inspect the first argument, and if that is a call the UUID.randomUUID, then replace that first argument using ListUtils.mapFirst
. Does that help?
rewrite-java/src/test/java/org/openrewrite/java/ReplaceUUIDRandomIdTest.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/test/java/org/openrewrite/java/ReplaceUUIDRandomIdTest.java
Outdated
Show resolved
Hide resolved
Hi @timtebeek, |
Hi @timtebeek, |
rewrite-java/src/main/java/org/openrewrite/java/ReplaceUUIDRandomId.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/ReplaceUUIDRandomId.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/ReplaceUUIDRandomId.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/ReplaceUUIDRandomId.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/test/java/org/openrewrite/java/ReplaceUUIDRandomIdTest.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/ReplaceUUIDRandomId.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/test/java/org/openrewrite/java/ReplaceUUIDRandomIdTest.java
Outdated
Show resolved
Hide resolved
Hi @TheMarvelFan ! I've not had time to dive in fully here; I've applied a quick few suggestions to hopefully get the tests going, but don't expect to find time until next week to look at this again. Thanks for getting this started! Hope we can improve this and make it part of the checks that we run on every pull request. |
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.
Hi @TheMarvelFan , thank you for opening a PR! I've left some comments for consideration.
rewrite-java/src/main/java/org/openrewrite/java/ReplaceUUIDRandomId.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/ReplaceUUIDRandomId.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/ReplaceUUIDRandomId.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/ReplaceUUIDRandomId.java
Outdated
Show resolved
Hide resolved
Tree.randomId()
to construct LST elements, not UUID.randomUUID()
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.
Thanks for the initial help here @TheMarvelFan and thanks for the detailed review comments @traceyyoshima ; I've gone ahead and applied the suggestions, such that we can start to use this recipe in our automated code reviews. 🎉
Also applied it to the OpenRewrite projects just now |
Referencing Issue #3757
What's changed?
A recipe has been added to modify all references to UUID.randomUUID() to Tree.randomId(). This recipe touches only these references., and does not modify the other classes.
Checklist