Class IllegalTypeCheck

  • All Implemented Interfaces:
    Configurable, Contextualizable

    public final class IllegalTypeCheck
    extends AbstractCheck
    Checks that particular class are never used as types in variable declarations, return values or parameters.

    Rationale: Helps reduce coupling on concrete classes.

    Check has following properties:

    format - Pattern for illegal class names.

    legalAbstractClassNames - Abstract classes that may be used as types.

    illegalClassNames - Classes that should not be used as types in variable declarations, return values or parameters. It is possible to set illegal class names via short or canonical name. Specifying illegal type invokes analyzing imports and Check puts violations at corresponding declarations (of variables, methods or parameters). This helps to avoid ambiguous cases, e.g.:

    java.awt.List was set as illegal class name, then, code like:

    import java.util.List;<br> ...<br> List list; //No violation here

    will be ok.

    validateAbstractClassNames - controls whether to validate abstract class names. Default value is false

    ignoredMethodNames - Methods that should not be checked.

    memberModifiers - To check only methods and fields with only specified modifiers.

    In most cases it's justified to put following classes to illegalClassNames:

    • GregorianCalendar
    • Hashtable
    • ArrayList
    • LinkedList
    • Vector

    as methods that are differ from interface methods are rear used, so in most cases user will benefit from checking for them.

    Author:
    Simon Harris, Aleksey Nesterenko, Andrei Selkin
    • Constructor Detail

      • IllegalTypeCheck

        public IllegalTypeCheck()
        Creates new instance of the check.
    • Method Detail

      • setFormat

        public void setFormat​(Pattern pattern)
        Set the format for the specified regular expression.
        Parameters:
        pattern - a pattern.
      • setValidateAbstractClassNames

        public void setValidateAbstractClassNames​(boolean validateAbstractClassNames)
        Sets whether to validate abstract class names.
        Parameters:
        validateAbstractClassNames - whether abstract class names must be ignored.
      • 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
      • setIllegalClassNames

        public void setIllegalClassNames​(String... classNames)
        Set the list of illegal variable types.
        Parameters:
        classNames - array of illegal variable types
      • setIgnoredMethodNames

        public void setIgnoredMethodNames​(String... methodNames)
        Set the list of ignore method names.
        Parameters:
        methodNames - array of ignored method names
      • setLegalAbstractClassNames

        public void setLegalAbstractClassNames​(String... classNames)
        Set the list of legal abstract class names.
        Parameters:
        classNames - array of legal abstract class names
      • setMemberModifiers

        public void setMemberModifiers​(String modifiers)
        Set the list of member modifiers (of methods and fields) which should be checked.
        Parameters:
        modifiers - String contains modifiers.