Skip to content

[java] Local classes should preserve their modifiers #1848

@oowekyala

Description

@oowekyala

Local classes have several problems for now:

  • The modifiers are not preserved (the production is called with ClassOrInterfaceDeclaration(0), where 0 is supposed to be the modifiers)
  • Modifiers can't be mixed with annotations, the lookahead explicitly needs the annotations to precede the modifiers. But mixing modifiers with annotations like @F final @B class Local {} is just as valid for local classes as it would be for other types of class declarations.
  • for a local class, AccessNode#isPackagePrivate returns true, since there are no other visibility modifiers. A local class is not package private though... it's local.

/*
TODO: Seems like we should be discarding the "final"
after using it in the lookahead; I added a ["final|abstract"] inside
ClassOrInterfaceDeclaration, but that seems like a hack that
could break other things...
*/
LOOKAHEAD( (Annotation())* ["final"|"abstract"] "class") (Annotation())* ClassOrInterfaceDeclaration(0)

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions