GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [java] Java8 parsing corner case with annotated array types · Issue #997 · pmd/pmd

[java] Java8 parsing corner case with annotated array types  #997

New issue
Copy link
New issue
Copy link
Closed
Closed
[java] Java8 parsing corner case with annotated array types #997
Copy link
Assignees
oowekyala
Labels
a:bugPMD crashes or fails to analyse a file.in:astAbout the AST structure or API, the parsing step
Milestone
7.0.0

Description

@oowekyala
oowekyala
opened on Mar 23, 2018
Issue body actions

Problems

With Java 8 type annotations, the dimensions of an array may each have different annotations, which our parser actually doesn't support... There are several instances of this problem:

Type node

      // Doesn't parse
      int @Foo[]@Bar[] i;

JLS

Our grammar:

https://github.com/pmd/pmd/blob/master/pmd-java/etc/grammar/Java.jjt#L1885-L1887

Array creation expression

   // Doesn't parse
    new int @Foo[2] @Bar[];

JLS

Our grammar:

https://github.com/pmd/pmd/blob/master/pmd-java/etc/grammar/Java.jjt#L2261-L2269

VariableDeclaratorId

class Foo {
  int i @Bar[]; // field declaration

  void bar(int i@Bar[]) { // formal parameter 
    int i @Bar[]; // local variable declaration
  }
}

JLS

Our grammar:

https://github.com/pmd/pmd/blob/master/pmd-java/etc/grammar/Java.jjt#L1771-1787

Method declarations

The JLS allows array dimensions (including annotations) to be added after the formal parameter list, eg:

  int method()@Foo[]@Bar[] {
        return new int[2][];
  }

By the way, even without annotations, the parser currently discards the additionnal array dimensions, though it should be used in type resolution:

https://github.com/pmd/pmd/blob/master/pmd-java/etc/grammar/Java.jjt#L1822

This is related to the broader #910 changeset

Solution

  • Add a node for the array dimensions, which resembles the JLS for the Dims production. This wouldn't be API breaking, provided we make the dimensions of eg ReferenceType delegate to that Dims node.
  • Dimensionable should probably be deprecated entirely, and we could use a new interface to replace it that exposes the annotations and the dimensions for type resolution, based on the Dims node
  • To make the method return type resolution work correctly, we could make ReturnType a Dimensionable (and a TypeNode), and add the dimensions of the Dims node found in the method declarator to the dimensions found in the type node.

I imagine that could be 3 PRs

Activity

  1. oowekyala
    added
    a:bugPMD crashes or fails to analyse a file.
    on Mar 23, 2018
  2. oowekyala
    self-assigned this
    on Mar 23, 2018
  3. oowekyala
    added this to the 6.3.0 milestone on Mar 23, 2018
  4. adangel
    modified the milestones: 6.3.0, 6.4.0 on Apr 28, 2018
  5. adangel
    modified the milestones: 6.4.0, 6.5.0 on May 19, 2018
  6. oowekyala
    added
    in:astAbout the AST structure or API, the parsing step
    on May 27, 2018
  7. jsotuyod
    modified the milestones: 6.5.0, 6.6.0 on Jun 26, 2018
  8. adangel
    modified the milestones: 6.6.0, 6.7.0 on Jul 29, 2018
  9. adangel
    modified the milestones: 6.7.0, 6.8.0 on Sep 1, 2018
  10. oowekyala
    removed this from the 6.8.0 milestone on Sep 29, 2018
  11. oowekyala
    added this to the 7.0.0 milestone on Nov 6, 2018
  12. jsotuyod
    added
    has:pr
    on Apr 7, 2019
  13. oowekyala commented on Apr 25, 2020

    @oowekyala
    oowekyala
    on Apr 25, 2020
    MemberAuthor
    More actions

    Fixed on the java-grammar branch

  14. oowekyala
    closed this as completedon Apr 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @oowekyala
    oowekyala

Labels

a:bugPMD crashes or fails to analyse a file.in:astAbout the AST structure or API, the parsing step

Type

No type

Projects

No projects

    Milestone

    • 7.0.0

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.