-
Notifications
You must be signed in to change notification settings - Fork 364
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
Trait
interface and VariableAccess
/MethodAccess
implementation
#4309
Conversation
rewrite-core/src/main/java/org/openrewrite/trait/SimpleTraitMatcher.java
Show resolved
Hide resolved
rewrite-java/src/test/java/org/openrewrite/java/trait/VariableAccessTest.java
Outdated
Show resolved
Hide resolved
…tcher.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…AccessTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
rewrite-core/src/main/java/org/openrewrite/trait/TraitMatcher.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/trait/VariableAccess.java
Show resolved
Hide resolved
import static org.openrewrite.test.RewriteTest.toRecipe; | ||
|
||
@SuppressWarnings("ALL") | ||
class VariableAccessTest implements RewriteTest { |
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.
Do you want to add a test for the this
and super
cases?
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.
More tests are certainly warranted, but expensive in time to create. Wanted to do a quick check on whether or not this approach was even close to reasonable.
Very interesting to see this. I'm curious to see other cases too! |
Have you thought about tree navigation as well? |
I think the model you have in VarAccess is quite good. I don't see any reason why we can't build var access -> var declaration as either behavior or state of either. |
rewrite-java/src/test/java/org/openrewrite/java/trait/MethodAccessTest.java
Outdated
Show resolved
Hide resolved
…cessTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.
First part of a review before calls & heading out. Mostly smaller items and not on the big design, but good to clear out before a merge.
rewrite-core/src/main/java/org/openrewrite/trait/VisitFunction3.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/test/java/org/openrewrite/java/trait/VariableAccessTest.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/test/java/org/openrewrite/java/trait/VariableAccessTest.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/trait/MethodAccess.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/trait/VariableAccess.java
Outdated
Show resolved
Hide resolved
…AccessTest.java Co-authored-by: Tim te Beek <[email protected]>
…AccessTest.java Co-authored-by: Tim te Beek <[email protected]>
…cess.java Co-authored-by: Tim te Beek <[email protected]>
Trait
interface and VariableAccess
/MethodAccess
implementation
What's changed?
Introduces a
Trait
API into OpenRewrite which encapsulates semantic information on top of syntax.What's your motivation?
We had an initial implementation of
Trait
in rewrite-analysis written by @JLLeitschuh that really did a lot to help understand the shape of what is needed.In this implementation, we've removed the dependency on functionaljava, reasoning that this dependency would be too steep of a learning curve for the average user. One of the key benefits of functionaljava was in support of Jonathan's enhanced
Validation
type which has also been removed here. I thinkValidation
was mostly useful in the development of the trait, and where possible traits should build on other traits so that the logic of each is fairly comprehensible.We are also adding some API, in particular take note of how
Trait
can be turned into a visitor. Check out the test for how that is used. I'm imagining a future where many recipes would start out with a Trait that quickly hones the recipe in on a point of interest in the code.Example 1 (use the
higher
method to assert something about a tree's ancestors)Example 2 (turn the trait into a visitor)
This is the same recipe as above, implemented differently.