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] AccessNode API changes #1307

Closed
Tracked by #3898
oowekyala opened this issue Aug 17, 2018 · 3 comments · Fixed by #4768
Closed
Tracked by #3898

[java] AccessNode API changes #1307

oowekyala opened this issue Aug 17, 2018 · 3 comments · Fixed by #4768
Assignees
Labels
in:ast About the AST structure or API, the parsing step
Milestone

Comments

@oowekyala
Copy link
Member

oowekyala commented Aug 17, 2018

The purpose of AccessNode is to denote a node which can have declaration modifiers, eg abstract, final, public, etc. Some nodes implement it just to get the "final" modifier:

ASTLambdaExpression implements it for nothing, due to an implementation error: AbstractMethodLikeNode extends AbstractJavaAccessNode...

  1. I think all of these should stop implementing the interface in 7.0.0. We could have a separate base class for nodes that can be final, or implement it ad-hoc with a boolean since FormalParameter is a TypeNode and so we'd have to have several base classes. The amount of duplication seems acceptable
  2. The setters should be removed from the interface. They're only used by the parser, and could be package-private
@oowekyala oowekyala added the in:ast About the AST structure or API, the parsing step label Aug 17, 2018
@oowekyala oowekyala added this to the 7.0.0 milestone Aug 17, 2018
@oowekyala oowekyala changed the title [java] AccessNode refactorings [java] AccessNode API changes Aug 17, 2018
@adangel
Copy link
Member

adangel commented Mar 12, 2020

TODOs:

* TODO make modifiers accessible from XPath

* TODO rename to ModifierOwner, kept out from PR to reduce diff

@oowekyala
Copy link
Member Author

oowekyala commented Nov 10, 2020

I think the gist of this ticket was implemented, namely:

  • setters were made package-private
  • isPublic/isPrivate/isProtected/isPackagePrivate are replaced with getVisibility, and the corresponding @Visibility XPath attribute.
  • isSyntactically* are all replaced with AccessNode#hasExplicitModifiers, bzw ASTModifierList#hasAllExplicitly and hasAnyExplicitly for more control. In XPath these are exposed as a pmd-java:explicitModifiers() function, introduced by [java] New Java XPath functions #2917
  • isAbstract is still supported as a member of ASTMethodOrConstructorDeclaration and ASTAnyTypeDeclaration, and I think it makes sense
  • isFinal is for now a member of the new interface FinalizableNode, but it's not used that much and we could get rid of it (see below)
  • Lesser used modifier methods, like isSynchronized and isVolatile are deprecated for removal, as they don't really carry their weight and one can use hasModifier

I think what's I'd like to see to close this ticket is

  • push down isStatic to just ASTMethodOrConstructorDeclaration, ASTFieldDeclaration and ASTAnyTypeDeclaration as it's convenient (like isAbstract)
  • add a hasVisibility(Visibility) method to AccessNode, to replace the isPublic/Private/*, etc, for the convenience of java rules
  • remove FinalizableNode, as it's not a solid abstraction, and just push down isFinal to ASTVariableDeclaratorId, ASTAnyTypeDeclaration, ASTFieldDeclaration, and ASTMethodOrConstructorDeclaration for convenience

Having a stripped down ModifierOwner interface means it's ok to implement it in eg ASTFormalParameter (see the top comment here), without adding a bunch of irrelevant methods and XPath attributes to the API, like isSynchronized.

In any case I think the XPath API should expose as few attributes as possible, and boil down to

  • @Visibility, eg @Visibility = "public"
  • pmd-java:modifiers()
  • pmd-java:explicitModifiers()

as these apply to every ModifierOwner. Accordingly, we should use @NoAttribute everywhere else.

I think this ticket may be closed before the renaming of AccessNode to ModifierOwner, as this is already tracked by #2701 .

@adangel
Copy link
Member

adangel commented Feb 21, 2023

Note: Rename AccessNode to ModifierOwner is in #3751, scheduled for 7.0.0-RC3

@oowekyala oowekyala self-assigned this Feb 21, 2023
@adangel adangel assigned adangel and unassigned oowekyala Dec 11, 2023
adangel added a commit to adangel/pmd that referenced this issue Jan 11, 2024
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

Successfully merging a pull request may close this issue.

2 participants