Skip to content

Highlight unused access modifiers #1494

Closed

Description

@HamoodHabibi83

selam! is there a way to highlight when a modifier is not used within it's scope? For example

Main.java

keys

Key.java <- public class and constructor but only used by KeyManager, this should be marked
KeyManager.java <- public class and constructor but used by Main so this won't be marked

goodbye and thanks

Activity

  1. testforstephen commented on Jun 20, 2020

    @testforstephen
    Collaborator

    Please provide a complete Java snippet to describe what's your expectation.

  2. linsaftw commented on Jun 28, 2020

    @linsaftw

    Hi, i think he means to show if an access modifier is being really used. I was looking to ask for this feature aswell as IntelliJ IDEA has it and it was really useful.

  3. linsaftw commented on Jul 5, 2020

    @linsaftw

    An example would be:

    class Test {
    public Test() {
    doTest();
    }

    doTest() {
    System.out.println("test");
    }
    }

    Mark "doTest()" because it's protected but it's only being used in a private matter. (Only by the constructor) so the auto-correction would be to make it private. (Unused access modifier)

  4. robstryker commented on Oct 29, 2026

    @robstryker
    Contributor

    The Eclipse compiler has no option that flags a package-private method that could be private.

    • Unused private member: org.eclipse.jdt.core.compiler.problem.unusedPrivateMember only checks members that are already private. A non-private method, even one nothing outside the class calls, is never reported, because the compiler can't see other classes in the package or reflection users.
    • Closest built-ins: there's no "declaration access can be weaker" check in the JDT compiler or in jdt.ls code actions. At best, if you make it private by hand and nothing uses it, it'll then warn as unused.

    Other tools do have this check:

    • IntelliJ: has "Declaration access can be weaker".
    • PMD: can approximate it with rules like CouldBeStatic or unused-code rules, depending on the rule set.
    • SonarLint: likewise, with the relevant rules enabled.
    • Checkstyle: has DesignForExtension and VisibilityModifier, but those are about extension and fields, not this case.
  5. robstryker commented on Oct 29, 2026

    @robstryker
    Contributor

    It's also worth noting this check would generally be expensive, as you'd need to make sure nobody else in the package is actually calling it. That's why it's usually better suited to linters.

    Closing as wont-fix, unless someone implements it upstream in eclipse

  6. linsaftw commented on Oct 29, 2026

    @linsaftw

    wont a simple rg solve it tho? I've seen intellij do this.
    or maybe just detect from the already scanned scopes which ones to touch or work on.
    (I no longer use both btw)

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions