public final class ClassFanOutComplexityCheck extends AbstractClassCouplingCheck
The number of other classes a given class 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:
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.
excludedClasses
parameter,
the class does not increase complexity.
max
- Specify the maximum threshold allowed.
Default value is 20
.
excludedClasses
- Specify user-configured class names to ignore.
Default value is ArrayIndexOutOfBoundsException, ArrayList, Boolean, Byte,
Character, Class, Deprecated, Deque, Double, Exception, Float, FunctionalInterface,
HashMap, HashSet, IllegalArgumentException, IllegalStateException,
IndexOutOfBoundsException, Integer, LinkedList, List, Long, Map, NullPointerException,
Object, Override, Queue, RuntimeException, SafeVarargs, SecurityException, Set, Short,
SortedMap, SortedSet, String, StringBuffer, StringBuilder, SuppressWarnings, Throwable,
TreeMap, TreeSet, UnsupportedOperationException, Void, boolean, byte, char, double,
float, int, long, short, void
.
excludeClassesRegexps
- Specify user-configured regular
expressions to ignore classes.
Default value is ^$
.
excludedPackages
- Specify user-configured packages to ignore.
All excluded packages should end with a period, so it also appends a dot to a package name.
Default value is {}
.
To configure the check:
<module name="ClassFanOutComplexity"/>
To configure the check with a threshold of 10:
<module name="ClassFanOutComplexity"> <property name="max" value="10"/> </module>
Override property excludedPackages
to mark some packages as excluded.
Each member of excludedPackages
should be a valid identifier:
java.util
- valid, excludes all classes inside java.util
,
but not from the subpackages.
java.util.
- invalid, should not end with a dot.
java.util.*
- invalid, should not end with a star.
Note, that checkstyle will ignore all classes from the java.lang
package and its subpackages, even if the java.lang
was not listed
in the excludedPackages
parameter.
Also node, that excludedPackages
will not exclude classes, imported
via wildcard (e.g. import java.math.*
). Instead of wildcard import
you should use direct import (e.g. import java.math.BigDecimal
).
Also note, that checkstyle will not exclude classes within the same file even
if it was listed in the excludedPackages
parameter.
For example, assuming the config is
<module name="ClassDataAbstractionCoupling"> <property name="excludedPackages" value="a.b"/> </module>
And the file a.b.Foo.java
is:
package a.b; import a.b.Bar; import a.b.c.Baz; public class Foo { public Bar bar; // Will be ignored, located inside ignored a.b package public Baz baz; // Will not be ignored, located inside a.b.c package public Data data; // Will not be ignored, same file class Data { public Foo foo; // Will not be ignored, same file } }
The bar
member will not be counted, since the a.b
added to the excludedPackages
. The baz
member will be counted,
since the a.b.c
was not added to the excludedPackages
.
The data
and foo
members will be counted, as they are inside same file.
Example of usage:
<module name="ClassFanOutComplexity"> <property name="excludedPackages" value="java.util, java.math"/> </module>
AutomaticBean.OutputStreamOptions
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
MSG_KEY
A key is pointing to the warning message text in "messages.properties"
file.
|
Constructor and Description |
---|
ClassFanOutComplexityCheck()
Creates new instance of this check.
|
Modifier and Type | Method and Description |
---|---|
int[] |
getAcceptableTokens()
The configurable token set.
|
protected java.lang.String |
getLogMessageId()
Returns message key we use for log violations.
|
int[] |
getRequiredTokens()
The tokens that this check must be registered for.
|
beginTree, getDefaultTokens, leaveToken, setExcludeClassesRegexps, setExcludedClasses, setExcludedPackages, setMax, visitToken
clearMessages, destroy, finishTree, getFileContents, getLine, getLines, getMessages, getTabWidth, getTokenNames, init, isCommentNodesRequired, log, log, log, setFileContents, setTabWidth, setTokens
finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverity
configure, contextualize, getConfiguration, setupChild
public static final java.lang.String MSG_KEY
public ClassFanOutComplexityCheck()
public int[] getRequiredTokens()
AbstractCheck
getRequiredTokens
in class AbstractCheck
TokenTypes
public int[] getAcceptableTokens()
AbstractCheck
getAcceptableTokens
in class AbstractCheck
TokenTypes
protected java.lang.String getLogMessageId()
AbstractClassCouplingCheck
getLogMessageId
in class AbstractClassCouplingCheck
Copyright © 2001-2019. All Rights Reserved.