Class LineLengthExtendedCheck

  • All Implemented Interfaces:
    com.puppycrawl.tools.checkstyle.api.Configurable, com.puppycrawl.tools.checkstyle.api.Contextualizable

    public class LineLengthExtendedCheck
    extends com.puppycrawl.tools.checkstyle.api.AbstractCheck
    Checks for long lines.

    Rationale: Long lines are hard to read in printouts or if developers have limited screen space for the source code, e.g. if the IDE displays additional information like project tree, class hierarchy, etc.

    Note: Support for the special handling of imports in CheckStyle Version 2 has been dropped as it is a special case of regexp: The user can set the ignorePattern to "^import" and achieve the same effect.

    The default maximum allowable line length is 80 characters. To change the maximum, set property max.

    To ignore lines in the check, set property ignorePattern to a regular expression for the lines to ignore.

    An example of how to configure the check is:

     <module name="LineLength"/>
     

    An example of how to configure the check to accept lines up to 120 characters long is:

     <module name="LineLength">
        <property name="max" value="120"/>
     </module>
     

    An example of how to configure the check to ignore lines that begin with " * ", followed by just one word, such as within a Javadoc comment, is:

     <module name="LineLength">
        <property name="ignorePattern" value="^ *\* *[^ ]+$"/>
     </module>
     
     There are some exceptions for class, constructor, field and method
     declarations. To ignore to check such lines there are enable|disable options.
     By default they have "false" values.
     
    Since:
    1.5.1
    Author:
    Lars Kühne, Ruslan Dyachenko
    • Nested Class Summary

      • Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean

        com.puppycrawl.tools.checkstyle.api.AutomaticBean.OutputStreamOptions
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static String MSG_KEY
      Warning message key.
    • Constructor Summary

      Constructors 
      Constructor Description
      LineLengthExtendedCheck()
      Creates a new LineLengthCheck instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void beginTree​(com.puppycrawl.tools.checkstyle.api.DetailAST rootAST)  
      void finishTree​(com.puppycrawl.tools.checkstyle.api.DetailAST rootAST)  
      int[] getAcceptableTokens()  
      int[] getDefaultTokens()  
      int[] getRequiredTokens()  
      void setIgnoreClass​(boolean value)
      Enable|Disable checking class declaration length.
      void setIgnoreConstructor​(boolean value)
      Enable|Disable checking constructor declaration length.
      void setIgnoreField​(boolean value)
      Enable|Disable checking field declaration length.
      void setIgnoreMethod​(boolean value)
      Enable|Disable checking method declaration length.
      void setIgnorePattern​(String format)
      Set the ignore pattern.
      void setMax​(int length)
      Setter for the field max.
      void visitToken​(com.puppycrawl.tools.checkstyle.api.DetailAST ast)  
      • Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheck

        clearViolations, destroy, getFileContents, getFilePath, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, init, isCommentNodesRequired, leaveToken, log, log, log, setFileContents, setTabWidth, setTokens
      • Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter

        finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverity
      • Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean

        configure, contextualize, getConfiguration, setupChild
    • Constructor Detail

      • LineLengthExtendedCheck

        public LineLengthExtendedCheck()
        Creates a new LineLengthCheck instance.
    • Method Detail

      • setIgnoreField

        public void setIgnoreField​(boolean value)
        Enable|Disable checking field declaration length.
        Parameters:
        value - check field declaration length.
      • setIgnoreMethod

        public void setIgnoreMethod​(boolean value)
        Enable|Disable checking method declaration length.
        Parameters:
        value - check method declaration length.
      • setIgnoreConstructor

        public void setIgnoreConstructor​(boolean value)
        Enable|Disable checking constructor declaration length.
        Parameters:
        value - check constructor declaration length.
      • setIgnoreClass

        public void setIgnoreClass​(boolean value)
        Enable|Disable checking class declaration length.
        Parameters:
        value - check class declaration length.
      • getDefaultTokens

        public int[] getDefaultTokens()
        Specified by:
        getDefaultTokens in class com.puppycrawl.tools.checkstyle.api.AbstractCheck
      • getAcceptableTokens

        public int[] getAcceptableTokens()
        Specified by:
        getAcceptableTokens in class com.puppycrawl.tools.checkstyle.api.AbstractCheck
      • getRequiredTokens

        public int[] getRequiredTokens()
        Specified by:
        getRequiredTokens in class com.puppycrawl.tools.checkstyle.api.AbstractCheck
      • visitToken

        public void visitToken​(com.puppycrawl.tools.checkstyle.api.DetailAST ast)
        Overrides:
        visitToken in class com.puppycrawl.tools.checkstyle.api.AbstractCheck
      • beginTree

        public void beginTree​(com.puppycrawl.tools.checkstyle.api.DetailAST rootAST)
        Overrides:
        beginTree in class com.puppycrawl.tools.checkstyle.api.AbstractCheck
      • finishTree

        public void finishTree​(com.puppycrawl.tools.checkstyle.api.DetailAST rootAST)
        Overrides:
        finishTree in class com.puppycrawl.tools.checkstyle.api.AbstractCheck
      • setMax

        public void setMax​(int length)
        Setter for the field max.
        Parameters:
        length - the maximum length of a line
      • setIgnorePattern

        public final void setIgnorePattern​(String format)
        Set the ignore pattern.
        Parameters:
        format - a String value
        Throws:
        IllegalArgumentException - unable to parse aFormat