Closed kunli2 closed 6 months ago
@kunli2 AFAICT this will still require us to add a getSimpleName()
method to NameTree
. I will create a PR for this and then ask Jonathan for his input on that.
@kunli2 AFAICT this will still require us to add a
getSimpleName()
method toNameTree
. I will create a PR for this and then ask Jonathan for his input on that.
Turns out we don't need that quite yet after all. We had a call site in KotlinPrinter
which called J.Annotation#getSimpleName()
for all annotations: https://github.com/openrewrite/rewrite-kotlin/pull/549/commits/12f31a05ab935d5e95b89c905f60d7333d253f23. By removing that the tests now pass.
Since recipes should be allowed to call this method, we should still address this problem. In a first step we could maybe just return the empty string, if the annotation type isn't a J.Identifier
or J.FieldAccess
.
I've now gone ahead and made the changes to J.Annotation#getSimpleName()
: https://github.com/openrewrite/rewrite/commit/f7772889cb6e28427bf1ac78566fd6df45f47ba5
After discussion the design doc with the team, we decide to use option 3 to support use-site annotation instead of the
AnnotationUseSite
marker.Here are more details of option 3 Two models for single and multiple use-site included annotations, and both of them will be an
annotationType
field of theJ.Annotation
.Schema:
Use case examples:
Single annotation in bracket
Multi annotations
@[ Ann1 Ann2]
"@[ Ann1 Ann2]": J.Annotation annotationType = K.MultiAnnotationType arguments = [] "@[ Ann1 Ann2]": K.MultiAnnotationType: useSite = J.Empty annotations = [Ann1, Ann2]
to