Clover Coverage Report - Checkstyle
Coverage timestamp: Fri May 9 2008 10:48:13 EST
../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
11   122   8   1.57
0   51   0.73   7
7     1.14  
1    
 
  AbstractFormatCheck       Line # 38 100% 1.0
8 11 8 8 0.73
 
  ( 10 of 94)
 
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.Check;
22    import com.puppycrawl.tools.checkstyle.api.Utils;
23   
24    import java.util.regex.Pattern;
25    import java.util.regex.PatternSyntaxException;
26   
27    import org.apache.commons.beanutils.ConversionException;
28   
29    /**
30    * <p> Abstract class for checks that verify strings using a
31    * {@link java.util.regex.Pattern regular expression}. It
32    * provides support for setting the regular
33    * expression using the property name <code>format</code>. </p>
34    *
35    * @author Oliver Burn
36    * @version 1.0
37    */
 
38    public abstract class AbstractFormatCheck
39    extends Check
40    {
41    /** the flags to create the regular expression with */
42    private int mCompileFlags;
43    /** the regexp to match against */
44    private Pattern mRegexp;
45    /** the format string of the regexp */
46    private String mFormat;
47   
48    /**
49    * Creates a new <code>AbstractFormatCheck</code> instance. Defaults the
50    * compile flag to 0 (the default).
51    * @param aDefaultFormat default format
52    * @throws ConversionException unable to parse aDefaultFormat
53    */
 
54  81 toggle public AbstractFormatCheck(String aDefaultFormat)
55    throws ConversionException
56    {
57  81 this(aDefaultFormat, 0);
58    }
59   
60    /**
61    * Creates a new <code>AbstractFormatCheck</code> instance.
62    * @param aDefaultFormat default format
63    * @param aCompileFlags the Pattern flags to compile the regexp with.
64    * See {@link Pattern#compile(java.lang.String, int)}
65    * @throws ConversionException unable to parse aDefaultFormat
66    */
 
67  103 toggle public AbstractFormatCheck(String aDefaultFormat, int aCompileFlags)
68    throws ConversionException
69    {
70  103 updateRegexp(aDefaultFormat, aCompileFlags);
71    }
72   
73    /**
74    * Set the format to the specified regular expression.
75    * @param aFormat a <code>String</code> value
76    * @throws ConversionException unable to parse aFormat
77    */
 
78  59 toggle public final void setFormat(String aFormat)
79    throws ConversionException
80    {
81  59 updateRegexp(aFormat, mCompileFlags);
82    }
83   
84    /**
85    * Set the compile flags for the regular expression.
86    * @param aCompileFlags the compile flags to use.
87    */
 
88  2 toggle public final void setCompileFlags(int aCompileFlags)
89    {
90  2 updateRegexp(mFormat, aCompileFlags);
91    }
92   
93    /** @return the regexp to match against */
 
94  1505 toggle public final Pattern getRegexp()
95    {
96  1505 return mRegexp;
97    }
98   
99    /** @return the regexp format */
 
100  165 toggle public final String getFormat()
101    {
102  165 return mFormat;
103    }
104   
105    /**
106    * Updates the regular expression using the supplied format and compiler
107    * flags. Will also update the member variables.
108    * @param aFormat the format of the regular expression.
109    * @param aCompileFlags the compiler flags to use.
110    */
 
111  164 toggle private void updateRegexp(String aFormat, int aCompileFlags)
112    {
113  164 try {
114  164 mRegexp = Utils.getPattern(aFormat, aCompileFlags);
115  163 mFormat = aFormat;
116  163 mCompileFlags |= aCompileFlags;
117    }
118    catch (final PatternSyntaxException e) {
119  1 throw new ConversionException("unable to parse " + aFormat, e);
120    }
121    }
122    }