Skip to content

[java] Merge AccessorClassGeneration and AccessorMethodGeneration #2892

Open

Description

@oowekyala

Is your feature request related to a problem? Please describe.

AccessorClassGeneration, AccessorMethodGeneration

Both rules basically do the same check, ie they check for private members being accessed from outside the class they're defined in. The difference, is that AccessorClassGeneration only checks for private constructors, while the other rule checks for other kinds of members (fields and methods).

I think separating those is not useful, as the fix in both cases is the same: make the member non-private. The fact that for some kinds of members an accessor class is generated, and for the others, an accessor method, is a technicality that does not affect how a user would use those rules. It would be described in the documentation though.

Describe the solution you'd like Merge both rules into a new PrivateMemberAccess rule.

Describe alternatives you've considered
None

Additional context In PMD 7 the way I rewrote those rules is identical, and AccessorClassGeneration uses the implementation in AccessorMethodGeneration. Having a single class would be nice. See AccessorClassGeneration

It would also be nice to report the violation on the field/method/constructor being caught and not the usage, as there might be several usages, and it's easier to fix it this way. This is done in the rewrite for pmd 7.

Activity

  1. added
    an:enhancement
    on Nov 2, 2020
  2. added this to the 7.0.0 milestone on Nov 2, 2020
  3. changed the title [-]Merge AccessorClassGeneration and AccessorMethodGeneration[/-] [+][java] Merge AccessorClassGeneration and AccessorMethodGeneration[/+] on Nov 2, 2020
  4. adangel commented on Nov 23, 2020

    @adangel
    Member

    Note: These rules are only valid until java 10. After that, with java 11, there is support for JEP 181: Nest-Based Access Control. Then accessor classes/methods are not generated anymore.

    This info is unfortunately not mentioned in the rule description, but it should be.

    Otherwise 👍 for merging.

  5. modified the milestones: 7.0.0, 7.x on Jan 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    an:enhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions