|
1
|
|
//////////////////////////////////////////////////////////////////////////////// |
|
2
|
|
// checkstyle: Checks Java source code for adherence to a set of rules. |
|
3
|
|
// Copyright (C) 2001-2021 the original author or authors. |
|
4
|
|
// |
|
5
|
|
// This library is free software; you can redistribute it and/or |
|
6
|
|
// modify it under the terms of the GNU Lesser General Public |
|
7
|
|
// License as published by the Free Software Foundation; either |
|
8
|
|
// version 2.1 of the License, or (at your option) any later version. |
|
9
|
|
// |
|
10
|
|
// This library is distributed in the hope that it will be useful, |
|
11
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13
|
|
// Lesser General Public License for more details. |
|
14
|
|
// |
|
15
|
|
// You should have received a copy of the GNU Lesser General Public |
|
16
|
|
// License along with this library; if not, write to the Free Software |
|
17
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18
|
|
//////////////////////////////////////////////////////////////////////////////// |
|
19
|
|
|
|
20
|
|
package com.puppycrawl.tools.checkstyle.checks.imports; |
|
21
|
|
|
|
22
|
|
/** |
|
23
|
|
* Represents whether a package is allowed to be imported or not. |
|
24
|
|
*/ |
|
25
|
|
class PkgImportRule extends AbstractImportRule { |
|
26
|
|
|
|
27
|
|
/** Package to control access to. */ |
|
28
|
|
private final String pkgName; |
|
29
|
|
|
|
30
|
|
/** Indicates if the package name must be an exact match. */ |
|
31
|
|
private final boolean exactMatch; |
|
32
|
|
|
|
33
|
|
/** |
|
34
|
|
* Constructs an instance. |
|
35
|
|
* |
|
36
|
|
* @param allow whether to allow access. |
|
37
|
|
* @param localOnly whether the rule is to be applied locally only |
|
38
|
|
* @param pkgName the package to apply the rule on. |
|
39
|
|
* @param exactMatch whether the package name must match exactly. |
|
40
|
|
* @param regExp whether the package name is to be interpreted as a regular |
|
41
|
|
* expression. |
|
42
|
|
*/ |
|
43
|
|
/* package */ PkgImportRule(final boolean allow, final boolean localOnly, |
|
44
|
|
final String pkgName, final boolean exactMatch, final boolean regExp) { |
|
45
|
|
super(allow, localOnly, regExp); |
|
46
|
|
this.pkgName = pkgName; |
|
47
|
|
this.exactMatch = exactMatch; |
|
48
|
|
} |
|
49
|
|
|
|
50
|
|
/** |
|
51
|
|
* Verifies whether a package name is used. |
|
52
|
|
* |
|
53
|
|
* @param forImport the import to check. |
|
54
|
|
* @return a result {@link AccessResult} indicating whether it can be used. |
|
55
|
|
*/ |
|
56
|
|
@Override |
|
57
|
|
public AccessResult verifyImport(final String forImport) { |
|
58
|
|
// First check that we actually match the package. |
|
59
|
|
// Then check if matched and f we must be an exact match. |
|
60
|
|
// In this case, the text after the first "." must not contain |
|
61
|
|
// another "." as this indicates that it is not an exact match. |
|
62
|
|
|
|
63
|
|
boolean pkgMatch; |
|
64
|
|
|
|
65
|
3
1. verifyImport : negated conditional → KILLED
2. verifyImport : removed conditional - replaced equality check with false → KILLED
3. verifyImport : removed conditional - replaced equality check with true → KILLED
|
if (isRegExp()) { |
|
66
|
1
1. verifyImport : removed call to java/lang/StringBuilder::<init> → KILLED
|
pkgMatch = forImport.matches(pkgName + "\\..*"); |
|
67
|
|
|
|
68
|
6
1. verifyImport : negated conditional → KILLED
2. verifyImport : negated conditional → KILLED
3. verifyImport : removed conditional - replaced equality check with false → KILLED
4. verifyImport : removed conditional - replaced equality check with false → KILLED
5. verifyImport : removed conditional - replaced equality check with true → KILLED
6. verifyImport : removed conditional - replaced equality check with true → KILLED
|
if (pkgMatch && exactMatch) { |
|
69
|
4
1. verifyImport : removed call to java/lang/StringBuilder::<init> → KILLED
2. verifyImport : negated conditional → KILLED
3. verifyImport : removed conditional - replaced equality check with false → KILLED
4. verifyImport : removed conditional - replaced equality check with true → KILLED
|
pkgMatch = !forImport.matches(pkgName + "\\..*\\..*"); |
|
70
|
|
} |
|
71
|
|
} |
|
72
|
|
else { |
|
73
|
1
1. verifyImport : removed call to java/lang/StringBuilder::<init> → KILLED
|
pkgMatch = forImport.startsWith(pkgName + "."); |
|
74
|
|
|
|
75
|
6
1. verifyImport : negated conditional → KILLED
2. verifyImport : negated conditional → KILLED
3. verifyImport : removed conditional - replaced equality check with false → KILLED
4. verifyImport : removed conditional - replaced equality check with false → KILLED
5. verifyImport : removed conditional - replaced equality check with true → KILLED
6. verifyImport : removed conditional - replaced equality check with true → KILLED
|
if (pkgMatch && exactMatch) { |
|
76
|
3
1. verifyImport : negated conditional → KILLED
2. verifyImport : removed conditional - replaced equality check with false → KILLED
3. verifyImport : removed conditional - replaced equality check with true → KILLED
|
pkgMatch = forImport.indexOf('.', |
|
77
|
1
1. verifyImport : Replaced integer addition with subtraction → KILLED
|
pkgName.length() + 1) == -1; |
|
78
|
|
} |
|
79
|
|
} |
|
80
|
|
|
|
81
|
1
1. verifyImport : mutated return of Object value for com/puppycrawl/tools/checkstyle/checks/imports/PkgImportRule::verifyImport to ( if (x != null) null else throw new RuntimeException ) → KILLED
|
return calculateResult(pkgMatch); |
|
82
|
|
} |
|
83
|
|
|
|
84
|
|
} |
| | Mutations |
| 65 |
|
1.1 Location : verifyImport Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest]/[method:testPkgImportRuleNoRegexp()] negated conditional → KILLED 2.2 Location : verifyImport Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest]/[method:testPkgImportRuleExactMatchRegexp()] removed conditional - replaced equality check with false → KILLED 3.3 Location : verifyImport Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest]/[method:testPkgImportRuleNoRegexp()] removed conditional - replaced equality check with true → KILLED
|
| 66 |
|
1.1 Location : verifyImport Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest]/[method:testPkgImportRuleRegexpSimple()] removed call to java/lang/StringBuilder::<init> → KILLED
|
| 68 |
|
1.1 Location : verifyImport Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest]/[method:testPkgImportRuleExactMatchRegexp()] negated conditional → KILLED 2.2 Location : verifyImport Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest]/[method:testPkgImportRuleRegexpSimple()] negated conditional → KILLED 3.3 Location : verifyImport Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest]/[method:testPkgImportRuleExactMatchRegexp()] removed conditional - replaced equality check with false → KILLED 4.4 Location : verifyImport Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest]/[method:testPkgImportRuleExactMatchRegexp()] removed conditional - replaced equality check with false → KILLED 5.5 Location : verifyImport Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest]/[method:testPkgImportRuleExactMatchRegexp()] removed conditional - replaced equality check with true → KILLED 6.6 Location : verifyImport Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest]/[method:testPkgImportRuleRegexpSimple()] removed conditional - replaced equality check with true → KILLED
|
| 69 |
|
1.1 Location : verifyImport Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest]/[method:testPkgImportRuleExactMatchRegexp()] removed call to java/lang/StringBuilder::<init> → KILLED 2.2 Location : verifyImport Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest]/[method:testPkgImportRuleExactMatchRegexp()] negated conditional → KILLED 3.3 Location : verifyImport Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest]/[method:testPkgImportRuleExactMatchRegexp()] removed conditional - replaced equality check with false → KILLED 4.4 Location : verifyImport Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest]/[method:testPkgImportRuleExactMatchRegexp()] removed conditional - replaced equality check with true → KILLED
|
| 73 |
|
1.1 Location : verifyImport Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest]/[method:testPkgImportRule()] removed call to java/lang/StringBuilder::<init> → KILLED
|
| 75 |
|
1.1 Location : verifyImport Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest]/[method:testPkgImportRuleExactMatch()] negated conditional → KILLED 2.2 Location : verifyImport Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest]/[method:testPkgImportRule()] negated conditional → KILLED 3.3 Location : verifyImport Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest]/[method:testPkgImportRuleExactMatch()] removed conditional - replaced equality check with false → KILLED 4.4 Location : verifyImport Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest]/[method:testPkgImportRuleExactMatch()] removed conditional - replaced equality check with false → KILLED 5.5 Location : verifyImport Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest]/[method:testPkgImportRuleExactMatch()] removed conditional - replaced equality check with true → KILLED 6.6 Location : verifyImport Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest]/[method:testPkgImportRule()] removed conditional - replaced equality check with true → KILLED
|
| 76 |
|
1.1 Location : verifyImport Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest]/[method:testPkgImportRuleExactMatch()] negated conditional → KILLED 2.2 Location : verifyImport Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest]/[method:testPkgImportRuleExactMatch()] removed conditional - replaced equality check with false → KILLED 3.3 Location : verifyImport Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest]/[method:testPkgImportRuleExactMatch()] removed conditional - replaced equality check with true → KILLED
|
| 77 |
|
1.1 Location : verifyImport Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest]/[method:testPkgImportRuleExactMatch()] Replaced integer addition with subtraction → KILLED
|
| 81 |
|
1.1 Location : verifyImport Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest]/[method:testPkgImportRule()] mutated return of Object value for com/puppycrawl/tools/checkstyle/checks/imports/PkgImportRule::verifyImport to ( if (x != null) null else throw new RuntimeException ) → KILLED
|