class PkgImportControl extends AbstractImportControl
| Modifier and Type | Field and Description |
|---|---|
private java.util.List<AbstractImportControl> |
children
List of children
AbstractImportControl objects. |
private static java.lang.String |
DOT
The package separator: "."
|
private static java.lang.String |
DOT_ESCAPED_REGEX
The regex for the escaped package separator: "\\\\.".
|
private static java.lang.String |
DOT_REGEX
The regex for the package separator: "\\.".
|
private static java.util.regex.Pattern |
DOT_REGEX_PATTERN
A pattern matching the package separator: "\."
|
private java.lang.String |
fullPackageName
The full name for the package.
|
private java.util.regex.Pattern |
patternForExactMatch
The regex pattern for exact matches - only not null if regex is true.
|
private java.util.regex.Pattern |
patternForPartialMatch
The regex pattern for partial match (exact and for subpackages) - only not
null if regex is true.
|
private boolean |
regex
If this package represents a regular expression.
|
| Constructor and Description |
|---|
PkgImportControl(PkgImportControl parent,
java.lang.String subPackageName,
boolean regex,
MismatchStrategy strategyOnMismatch)
Construct a sub-package node.
|
PkgImportControl(java.lang.String packageName,
boolean regex,
MismatchStrategy strategyOnMismatch)
Construct a root, package node.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addChild(AbstractImportControl importControl)
Adds new child import control.
|
private static java.util.regex.Pattern |
createPatternForExactMatch(java.lang.String expression)
Creates a Pattern from
expression. |
private static java.util.regex.Pattern |
createPatternForPartialMatch(java.lang.String expression)
Creates a Pattern from
expression that matches exactly and child packages. |
private static java.lang.String |
encloseInGroup(java.lang.String expression)
Enclose
expression in a (non-capturing) group. |
private static java.lang.String |
ensureSelfContainedRegex(java.lang.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 enclosing
input in
a (non-capturing) group if input already is a regular expression. |
AbstractImportControl |
locateFinest(java.lang.String forPkg,
java.lang.String forFileName)
Search down the tree to locate the finest match for a supplied package.
|
private boolean |
matchesAtFront(java.lang.String pkg)
Matches other package name exactly or partially at front.
|
private boolean |
matchesAtFrontNoRegex(java.lang.String pkg)
Non-regex case.
|
protected boolean |
matchesExactly(java.lang.String pkg,
java.lang.String fileName)
Check for equality of this with pkg.
|
private static java.lang.String |
toRegex(java.lang.String input)
Converts a normal package name into a regex pattern by escaping all
special characters that may occur in a java package name.
|
addImportRule, checkAccessprivate static final java.lang.String DOT
private static final java.lang.String DOT_REGEX
private static final java.util.regex.Pattern DOT_REGEX_PATTERN
private static final java.lang.String DOT_ESCAPED_REGEX
private final java.util.List<AbstractImportControl> children
AbstractImportControl objects.private final java.lang.String fullPackageName
private final java.util.regex.Pattern patternForPartialMatch
private final java.util.regex.Pattern patternForExactMatch
private final boolean regex
PkgImportControl(java.lang.String packageName, boolean regex, MismatchStrategy strategyOnMismatch)
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.PkgImportControl(PkgImportControl parent, java.lang.String subPackageName, boolean regex, MismatchStrategy strategyOnMismatch)
ensureSelfContainedRegex(String, boolean) for more details.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.private static java.lang.String ensureSelfContainedRegex(java.lang.String input, boolean alreadyRegex)
input in
a (non-capturing) group if input already 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) input is 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.
input - the input string.alreadyRegex - signals if input already is a regular expression.private static java.lang.String encloseInGroup(java.lang.String expression)
expression in a (non-capturing) group.expression - the input regular expressionprivate static java.lang.String toRegex(java.lang.String input)
input - the input string.private static java.util.regex.Pattern createPatternForPartialMatch(java.lang.String expression)
expression that matches exactly and child packages.expression - a self-contained regular expression matching the full package exactly.private static java.util.regex.Pattern createPatternForExactMatch(java.lang.String expression)
expression.expression - a self-contained regular expression matching the full package exactly.public AbstractImportControl locateFinest(java.lang.String forPkg, java.lang.String forFileName)
AbstractImportControllocateFinest in class AbstractImportControlforPkg - the package to search for.forFileName - the file name to search for.public void addChild(AbstractImportControl importControl)
importControl - child import controlprivate boolean matchesAtFront(java.lang.String pkg)
pkg - the package to compare with.private boolean matchesAtFrontNoRegex(java.lang.String pkg)
pkg - the package to compare with.protected boolean matchesExactly(java.lang.String pkg, java.lang.String fileName)
AbstractImportControlmatchesExactly in class AbstractImportControlpkg - the package to compare with.fileName - the file name to compare with.Copyright © 2001-2022. All Rights Reserved.