Skip to content

[java] Preserve local class modifiers#1849

Merged
adangel merged 5 commits into
pmd:masterfrom
oowekyala:java-fix-local-modifiers
Jun 1, 2019
Merged

[java] Preserve local class modifiers#1849
adangel merged 5 commits into
pmd:masterfrom
oowekyala:java-fix-local-modifiers

Conversation

@oowekyala

Copy link
Copy Markdown
Member

Fix #1848

@oowekyala oowekyala added a:bug PMD crashes or fails to analyse a file. in:ast About the AST structure or API, the parsing step labels May 30, 2019
@oowekyala oowekyala added this to the 6.16.0 milestone May 30, 2019
@oowekyala oowekyala added the is:WIP For PRs that are not fully ready, or issues that are actively being tackled label May 30, 2019
@oowekyala oowekyala removed the is:WIP For PRs that are not fully ready, or issues that are actively being tackled label May 30, 2019
@ghost

ghost commented May 30, 2019

Copy link
Copy Markdown
1 Message
📖 This changeset introduces 1 new violations, 13 new errors and 0 new configuration errors,
removes 166 violations, 13 errors and 0 configuration errors.
Full report

Generated by 🚫 Danger

@adangel adangel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Seems like, we should consider different modifiers in PMD 7, so that "default" would only be valid for a interface method?

@adangel adangel merged commit 94afed8 into pmd:master Jun 1, 2019
@oowekyala oowekyala deleted the java-fix-local-modifiers branch June 1, 2019 19:28
@oowekyala

Copy link
Copy Markdown
Member Author

@adangel We could use several Modifiers productions in the future. Eg FieldModifiers wouldn't accept the abstract modifier, etc. This would remove the need for the lookaheads I introduced here, but would hide modifier errors behind a syntax error, which is super ugly, Javacc being what it is.

Alternatively we could just have the Modifiers production check for the modifier incompatibilities, that could break a PMD run. In particular I'm thinking about

  • specifying more than one access modifier, which could mess with many rules and with accessibility resolution for type resolution
  • specifying both "abstract" and "final" or "abstract" and "private"
  • or specifying an access modifier for a local class

I wouldn't care too much about completely absurd modifier combinations like a default class, because no rule would consider this possibility, so it couldn't break the assumptions we make for analysis

However I think the API of nodes should not expose methods for such absurd modifiers. So, ClassOrInterfaceDeclaration shouldn't have a isDefault method. We should split AccessNode I think. Probably the only thing we can share between all AccessNodes is the access modifier, which given its name, sounds like what AccessNode is supposed to be. The implementation doesn't need to change much though, we could still use an integer and parse the same way. Wdyt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a:bug PMD crashes or fails to analyse a file. in:ast About the AST structure or API, the parsing step

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[java] Local classes should preserve their modifiers

2 participants