Class ClassDataAbstractionCouplingCheck

All Implemented Interfaces:
Configurable, Contextualizable

public final class ClassDataAbstractionCouplingCheck extends AbstractClassCouplingCheck
Measures the number of distinct classes that are instantiated within the given class or record. This type of coupling is not caused by inheritance or the object-oriented paradigm. Generally speaking, any data type with other data types as members or local variable that is an instantiation (object) of another class has data abstraction coupling (DAC). The higher the DAC, the more complex the structure of the class.

This check processes files in the following way:

  1. Iterates over the list of tokens (defined below) and counts all mentioned classes.
  2. If a class was imported with direct import (i.e. import java.math.BigDecimal), or the class was referenced with the package name (i.e. java.math.BigDecimal value) and the package was added to the excludedPackages parameter, the class does not increase complexity.
  3. If a class name was added to the excludedClasses parameter, the class does not increase complexity.
Since:
3.4
  • 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:
    • DEFAULT_MAX

      private static final int DEFAULT_MAX
      Default allowed complexity.
      See Also:
  • Constructor Details

    • ClassDataAbstractionCouplingCheck

      public ClassDataAbstractionCouplingCheck()
      Creates bew instance of the check.
  • Method Details

    • getRequiredTokens

      public int[] getRequiredTokens()
      Description copied from class: AbstractCheck
      The tokens that this check must be registered for.
      Specified by:
      getRequiredTokens in class AbstractCheck
      Returns:
      the token set this must be registered for.
      See Also:
    • 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:
    • getLogMessageId

      protected String getLogMessageId()
      Description copied from class: AbstractClassCouplingCheck
      Returns message key we use for log violations.
      Specified by:
      getLogMessageId in class AbstractClassCouplingCheck
      Returns:
      message key we use for log violations.
    • setExcludeClassesRegexps

      public void setExcludeClassesRegexps(Pattern... from)
      Setter to specify user-configured regular expressions to ignore classes.
      Overrides:
      setExcludeClassesRegexps in class AbstractClassCouplingCheck
      Parameters:
      from - array representing regular expressions of classes to ignore.
    • setExcludedClasses

      public void setExcludedClasses(String... excludedClasses)
      Setter to specify user-configured class names to ignore.
      Overrides:
      setExcludedClasses in class AbstractClassCouplingCheck
      Parameters:
      excludedClasses - classes to ignore.
    • setExcludedPackages

      public void setExcludedPackages(String... excludedPackages)
      Setter to specify user-configured packages to ignore.
      Overrides:
      setExcludedPackages in class AbstractClassCouplingCheck
      Parameters:
      excludedPackages - packages to ignore.
      Throws:
      IllegalArgumentException - if there are invalid identifiers among the packages.