-
Notifications
You must be signed in to change notification settings - Fork 354
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
Add annotation element values to type attribution model #4746
base: main
Are you sure you want to change the base?
Add annotation element values to type attribution model #4746
Conversation
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.
Great to see already; some very minor feedback as a first pass through; I like how you've taken care to minimize your changes and immediately roll them out across the various parsers.
rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17TypeMapping.java
Outdated
Show resolved
Hide resolved
rewrite-java-21/src/main/java/org/openrewrite/java/isolated/ReloadableJava21TypeMapping.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/tree/JavaType.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Tim te Beek <timtebeek@gmail.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.
Looking very good already! I have quite a few use cases in mind for this, actually. I think we have some issues I can link to this PR (I will try to dig them out).
I added some review comments and also took the liberty to push a commit to the PR to store the "actual" annotation values, rather than a stringified representation of them, as I suspect that could make them a lot more useful. This work definitely isn't complete yet. Also, feel free to revert if you disagree.
rewrite-java/src/main/java/org/openrewrite/java/tree/JavaType.java
Outdated
Show resolved
Hide resolved
rewrite-java/src/main/java/org/openrewrite/java/tree/JavaType.java
Outdated
Show resolved
Hide resolved
rewrite-java-21/src/test/java/org/openrewrite/java/Java21ParserTest.java
Outdated
Show resolved
Hide resolved
rewrite-java-21/src/test/java/org/openrewrite/java/Java21ParserTest.java
Outdated
Show resolved
Hide resolved
rewrite-java-test/src/main/java/org/openrewrite/java/JavaTypeMappingTest.java
Outdated
Show resolved
Hide resolved
rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17TypeMapping.java
Show resolved
Hide resolved
…eserve_annotation_values # Conflicts: # rewrite-java/src/main/java/org/openrewrite/java/tree/JavaType.java
89436f3
to
865540c
Compare
rewrite-java-21/src/test/java/org/openrewrite/java/Java21ParserTest.java
Outdated
Show resolved
Hide resolved
rewrite-java-tck/src/main/java/org/openrewrite/java/tree/AnnotationTest.java
Outdated
Show resolved
Hide resolved
|
||
@Override | ||
public FullyQualified withFullyQualifiedName(String fullyQualifiedName) { | ||
return this; |
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.
Should this not delegate to type?
Perhaps this should delegate to a this.withType
and call type.withFullyQualifiedName
?
What's changed?
This PR adds ability to preserve annotation values parsed by JavaParsers (I updated all existing Java parser versions: 8, 11, 17, 21).
It adds a new subclass
Annotation
ofFullyQualified
inJavaType
. It delegates most functionality to annotation'sJavaType.FullyQualified
object but stores list of value attribute pairs as part of the structure inElementValue
objects (with the two implementationsSingleElementValue
andArrayElementValue
).What's your motivation?
In the recipe I'm working on I need to be able to access annotation values on the method invoked in the source file (method could be defined in a dependency in the classpath instead of being as part of the source file input).
Anything in particular you'd like reviewers to focus on?
Not sure if it is there already a model somewhere else for annotation I could use instead of defining a new subclass of FullyQualified.
Also the interface didn't change after this change. It is still returning
FullyQualified
objects when accessing annotations. I'm concerned that changing this will complicate this change but let me know if you feel differently.Anyone you would like to review specifically?
@jkschneider
@timtebeek
Have you considered any alternatives or workarounds?
I don't think there is a workaround with OpenRewrite. I worked around in my solution by loading all classes and use reflection to inspect the actual annotation values, which is a bit cumbersome.
Checklist