Class FileLengthCheck

All Implemented Interfaces:
Configurable, Contextualizable, FileSetCheck

public class FileLengthCheck extends AbstractFileSetCheck

Checks for long source files.

Rationale: If a source file becomes very long it is hard to understand. Therefore long classes should usually be refactored into several individual classes that focus on a specific task.

  • Property max - Specify the maximum number of lines allowed. Type is int. Default value is 2000.
  • Property fileExtensions - Specify the file type extension of files to process. Type is java.lang.String[]. Default value is "".

To configure the check:

 <module name="FileLength"/>
 

To configure the check to accept files with up to 1500 lines:

 <module name="FileLength">
   <property name="max" value="1500"/>
 </module>
 

Parent is com.puppycrawl.tools.checkstyle.Checker

Violation Message Keys:

  • maxLen.file
Since:
5.0
  • Field Details

    • MSG_KEY

      public static final String MSG_KEY
      A key is pointing to the warning message text in "messages.properties" file.
      See Also:
  • Constructor Details

    • FileLengthCheck

      public FileLengthCheck()
  • Method Details

    • processFiltered

      protected void processFiltered(File file, FileText fileText)
      Description copied from class: AbstractFileSetCheck
      Called to process a file that matches the specified file extensions.
      Specified by:
      processFiltered in class AbstractFileSetCheck
      Parameters:
      file - the file to be processed
      fileText - the contents of the file.
    • setMax

      public void setMax(int length)
      Setter to specify the maximum number of lines allowed.
      Parameters:
      length - the maximum length of a Java source file