Skip to content
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

[java] ClassOrInterfaceType AST improvements #1150

Closed
oowekyala opened this issue May 27, 2018 · 1 comment
Closed

[java] ClassOrInterfaceType AST improvements #1150

oowekyala opened this issue May 27, 2018 · 1 comment
Labels
in:ast About the AST structure or API, the parsing step
Milestone

Comments

@oowekyala
Copy link
Member

oowekyala commented May 27, 2018

ClassOrInterfaceType currently has a single image for the entire type. E.g. the type Map.Entry<K,V> is parsed as

ClassOrInterfaceType "Map.Entry"
   - TypeArguments
     - TypeArgument "K"
     - TypeArgument "V"

This looks ok. Now, the invented type Foo<K>.Bar.Brew<V> is parsed as

ClassOrInterfaceType "Foo.Bar.Brew"
   - TypeArguments
     - TypeArgument "K"
   - TypeArguments
     - TypeArgument "V"

and now we don't know to which type the type arguments apply. Moreover, Java 1.8+ makes it possible to add annotations to the individual segments, such that e.g. Map.@Foo Entry<K,V> is perfectly legal. But our parser chokes on it for now (related to #997). If we are to add support for that, we'd better do it in a sensible way, such that the annotations don't end up all mixed whenever there's several of them.

I think for those reasons, we'd have interest in making ClassOrInterfaceType conform to the JLS (our ClassOrInterfaceType would be the JLS's ClassType), which would make the above examples be parsed recursively, (see examples at the end). I think this may help type resolution too.

Map.Entry<K,V>

ClassOrInterfaceType "Entry"
   - ClassOrInterfaceType "Map"
   - TypeArguments
     - TypeArgument "K"
     - TypeArgument "V"

Foo<K>.Bar.Brew<V>

ClassOrInterfaceType "Brew"
   - ClassOrInterfaceType "Bar"
      - ClassOrInterfaceType "Foo"
          - TypeArguments
             - TypeArgument "K"
   - TypeArguments
     - TypeArgument "V"

Map.@Foo Entry<K,V>

ClassOrInterfaceType "Entry"
   - ClassOrInterfaceType "Map"
   - Annotation
      - MarkerAnnotation "Foo"
   - TypeArguments
     - TypeArgument "K"
     - TypeArgument "V"
@oowekyala oowekyala added the in:ast About the AST structure or API, the parsing step label May 27, 2018
@oowekyala oowekyala added this to the 7.0.0 milestone May 27, 2018
@oowekyala
Copy link
Member Author

This is fixed on the java-grammar branch

@adangel adangel mentioned this issue Jan 23, 2023
55 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in:ast About the AST structure or API, the parsing step
Projects
None yet
Development

No branches or pull requests

1 participant