| 1 | //////////////////////////////////////////////////////////////////////////////// | |
| 2 | // checkstyle: Checks Java source code for adherence to a set of rules. | |
| 3 | // Copyright (C) 2001-2017 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 |  * @author Oliver Burn | |
| 25 |  */ | |
| 26 | class PkgImportRule extends AbstractImportRule { | |
| 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 |      * @param allow whether to allow access. | |
| 36 |      * @param localOnly whether the rule is to be applied locally only | |
| 37 |      * @param pkgName the package to apply the rule on. | |
| 38 |      * @param exactMatch whether the package name must match exactly. | |
| 39 |      * @param regExp whether the package name is to be interpreted as a regular | |
| 40 |      *        expression. | |
| 41 |      */ | |
| 42 |     PkgImportRule(final boolean allow, final boolean localOnly, | |
| 43 |         final String pkgName, final boolean exactMatch, final boolean regExp) { | |
| 44 |         super(allow, localOnly, regExp); | |
| 45 |         this.pkgName = pkgName; | |
| 46 |         this.exactMatch = exactMatch; | |
| 47 |     } | |
| 48 | ||
| 49 |     /** | |
| 50 |      * Verifies whether a package name is used. | |
| 51 |      * @param forImport the import to check. | |
| 52 |      * @return a result {@link AccessResult} indicating whether it can be used. | |
| 53 |      */ | |
| 54 |     @Override | |
| 55 |     public AccessResult verifyImport(final String forImport) { | |
| 56 |         // First check that we actually match the package. | |
| 57 |         // Then check if matched and f we must be an exact match. | |
| 58 |         // In this case, the text after the first "." must not contain | |
| 59 |         // another "." as this indicates that it is not an exact match. | |
| 60 | ||
| 61 |         boolean pkgMatch; | |
| 62 | ||
| 63 | 
1
1. verifyImport : negated conditional → KILLED | 
        if (isRegExp()) { | 
| 64 |             pkgMatch = forImport.matches(pkgName + "\\..*"); | |
| 65 | ||
| 66 | 
2
1. verifyImport : negated conditional → KILLED 2. verifyImport : negated conditional → KILLED  | 
            if (pkgMatch && exactMatch) { | 
| 67 | 
1
1. verifyImport : negated conditional → KILLED | 
                pkgMatch = !forImport.matches(pkgName + "\\..*\\..*"); | 
| 68 |             } | |
| 69 |         } | |
| 70 |         else { | |
| 71 |             pkgMatch = forImport.startsWith(pkgName + "."); | |
| 72 | ||
| 73 | 
2
1. verifyImport : negated conditional → KILLED 2. verifyImport : negated conditional → KILLED  | 
            if (pkgMatch && exactMatch) { | 
| 74 | 
1
1. verifyImport : negated conditional → KILLED | 
                pkgMatch = forImport.indexOf('.', | 
| 75 | 
1
1. verifyImport : Replaced integer addition with subtraction → KILLED | 
                        pkgName.length() + 1) == -1; | 
| 76 |             } | |
| 77 |         } | |
| 78 | ||
| 79 | 
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); | 
| 80 |     } | |
| 81 | } | |
Mutations | ||
| 63 | 
 
 1.1  | 
|
| 66 | 
 
 1.1 2.2  | 
|
| 67 | 
 
 1.1  | 
|
| 73 | 
 
 1.1 2.2  | 
|
| 74 | 
 
 1.1  | 
|
| 75 | 
 
 1.1  | 
|
| 79 | 
 
 1.1  |