Class PkgImportControl
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprivate final List<AbstractImportControl>List of childrenAbstractImportControlobjects.private static final StringThe package separator: ".".private static final StringThe regex for the escaped package separator: "\\\\.".private static final StringThe regex for the package separator: "\\.".private static final PatternA pattern matching the package separator: "\.".private final StringThe full name for the package.private final PatternThe regex pattern for exact matches - only not null if regex is true.private final PatternThe regex pattern for partial match (exact and for subpackages) - only not null if regex is true.private final booleanIf this package represents a regular expression.
- 
Constructor SummaryConstructorsConstructorDescriptionPkgImportControl(PkgImportControl parent, String subPackageName, boolean regex, MismatchStrategy strategyOnMismatch) Construct a sub-package node.PkgImportControl(String packageName, boolean regex, MismatchStrategy strategyOnMismatch) Construct a root, package node.
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddChild(AbstractImportControl importControl) Adds new child import control.private static PatterncreatePatternForExactMatch(String expression) Creates a Pattern fromexpression.private static PatterncreatePatternForPartialMatch(String expression) Creates a Pattern fromexpressionthat matches exactly and child packages.private static StringencloseInGroup(String expression) Encloseexpressionin a (non-capturing) group.private static StringensureSelfContainedRegex(String input, boolean alreadyRegex) Returns a regex that is suitable for concatenation by 1) either converting a plain string into a regular expression (handling special characters) or 2) by enclosinginputin a (non-capturing) group ifinputalready is a regular expression.locateFinest(String forPkg, String forFileName) Search down the tree to locate the finest match for a supplied package.private booleanmatchesAtFront(String pkg) Matches other package name exactly or partially at front.private booleanNon-regex case.protected booleanmatchesExactly(String pkg, String fileName) Check for equality of this with pkg.private static StringConverts a normal package name into a regex pattern by escaping all special characters that may occur in a java package name.Methods inherited from class com.puppycrawl.tools.checkstyle.checks.imports.AbstractImportControladdImportRule, checkAccess
- 
Field Details- 
DOTThe package separator: ".".- See Also:
 
- 
DOT_REGEXThe regex for the package separator: "\\.".- See Also:
 
- 
DOT_REGEX_PATTERNA pattern matching the package separator: "\.".
- 
DOT_ESCAPED_REGEXThe regex for the escaped package separator: "\\\\.".- See Also:
 
- 
childrenList of childrenAbstractImportControlobjects.
- 
fullPackageNameThe full name for the package.
- 
patternForPartialMatchThe regex pattern for partial match (exact and for subpackages) - only not null if regex is true.
- 
patternForExactMatchThe regex pattern for exact matches - only not null if regex is true.
- 
regexIf this package represents a regular expression.
 
- 
- 
Constructor Details- 
PkgImportControlPkgImportControl(String packageName, boolean regex, MismatchStrategy strategyOnMismatch) Construct a root, package node.- Parameters:
- packageName- the name of the package.
- regex- flags interpretation of name as regex pattern.
- strategyOnMismatch- strategy in a case if matching allow/disallow rule was not found.
 
- 
PkgImportControlPkgImportControl(PkgImportControl parent, String subPackageName, boolean regex, MismatchStrategy strategyOnMismatch) Construct a sub-package node. The concatenation of regular expressions needs special care: seeensureSelfContainedRegex(String, boolean)for more details.- Parameters:
- parent- the parent package.
- subPackageName- the name of the current sub-package.
- regex- flags interpretation of name as regex pattern.
- strategyOnMismatch- strategy in a case if matching allow/disallow rule was not found.
 
 
- 
- 
Method Details- 
ensureSelfContainedRegexReturns a regex that is suitable for concatenation by 1) either converting a plain string into a regular expression (handling special characters) or 2) by enclosinginputin a (non-capturing) group ifinputalready is a regular expression.1) When concatenating a non-regex package component (like "org.google") with a regex component (like "[^.]+") the other component has to be converted into a regex too, see toRegex(String).2) The grouping is strictly necessary if a) inputis a regular expression that b) contains the alteration character ('|') and if c) the pattern is not already enclosed in a group - as you see in this example:parent="com|org", child="common|uncommon"will result in the pattern"(?:org|com)\.(?common|uncommon)"what will match"com.common","com.uncommon","org.common", and"org.uncommon". Without the grouping it would be"com|org.common|uncommon"which would match"com","org.common", and"uncommon", which clearly is undesirable. Adding the group fixes this.For simplicity the grouping is added to regular expressions unconditionally. - Parameters:
- input- the input string.
- alreadyRegex- signals if input already is a regular expression.
- Returns:
- a regex string.
 
- 
encloseInGroupEncloseexpressionin a (non-capturing) group.- Parameters:
- expression- the input regular expression
- Returns:
- a grouped pattern.
 
- 
toRegexConverts a normal package name into a regex pattern by escaping all special characters that may occur in a java package name.- Parameters:
- input- the input string.
- Returns:
- a regex string.
 
- 
createPatternForPartialMatchCreates a Pattern fromexpressionthat matches exactly and child packages.- Parameters:
- expression- a self-contained regular expression matching the full package exactly.
- Returns:
- a Pattern.
 
- 
createPatternForExactMatchCreates a Pattern fromexpression.- Parameters:
- expression- a self-contained regular expression matching the full package exactly.
- Returns:
- a Pattern.
 
- 
locateFinestDescription copied from class:AbstractImportControlSearch down the tree to locate the finest match for a supplied package.- Specified by:
- locateFinestin class- AbstractImportControl
- 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.
 
- 
addChildAdds new child import control.- Parameters:
- importControl- child import control
 
- 
matchesAtFrontMatches other package name exactly or partially at front.- Parameters:
- pkg- the package to compare with.
- Returns:
- if it matches.
 
- 
matchesAtFrontNoRegexNon-regex case. Ensure a trailing dot for subpackages, i.e. "com.puppy" will match "com.puppy.crawl" but not "com.puppycrawl.tools".- Parameters:
- pkg- the package to compare with.
- Returns:
- if it matches.
 
- 
matchesExactlyDescription copied from class:AbstractImportControlCheck for equality of this with pkg.- Specified by:
- matchesExactlyin class- AbstractImportControl
- Parameters:
- pkg- the package to compare with.
- fileName- the file name to compare with.
- Returns:
- if it matches.
 
 
-