Usage Checks Checkstyle Development Team

Checks that a private field is used in more than one method, constructor, or initializer.

Rationale: a private field used in only one method, constructor, or initializer should be replaced by a local variable.

name description type default value
ignoreFormat pattern for field names that should be ignored regular expression ^$ (empty)

To configure the check:

<module name="usage.OneMethodPrivateField"/>

To configure the check to ignore fields whose name ends in Temp:

<module name="usage.OneMethodPrivateField"> <property name="ignoreFormat" value="Temp$"/> </module>

com.puppycrawl.tools.checkstyle.checks.usage

TreeWalker

Checks that a local variable is used after its declaration.

name description type default value
ignoreFormat pattern for variable names that should be ignored regular expression ^$ (empty)

To configure the check:

<module name="usage.UnusedLocalVariable"/>

To configure the check to ignore variables whose name ends in Temp:

<module name="usage.UnusedLocalVariable"> <property name="ignoreFormat" value="Temp$"/> </module>

com.puppycrawl.tools.checkstyle.checks.usage

TreeWalker

Checks that a parameter is used.

name description type default value
ignoreFormat pattern for parameter names that should be ignored regular expression ^$ (empty)
ignoreCatch controls whether catch parameters should be ignored boolean true
ignoreNonLocal controls whether parameters of non local (public, protected or package) methods should be ignored boolean false

To configure the check:

<module name="usage.UnusedParameter"/>

To configure the check to ignore parameters whose name ends in Temp:

<module name="usage.UnusedParameter"> <property name="ignoreFormat" value="Temp$"/> </module>

To configure the check to report unused catch parameters:

<module name="usage.UnusedParameter"> <property name="ignoreCatch" value="false"/> </module>

com.puppycrawl.tools.checkstyle.checks.usage

TreeWalker

Checks that a private field is used.

name description type default value
ignoreFormat pattern for field names that should be ignored regular expression ^$ (empty)

To configure the check:

<module name="usage.UnusedPrivateField"/>

To configure the check to ignore fields whose name ends in Temp:

<module name="usage.UnusedPrivateField"> <property name="ignoreFormat" value="Temp$"/> </module>

com.puppycrawl.tools.checkstyle.checks.usage

TreeWalker

Checks that a private method is used.

name description type default value
ignoreFormat pattern for method names that should be ignored regular expression ^$ (empty)
allowSerializationMethods whether the check should allow serialization-related methods (readObject(), writeObject(), readResolve() and writeReplace() boolean false

To configure the check:

<module name="usage.UnusedPrivateMethod"/>

To configure the check to ignore methods whose name ends in Temp:

<module name="usage.UnusedPrivateMethod"> <property name="ignoreFormat" value="Temp$"/> </module>
  • The classpath may need to be configured to locate parameter type information. The classpath configuration is dependent on the mechanism used to invoke Checkstyle.

com.puppycrawl.tools.checkstyle.checks.usage

TreeWalker