Inspectopedia Help

Declaration access can be weaker

Reports fields, methods or classes that may have their access modifier narrowed down.

Example:

class Sample { void foo() { bar("foo", "foo"); } void bar(String x, String y) { } // can be private }

After the quick-fix is applied:

class Sample { void foo() { bar("foo", "foo"); } private void bar(String x, String y) { } }

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

WeakerAccess
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Java | Declaration redundancy

Use the inspection's options to define the rules for the modifier change suggestions.

Inspection options

Here you can find the description of settings available for the Declaration access can be weaker inspection, and the reference of their default values.

Suggest package-private visibility level for class members

Default: Selected

Suggest package-private visibility level for top-level classes

Default: Selected

Suggest 'private' for inner class members when referenced from outer class only

Not selected

Suggest weaker visibility for constants

Default: Selected

Suggest package-private visibility level for classes in exported packages (Java 9+)

Default: Selected

Suggest package-private visibility level for junit 5 tests

Default: Selected

Availability

By default bundled with

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin

Java, 241.18072

Last modified: 18 June 2024