|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RequiredRegexpCheck | Line # 41 | 100% |
1.0
|
5 | 9 | 5 | 5 | 0.56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (3) | |||
| Result | |||
|
0.875
|
com.puppycrawl.tools.checkstyle.checks.RequiredRegexpCheckTest.testMissing
com.puppycrawl.tools.checkstyle.checks.RequiredRegexpCheckTest.testMissing
|
1 PASS | |
|
0.875
|
com.puppycrawl.tools.checkstyle.checks.RequiredRegexpCheckTest.testExistingInCode
com.puppycrawl.tools.checkstyle.checks.RequiredRegexpCheckTest.testExistingInCode
|
1 PASS | |
|
0.875
|
com.puppycrawl.tools.checkstyle.checks.RequiredRegexpCheckTest.testExistingInDoc
com.puppycrawl.tools.checkstyle.checks.RequiredRegexpCheckTest.testExistingInDoc
|
1 PASS | |
| 1 | //////////////////////////////////////////////////////////////////////////////// | |
| 2 | // checkstyle: Checks Java source code for adherence to a set of rules. | |
| 3 | // Copyright (C) 2001-2005 Oliver Burn | |
| 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 | package com.puppycrawl.tools.checkstyle.checks; | |
| 20 | ||
| 21 | import com.puppycrawl.tools.checkstyle.api.DetailAST; | |
| 22 | ||
| 23 | import java.util.regex.Pattern; | |
| 24 | ||
| 25 | /** | |
| 26 | * <p> | |
| 27 | * A check that makes sure that a specified pattern exists in the code. | |
| 28 | * </p> | |
| 29 | * <p> | |
| 30 | * An example of how to configure the check to make sure a copyright statement | |
| 31 | * is included in the file (but without requirements on where in the file | |
| 32 | * it should be): | |
| 33 | * </p> | |
| 34 | * <pre> | |
| 35 | * <module name="RequiredRegexp"> | |
| 36 | * <property name="format" value="This code is copyrighted"/> | |
| 37 | * </module> | |
| 38 | * </pre> | |
| 39 | * @author Daniel Grenner | |
| 40 | */ | |
| 41 | public class RequiredRegexpCheck extends AbstractFormatCheck | |
| 42 | { | |
| 43 | /** | |
| 44 | * Instantiates an new GenericIllegalRegexpCheck. | |
| 45 | */ | |
| 46 | 3 |
public RequiredRegexpCheck() |
| 47 | { | |
| 48 | 3 | super("$^"); // the empty language |
| 49 | } | |
| 50 | ||
| 51 | /** {@inheritDoc} */ | |
| 52 | 3 |
public int[] getDefaultTokens() |
| 53 | { | |
| 54 | 3 | return new int[0]; |
| 55 | } | |
| 56 | ||
| 57 | /** {@inheritDoc} */ | |
| 58 | 3 |
public void beginTree(DetailAST aRootAST) |
| 59 | { | |
| 60 | 3 | final Pattern pattern = getRegexp(); |
| 61 | 3 | final String[] lines = getLines(); |
| 62 | 205 | for (int i = 0; i < lines.length; i++) { |
| 63 | ||
| 64 | 204 | final String line = lines[i]; |
| 65 | 204 | if (pattern.matcher(line).find()) { |
| 66 | 2 | return; |
| 67 | } | |
| 68 | } | |
| 69 | 1 | log(0, "required.regexp", getFormat()); |
| 70 | } | |
| 71 | } | |
| 72 | ||
|
|||||||||||||