Class AbbreviationAsWordInNameCheck

  • All Implemented Interfaces:
    Configurable, Contextualizable

    public class AbbreviationAsWordInNameCheck
    extends AbstractCheck

    The Check validate abbreviations(consecutive capital letters) length in identifier name, it also allows to enforce camel case naming. Please read more at Google Style Guide to get to know how to avoid long abbreviations in names.

    allowedAbbreviationLength specifies how many consecutive capital letters are allowed in the identifier. A value of 3 indicates that up to 4 consecutive capital letters are allowed, one after the other, before a violation is printed. The identifier 'MyTEST' would be allowed, but 'MyTESTS' would not be. A value of 0 indicates that only 1 consecutive capital letter is allowed. This is what should be used to enforce strict camel casing. The identifier 'MyTest' would be allowed, but 'MyTEst' would not be.

    Option allowedAbbreviationLength indicates on the allowed amount of capital letters in abbreviations in the classes, interfaces, variables and methods names. Default value is '3'.

    Option allowedAbbreviations - list of abbreviations that must be skipped for checking. Abbreviations should be separated by comma, no spaces are allowed.

    Option ignoreFinal allow to skip variables with final modifier. Default value is true.

    Option ignoreStatic allow to skip variables with static modifier. Default value is true.

    Option ignoreOverriddenMethod - Allows to ignore methods tagged with @Override annotation (that usually mean inherited name). Default value is true.

    Default configuration
     <module name="AbbreviationAsWordInName" />
     

    To configure to check variables and classes identifiers, do not ignore variables with static modifier and allow no abbreviations (enforce camel case phrase) but allow XML and URL abbreviations.

     <module name="AbbreviationAsWordInName">
         <property name="tokens" value="VARIABLE_DEF,CLASS_DEF"/>
         <property name="ignoreStatic" value="false"/>
         <property name="allowedAbbreviationLength" value="1"/>
         <property name="allowedAbbreviations" value="XML,URL"/>
     </module>
     
    Author:
    Roman Ivanov, Daniil Yaroslvtsev, Baratali Izmailov
    • Method Detail

      • setIgnoreFinal

        public void setIgnoreFinal​(boolean ignoreFinal)
        Sets ignore option for variables with 'final' modifier.
        Parameters:
        ignoreFinal - Defines if ignore variables with 'final' modifier or not.
      • setIgnoreStatic

        public void setIgnoreStatic​(boolean ignoreStatic)
        Sets ignore option for variables with 'static' modifier.
        Parameters:
        ignoreStatic - Defines if ignore variables with 'static' modifier or not.
      • setIgnoreOverriddenMethods

        public void setIgnoreOverriddenMethods​(boolean ignoreOverriddenMethods)
        Sets ignore option for methods with "@Override" annotation.
        Parameters:
        ignoreOverriddenMethods - Defines if ignore methods with "@Override" annotation or not.
      • setAllowedAbbreviationLength

        public void setAllowedAbbreviationLength​(int allowedAbbreviationLength)
        Allowed abbreviation length in names.
        Parameters:
        allowedAbbreviationLength - amount of allowed capital letters in abbreviation.
      • setAllowedAbbreviations

        public void setAllowedAbbreviations​(String... allowedAbbreviations)
        Set a list of abbreviations that must be skipped for checking. Abbreviations should be separated by comma, no spaces is allowed.
        Parameters:
        allowedAbbreviations - an string of abbreviations that must be skipped from checking, each abbreviation separated by comma.
      • getAcceptableTokens

        public int[] getAcceptableTokens()
        Description copied from class: AbstractCheck
        The configurable token set. Used to protect Checks against malicious users who specify an unacceptable token set in the configuration file. The default implementation returns the check's default tokens.
        Specified by:
        getAcceptableTokens in class AbstractCheck
        Returns:
        the token set this check is designed for.
        See Also:
        TokenTypes