Class AbstractClassCouplingCheck
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
- All Implemented Interfaces:
Configurable,Contextualizable
- Direct Known Subclasses:
ClassDataAbstractionCouplingCheck,ClassFanOutComplexityCheck
Base class for coupling calculation.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final classEncapsulates information about class coupling.Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final PatternPattern to match brackets in a full type name.private final Deque<AbstractClassCouplingCheck.ClassContext>Stack of class contexts.Class names to ignore.Package names to ignore.private static final charA package separator - ".".Specify user-configured regular expressions to ignore classes.Specify user-configured class names to ignore.Specify user-configured packages to ignore.A map of (imported class name -> class name with package) pairs.private intSpecify the maximum threshold allowed.private StringCurrent file package. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractClassCouplingCheck(int defaultMax) Creates new instance of the check. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidCalled before the starting to process a tree.private voidRestores previous context.private voidcreateNewClassContext(String className, DetailAST ast) Creates new inner class context with given name and location.final int[]Returns the default token a check is interested in.protected abstract StringReturns message key we use for log violations.private voidRestores previous context.voidleaveToken(DetailAST ast) Called after all the child nodes have been process.private voidregisterImport(DetailAST imp) Registers given import.voidsetExcludeClassesRegexps(Pattern... from) Setter to specify user-configured regular expressions to ignore classes.final voidsetExcludedClasses(String... excludedClasses) Setter to specify user-configured class names to ignore.final voidsetExcludedPackages(String... excludedPackages) Setter to specify user-configured packages to ignore.final voidsetMax(int max) Setter to specify the maximum threshold allowed.private voidvisitAnnotationType(DetailAST annotationAST) Visit ANNOTATION literal and get its type to referenced classes of context.private voidvisitClassDef(DetailAST classDef) Creates new context for a given class.private voidvisitLiteralNew(DetailAST ast) Visits NEW token for the current class context.private voidVisits THROWS token for the current class context.private voidvisitPackageDef(DetailAST pkg) Stores package of current class we check.voidvisitToken(DetailAST ast) Called to process a token.private voidVisits type token for the current class context.Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheck
clearViolations, destroy, finishTree, getAcceptableTokens, getFileContents, getFilePath, getLine, getLineCodePoints, getLines, getRequiredTokens, getTabWidth, getTokenNames, getViolations, init, isCommentNodesRequired, log, log, log, setFileContents, setTabWidth, setTokensMethods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityMethods inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
configure, contextualize, getConfiguration, setupChild
-
Field Details
-
DOT
A package separator - ".".- See Also:
-
DEFAULT_EXCLUDED_CLASSES
Class names to ignore. -
DEFAULT_EXCLUDED_PACKAGES
Package names to ignore. -
BRACKET_PATTERN
Pattern to match brackets in a full type name. -
excludeClassesRegexps
Specify user-configured regular expressions to ignore classes. -
importedClassPackages
A map of (imported class name -> class name with package) pairs. -
classesContexts
Stack of class contexts. -
excludedClasses
Specify user-configured class names to ignore. -
excludedPackages
Specify user-configured packages to ignore. -
max
Specify the maximum threshold allowed. -
packageName
Current file package.
-
-
Constructor Details
-
AbstractClassCouplingCheck
Creates new instance of the check.- Parameters:
defaultMax- default value for allowed complexity.
-
-
Method Details
-
getLogMessageId
Returns message key we use for log violations.- Returns:
- message key we use for log violations.
-
getDefaultTokens
Description copied from class:AbstractCheckReturns the default token a check is interested in. Only used if the configuration for a check does not define the tokens.- Specified by:
getDefaultTokensin classAbstractCheck- Returns:
- the default tokens
- See Also:
-
setMax
Setter to specify the maximum threshold allowed.- Parameters:
max- allowed complexity.
-
setExcludedClasses
Setter to specify user-configured class names to ignore.- Parameters:
excludedClasses- classes to ignore.
-
setExcludeClassesRegexps
Setter to specify user-configured regular expressions to ignore classes.- Parameters:
from- array representing regular expressions of classes to ignore.
-
setExcludedPackages
Setter to specify user-configured packages to ignore.- Parameters:
excludedPackages- packages to ignore.- Throws:
IllegalArgumentException- if there are invalid identifiers among the packages.
-
beginTree
Description copied from class:AbstractCheckCalled before the starting to process a tree. Ideal place to initialize information that is to be collected whilst processing a tree.- Overrides:
beginTreein classAbstractCheck- Parameters:
ast- the root of the tree
-
visitToken
Description copied from class:AbstractCheckCalled to process a token.- Overrides:
visitTokenin classAbstractCheck- Parameters:
ast- the token to process
-
leaveToken
Description copied from class:AbstractCheckCalled after all the child nodes have been process.- Overrides:
leaveTokenin classAbstractCheck- Parameters:
ast- the token leaving
-
visitPackageDef
Stores package of current class we check.- Parameters:
pkg- package definition.
-
visitClassDef
Creates new context for a given class.- Parameters:
classDef- class definition node.
-
leaveClassDef
Restores previous context. -
registerImport
Registers given import. This allows us to track imported classes.- Parameters:
imp- import definition.
-
createNewClassContext
Creates new inner class context with given name and location.- Parameters:
className- The class name.ast- The class ast.
-
checkCurrentClassAndRestorePrevious
Restores previous context. -
visitType
Visits type token for the current class context.- Parameters:
ast- TYPE token.
-
visitLiteralNew
Visits NEW token for the current class context.- Parameters:
ast- NEW token.
-
visitLiteralThrows
Visits THROWS token for the current class context.- Parameters:
ast- THROWS token.
-
visitAnnotationType
Visit ANNOTATION literal and get its type to referenced classes of context.- Parameters:
annotationAST- Annotation ast.
-