Class AbstractClassCouplingCheck.ClassContext
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.checks.metrics.AbstractClassCouplingCheck.ClassContext
-
- Enclosing class:
- AbstractClassCouplingCheck
private final class AbstractClassCouplingCheck.ClassContext extends java.lang.Object
Encapsulates information about class coupling.
-
-
Field Summary
Fields Modifier and Type Field Description private DetailAST
classAst
AST of class definition.private java.lang.String
className
Own class name.private java.util.Set<java.lang.String>
referencedClassNames
Set of referenced classes.
-
Constructor Summary
Constructors Modifier Constructor Description private
ClassContext(java.lang.String className, DetailAST ast)
Create new context associated with given class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addReferencedClassName(DetailAST ast)
Adds new referenced class.private void
addReferencedClassName(java.lang.String referencedClassName)
Adds new referenced class.void
checkCoupling()
Checks if coupling less than allowed or not.private java.util.Optional<java.lang.String>
getClassNameWithPackage(java.lang.String examineClassName)
Retrieves class name with packages.private boolean
isExcludedClassRegexp(java.lang.String candidateClassName)
Checks if given class should be ignored as it belongs to excluded class regexp.private boolean
isFromExcludedPackage(java.lang.String candidateClassName)
Checks if given class should be ignored as it belongs to excluded package.private boolean
isSignificant(java.lang.String candidateClassName)
Checks if given class shouldn't be ignored and not from java.lang.void
visitLiteralNew(DetailAST ast)
Visits NEW.void
visitLiteralThrows(DetailAST literalThrows)
Visits throws clause and collects all exceptions we throw.void
visitType(DetailAST ast)
Visits type.
-
-
-
Field Detail
-
referencedClassNames
private final java.util.Set<java.lang.String> referencedClassNames
Set of referenced classes. Sorted by name for predictable violation messages in unit tests.
-
className
private final java.lang.String className
Own class name.
-
-
Constructor Detail
-
ClassContext
private ClassContext(java.lang.String className, DetailAST ast)
Create new context associated with given class.- Parameters:
className
- name of the given class.ast
- ast of class definition.
-
-
Method Detail
-
visitLiteralThrows
public void visitLiteralThrows(DetailAST literalThrows)
Visits throws clause and collects all exceptions we throw.- Parameters:
literalThrows
- throws to process.
-
visitLiteralNew
public void visitLiteralNew(DetailAST ast)
Visits NEW.- Parameters:
ast
- NEW to process.
-
addReferencedClassName
private void addReferencedClassName(DetailAST ast)
Adds new referenced class.- Parameters:
ast
- a node which represents referenced class.
-
addReferencedClassName
private void addReferencedClassName(java.lang.String referencedClassName)
Adds new referenced class.- Parameters:
referencedClassName
- class name of the referenced class.
-
checkCoupling
public void checkCoupling()
Checks if coupling less than allowed or not.
-
isSignificant
private boolean isSignificant(java.lang.String candidateClassName)
Checks if given class shouldn't be ignored and not from java.lang.- Parameters:
candidateClassName
- class to check.- Returns:
- true if we should count this class.
-
isFromExcludedPackage
private boolean isFromExcludedPackage(java.lang.String candidateClassName)
Checks if given class should be ignored as it belongs to excluded package.- Parameters:
candidateClassName
- class to check- Returns:
- true if we should not count this class.
-
getClassNameWithPackage
private java.util.Optional<java.lang.String> getClassNameWithPackage(java.lang.String examineClassName)
Retrieves class name with packages. Uses previously registered imports to get the full class name.- Parameters:
examineClassName
- Class name to be retrieved.- Returns:
- Class name with package name, if found,
Optional.empty()
otherwise.
-
isExcludedClassRegexp
private boolean isExcludedClassRegexp(java.lang.String candidateClassName)
Checks if given class should be ignored as it belongs to excluded class regexp.- Parameters:
candidateClassName
- class to check.- Returns:
- true if we should not count this class.
-
-