AnonInnerLength

Since Checkstyle 3.2

Description

Checks for long anonymous inner classes.

Rationale: If an anonymous inner class becomes very long it is hard to understand and to see the flow of the method where the class is defined. Therefore, long anonymous inner classes should usually be refactored into a named inner class. See also Bloch, Effective Java, p. 93.

Properties

name description type default value since
max Specify the maximum number of lines allowed. int 20 3.2

Examples

To configure the check to accept anonymous classes with up to 20 lines:

<module name="Checker">
  <module name="TreeWalker">
    <module name="AnonInnerLength"/>
  </module>
</module>
        

To configure the check to accept anonymous classes with up to 60 lines:

<module name="Checker">
  <module name="TreeWalker">
    <module name="AnonInnerLength">
      <property name="max" value="60"/>
    </module>
  </module>
</module>
        

Example of Usage

Violation Messages

All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.sizes

Parent Module

TreeWalker