Clover Coverage Report - Checkstyle
Coverage timestamp: Fri May 9 2008 10:48:13 EST
../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
9   72   5   3
4   26   0.56   3
3     1.67  
1    
 
  RequiredRegexpCheck       Line # 41 100% 1.0
5 9 5 5 0.56
 
  (3)
 
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    * &lt;module name="RequiredRegexp"&gt;
36    * &lt;property name="format" value="This code is copyrighted"/&gt;
37    * &lt;/module&gt;
38    * </pre>
39    * @author Daniel Grenner
40    */
 
41    public class RequiredRegexpCheck extends AbstractFormatCheck
42    {
43    /**
44    * Instantiates an new GenericIllegalRegexpCheck.
45    */
 
46  3 toggle public RequiredRegexpCheck()
47    {
48  3 super("$^"); // the empty language
49    }
50   
51    /** {@inheritDoc} */
 
52  3 toggle public int[] getDefaultTokens()
53    {
54  3 return new int[0];
55    }
56   
57    /** {@inheritDoc} */
 
58  3 toggle 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