-
Notifications
You must be signed in to change notification settings - Fork 339
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 modifiers for ParenthesizedTypeTree
#3862
base: main
Are you sure you want to change the base?
Conversation
These parentheses are annoying. I am here also wondering if Kotlin requires a specific order between annotations and modifiers. As far as I can see there is no such order, so if we now add modifiers here, we will still have that problem left to solve. See https://kotlinlang.org/docs/reference/grammar.html#type. I get the impression we might need something like an |
Adding a code example: class SomeReceiver
suspend inline fun SomeReceiver . method(
body : @A1 suspend @A2 ( SomeReceiver . () -> Unit )
) {}
@Target(AnnotationTarget.TYPE)
annotation class A1
@Target(AnnotationTarget.TYPE)
annotation class A2 |
Since in PSI, those parentheses are just flattened to tokens only and the nested parentheses structures are not preserved, so building nested structures is challenging for us. I think having I think the mixed modifier and annotation in random order can be supported in the same way we used for others. For the example provided by Tracey above, class SomeReceiver
suspend inline fun SomeReceiver . method(
body : @A1 suspend @A2 ( SomeReceiver . () -> Unit )
) {} Models
|
Yes, I forgot that our modifiers can also have annotations. But the annotations on modifiers are leading annotations (despite the field being declared as the last field) and typically the pattern we have is: List<Annotation> leadingAnnotations;
List<Modifier> modifiers;
OtherTypeWithAnnotations other; While our field is called |
Yes, annotations on modifiers are leading annotations, and they are supposed to be stored in modifiers, agree that moving |
To clarify, class Foo {
List<Annotation> leadingAnnotations;
List<Modifier> modifiers;
OtherTypeWithAnnotations other;
} The modeling that Knut linked shows that we represent leading annotations as a separate field before modifiers. Then have a list of modifiers, since annotations may exist between modifiers. Example: @LeadingAnnotation private @AnnotationOnModifier static foo() {}` ; In terms of modeling, fields are declared in the order they are parsed, which is what lead to the confusion. This case is odd, since there may be annotations following the modifiers without a container in the model to add the annotations to: body : @A1 suspend @A2 ( SomeReceiver . () -> Unit )`. In this case, we would either: List<Annotation> leadingAnnotations
List<Modifier> modifiers
List<Annotation> otherAnnotations or List<Modifier> modifiers
List<Annotation> annotations |
I didn't see any contradiction here, we are referring to the 2nd option,
so |
This is to support cases like openrewrite/rewrite-kotlin#571 which has modifiers before redundant parens, and we present redundant paren to a
ParenthesizedTypeTree
, so addingmodifiers
toParenthesizedTypeTree
in this PR.An example