AbstractImportRule.java

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
 * Base class for import rules.
24
 */
25
abstract class AbstractImportRule {
26
27
    /** Indicates whether to allow access or not. */
28
    private final boolean allowed;
29
30
    /** Indicates if the rule only applies to this package. */
31
    private final boolean localOnly;
32
33
    /**
34
     * Indicates if the name is to be interpreted
35
     * as a regular expression.
36
     */
37
    private final boolean regExp;
38
39
    /**
40
     * Constructs an instance.
41
     *
42
     * @param allow whether to allow access.
43
     * @param localOnly whether the rule is to be applied locally only.
44
     * @param regExp whether the name is to be interpreted as a regular
45
     *        expression.
46
     */
47
    protected AbstractImportRule(final boolean allow, final boolean localOnly,
48
        final boolean regExp) {
49
        allowed = allow;
50
        this.localOnly = localOnly;
51
        this.regExp = regExp;
52
    }
53
54
    /**
55
     * Verifies whether a package name is used.
56
     *
57
     * @param forImport the import to check.
58
     * @return a result {@link AccessResult} indicating whether it can be used.
59
     */
60
    public abstract AccessResult verifyImport(String forImport);
61
62
    /**
63
     * Return true if the guard is to only be applied locally or false.
64
     *
65
     * @return whether the guard is to only be applied locally.
66
     */
67
    public boolean isLocalOnly() {
68 3 1. isLocalOnly : replaced boolean return with false for com/puppycrawl/tools/checkstyle/checks/imports/AbstractImportRule::isLocalOnly → KILLED
2. isLocalOnly : replaced boolean return with true for com/puppycrawl/tools/checkstyle/checks/imports/AbstractImportRule::isLocalOnly → KILLED
3. isLocalOnly : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED
        return localOnly;
69
    }
70
71
    /**
72
     * Return true if the name is to be interpreted as a regular expression or false.
73
     *
74
     * @return whether the name is to be interpreted as a regular expression.
75
     */
76
    protected boolean isRegExp() {
77 3 1. isRegExp : replaced boolean return with false for com/puppycrawl/tools/checkstyle/checks/imports/AbstractImportRule::isRegExp → KILLED
2. isRegExp : replaced boolean return with true for com/puppycrawl/tools/checkstyle/checks/imports/AbstractImportRule::isRegExp → KILLED
3. isRegExp : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED
        return regExp;
78
    }
79
80
    /**
81
     * Returns the appropriate {@link AccessResult} based on whether there
82
     * was a match and if the rule is to allow access.
83
     *
84
     * @param matched indicates whether there was a match.
85
     * @return An appropriate {@link AccessResult}.
86
     */
87
    protected AccessResult calculateResult(final boolean matched) {
88
        AccessResult result = AccessResult.UNKNOWN;
89
90 3 1. calculateResult : negated conditional → KILLED
2. calculateResult : removed conditional - replaced equality check with false → KILLED
3. calculateResult : removed conditional - replaced equality check with true → KILLED
        if (matched) {
91 3 1. calculateResult : negated conditional → KILLED
2. calculateResult : removed conditional - replaced equality check with false → KILLED
3. calculateResult : removed conditional - replaced equality check with true → KILLED
            if (allowed) {
92
                result = AccessResult.ALLOWED;
93
            }
94
            else {
95
                result = AccessResult.DISALLOWED;
96
            }
97
        }
98
99 1 1. calculateResult : mutated return of Object value for com/puppycrawl/tools/checkstyle/checks/imports/AbstractImportRule::calculateResult to ( if (x != null) null else throw new RuntimeException ) → KILLED
        return result;
100
    }
101
102
}

Mutations

68

1.1
Location : isLocalOnly
Killed by : com.puppycrawl.tools.checkstyle.checks.imports.ImportControlCheckTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.ImportControlCheckTest]/[method:testOne()]
replaced boolean return with false for com/puppycrawl/tools/checkstyle/checks/imports/AbstractImportRule::isLocalOnly → KILLED

2.2
Location : isLocalOnly
Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportControlTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportControlTest]/[method:testCheckAccess()]
replaced boolean return with true for com/puppycrawl/tools/checkstyle/checks/imports/AbstractImportRule::isLocalOnly → KILLED

3.3
Location : isLocalOnly
Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportControlTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportControlTest]/[method:testCheckAccess()]
replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED

77

1.1
Location : isRegExp
Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest]/[method:testPkgImportRuleExactMatchRegexp()]
replaced boolean return with false for com/puppycrawl/tools/checkstyle/checks/imports/AbstractImportRule::isRegExp → KILLED

2.2
Location : isRegExp
Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest]/[method:testPkgImportRuleNoRegexp()]
replaced boolean return with true for com/puppycrawl/tools/checkstyle/checks/imports/AbstractImportRule::isRegExp → KILLED

3.3
Location : isRegExp
Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportRuleTest]/[method:testPkgImportRuleNoRegexp()]
replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED

90

1.1
Location : calculateResult
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

2.2
Location : calculateResult
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 false → KILLED

3.3
Location : calculateResult
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

91

1.1
Location : calculateResult
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

2.2
Location : calculateResult
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 false → KILLED

3.3
Location : calculateResult
Killed by : com.puppycrawl.tools.checkstyle.checks.imports.PkgImportControlTest.[engine:junit-jupiter]/[class:com.puppycrawl.tools.checkstyle.checks.imports.PkgImportControlTest]/[method:testCheckAccess()]
removed conditional - replaced equality check with true → KILLED

99

1.1
Location : calculateResult
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/AbstractImportRule::calculateResult to ( if (x != null) null else throw new RuntimeException ) → KILLED

Active mutators

Tests examined


Report generated by PIT 1.6.3