Class ClassDataAbstractionCouplingCheck
java.lang.Object
com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
com.puppycrawl.tools.checkstyle.api.AbstractCheck
com.puppycrawl.tools.checkstyle.checks.metrics.AbstractClassCouplingCheck
com.puppycrawl.tools.checkstyle.checks.metrics.ClassDataAbstractionCouplingCheck
- All Implemented Interfaces:
Configurable
,Contextualizable
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:
- Iterates over the list of tokens (defined below) and counts all mentioned classes.
-
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 theexcludedPackages
parameter, the class does not increase complexity. -
If a class name was added to the
excludedClasses
parameter, the class does not increase complexity.
- Since:
- 3.4
-
Nested Class Summary
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
Default allowed complexity.static final String
A key is pointing to the warning message text in "messages.properties" file. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint[]
The configurable token set.protected String
Returns message key we use for log violations.int[]
The tokens that this check must be registered for.void
setExcludeClassesRegexps
(Pattern... from) Setter to specify user-configured regular expressions to ignore classes.void
setExcludedClasses
(String... excludedClasses) Setter to specify user-configured class names to ignore.void
setExcludedPackages
(String... excludedPackages) Setter to specify user-configured packages to ignore.Methods inherited from class com.puppycrawl.tools.checkstyle.checks.metrics.AbstractClassCouplingCheck
beginTree, getDefaultTokens, leaveToken, setMax, visitToken
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheck
clearViolations, destroy, finishTree, getFileContents, getFilePath, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, init, isCommentNodesRequired, 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.AbstractAutomaticBean
configure, contextualize, getConfiguration, setupChild
-
Field Details
-
MSG_KEY
A key is pointing to the warning message text in "messages.properties" file.- See Also:
-
DEFAULT_MAX
Default allowed complexity.- See Also:
-
-
Constructor Details
-
ClassDataAbstractionCouplingCheck
public ClassDataAbstractionCouplingCheck()Creates bew instance of the check.
-
-
Method Details
-
getRequiredTokens
Description copied from class:AbstractCheck
The tokens that this check must be registered for.- Specified by:
getRequiredTokens
in classAbstractCheck
- Returns:
- the token set this must be registered for.
- See Also:
-
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 classAbstractCheck
- Returns:
- the token set this check is designed for.
- See Also:
-
getLogMessageId
Description copied from class:AbstractClassCouplingCheck
Returns message key we use for log violations.- Specified by:
getLogMessageId
in classAbstractClassCouplingCheck
- Returns:
- message key we use for log violations.
-
setExcludeClassesRegexps
Setter to specify user-configured regular expressions to ignore classes.- Overrides:
setExcludeClassesRegexps
in classAbstractClassCouplingCheck
- Parameters:
from
- array representing regular expressions of classes to ignore.
-
setExcludedClasses
Setter to specify user-configured class names to ignore.- Overrides:
setExcludedClasses
in classAbstractClassCouplingCheck
- Parameters:
excludedClasses
- classes to ignore.
-
setExcludedPackages
Setter to specify user-configured packages to ignore.- Overrides:
setExcludedPackages
in classAbstractClassCouplingCheck
- Parameters:
excludedPackages
- packages to ignore.- Throws:
IllegalArgumentException
- if there are invalid identifiers among the packages.
-