Class AbstractImportControl
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.checks.imports.AbstractImportControl
-
- Direct Known Subclasses:
FileImportControl,PkgImportControl
abstract class AbstractImportControl extends java.lang.Object
Represents a tree of import rules for controlling whether packages or classes are allowed to be used. Each instance must have a single parent or be the root node.
-
-
Field Summary
Fields Modifier and Type Field Description private AbstractImportControlparentThe parent.private java.util.Deque<AbstractImportRule>rulesList ofAbstractImportRuleobjects to check.private MismatchStrategystrategyOnMismatchStrategy in a case if matching allow/disallow rule was not found.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractImportControl(AbstractImportControl parent, MismatchStrategy strategyOnMismatch)Construct a child node.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidaddImportRule(AbstractImportRule rule)Adds anAbstractImportRuleto the node.AccessResultcheckAccess(java.lang.String inPkg, java.lang.String inFileName, java.lang.String forImport)Returns whether a package or class is allowed to be imported.private AccessResultlocalCheckAccess(java.lang.String inPkg, java.lang.String inFileName, java.lang.String forImport)Checks whether any of the rules for this node control access to a specified package or file.abstract AbstractImportControllocateFinest(java.lang.String forPkg, java.lang.String forFileName)Search down the tree to locate the finest match for a supplied package.protected abstract booleanmatchesExactly(java.lang.String pkg, java.lang.String fileName)Check for equality of this with pkg.
-
-
-
Field Detail
-
rules
private final java.util.Deque<AbstractImportRule> rules
List ofAbstractImportRuleobjects to check.
-
parent
private final AbstractImportControl parent
The parent. Null indicates we are the root node.
-
strategyOnMismatch
private final MismatchStrategy strategyOnMismatch
Strategy in a case if matching allow/disallow rule was not found.
-
-
Constructor Detail
-
AbstractImportControl
protected AbstractImportControl(AbstractImportControl parent, MismatchStrategy strategyOnMismatch)
Construct a child node.- Parameters:
parent- the parent node.strategyOnMismatch- strategy in a case if matching allow/disallow rule was not found.
-
-
Method Detail
-
locateFinest
public abstract AbstractImportControl locateFinest(java.lang.String forPkg, java.lang.String forFileName)
Search down the tree to locate the finest match for a supplied package.- Parameters:
forPkg- the package to search for.forFileName- the file name to search for.- Returns:
- the finest match, or null if no match at all.
-
matchesExactly
protected abstract boolean matchesExactly(java.lang.String pkg, java.lang.String fileName)
Check for equality of this with pkg.- Parameters:
pkg- the package to compare with.fileName- the file name to compare with.- Returns:
- if it matches.
-
addImportRule
protected void addImportRule(AbstractImportRule rule)
Adds anAbstractImportRuleto the node.- Parameters:
rule- the rule to be added.
-
checkAccess
public AccessResult checkAccess(java.lang.String inPkg, java.lang.String inFileName, java.lang.String forImport)
Returns whether a package or class is allowed to be imported. The algorithm checks with the current node for a result, and if none is found then calls its parent looking for a match. This will recurse looking for match. If there is no clear result thenAccessResult.UNKNOWNis returned.- Parameters:
inPkg- the package doing the import.inFileName- the file name doing the import.forImport- the import to check on.- Returns:
- an
AccessResult.
-
localCheckAccess
private AccessResult localCheckAccess(java.lang.String inPkg, java.lang.String inFileName, java.lang.String forImport)
Checks whether any of the rules for this node control access to a specified package or file.- Parameters:
inPkg- the package doing the import.inFileName- the file name doing the import.forImport- the import to check on.- Returns:
- an
AccessResult.
-
-