Class ClassFanOutComplexityCheck
- 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.ClassFanOutComplexityCheck
-
- All Implemented Interfaces:
Configurable
,Contextualizable
public final class ClassFanOutComplexityCheck extends AbstractClassCouplingCheck
Checks the number of other types a given class/record/interface/enum/annotation relies on. Also, the square of this has been shown to indicate the amount of maintenance required in functional programs (on a file basis) at least.This check processes files in the following way:
- Iterates over all tokens that might contain type reference.
-
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.
-
Property
excludeClassesRegexps
- Specify user-configured regular expressions to ignore classes. Type isjava.util.regex.Pattern[]
. Default value is^$
. -
Property
excludedClasses
- Specify user-configured class names to ignore. Type isjava.lang.String[]
. Default value isArrayIndexOutOfBoundsException, ArrayList, Boolean, Byte, Character, Class, Collection, Deprecated, Deque, Double, DoubleStream, EnumSet, Exception, Float, FunctionalInterface, HashMap, HashSet, IllegalArgumentException, IllegalStateException, IndexOutOfBoundsException, IntStream, Integer, LinkedHashMap, LinkedHashSet, LinkedList, List, Long, LongStream, Map, NullPointerException, Object, Optional, OptionalDouble, OptionalInt, OptionalLong, Override, Queue, RuntimeException, SafeVarargs, SecurityException, Set, Short, SortedMap, SortedSet, Stream, String, StringBuffer, StringBuilder, SuppressWarnings, Throwable, TreeMap, TreeSet, UnsupportedOperationException, Void, boolean, byte, char, double, float, int, long, short, var, void
. -
Property
excludedPackages
- Specify user-configured packages to ignore. Type isjava.lang.String[]
. Default value is""
. -
Property
max
- Specify the maximum threshold allowed. Type isint
. Default value is20
.
Parent is
com.puppycrawl.tools.checkstyle.TreeWalker
Violation Message Keys:
-
classFanOutComplexity
- Since:
- 3.4
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions
-
-
Field Summary
Fields Modifier and Type Field Description private static int
DEFAULT_MAX
Default value of max value.static String
MSG_KEY
A key is pointing to the warning message text in "messages.properties" file.
-
Constructor Summary
Constructors Constructor Description ClassFanOutComplexityCheck()
Creates new instance of this check.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int[]
getAcceptableTokens()
The configurable token set.protected String
getLogMessageId()
Returns message key we use for log violations.int[]
getRequiredTokens()
The tokens that this check must be registered for.-
Methods inherited from class com.puppycrawl.tools.checkstyle.checks.metrics.AbstractClassCouplingCheck
beginTree, getDefaultTokens, leaveToken, setExcludeClassesRegexps, setExcludedClasses, setExcludedPackages, 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 Detail
-
MSG_KEY
public static final String MSG_KEY
A key is pointing to the warning message text in "messages.properties" file.- See Also:
- Constant Field Values
-
DEFAULT_MAX
private static final int DEFAULT_MAX
Default value of max value.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ClassFanOutComplexityCheck
public ClassFanOutComplexityCheck()
Creates new instance of this check.
-
-
Method Detail
-
getRequiredTokens
public int[] 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:
TokenTypes
-
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 classAbstractCheck
- Returns:
- the token set this check is designed for.
- See Also:
TokenTypes
-
getLogMessageId
protected String 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.
-
-