Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/puppycrawl/tools/checkstyle/checks/AbstractFormatCheck.java


1   ////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code for adherence to a set of rules.
3   // Copyright (C) 2001-2003  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  import org.apache.regexp.RESyntaxException;
24  import org.apache.regexp.RE;
25  import org.apache.commons.beanutils.ConversionException;
26  
27  /**
28   * <p> Abstract class for checks that verify strings using a <a
29   * href="http://jakarta.apache.org/regexp/apidocs/org/apache/regexp/RE.html">
30   * regular expression</a>.  It provides support for setting the regular
31   * expression using the property name <code>format</code>.  </p>
32   *
33   * @author Oliver Burn
34   * @version 1.0
35   */
36  public abstract class AbstractFormatCheck
37      extends Check
38  {
39      /** the regexp to match against */
40      private RE mRegexp;
41      /** the format string of the regexp */
42      private String mFormat;
43  
44      /**
45       * Creates a new <code>AbstractFormatCheck</code> instance.
46       * @param aDefaultFormat default format
47       * @throws ConversionException unable to parse aDefaultFormat
48       */
49      public AbstractFormatCheck(String aDefaultFormat)
50          throws ConversionException
51      {
52          setFormat(aDefaultFormat);
53      }
54  
55      /**
56       * Set the format to the specified regular expression.
57       * @param aFormat a <code>String</code> value
58       * @throws ConversionException unable to parse aFormat
59       */
60      public void setFormat(String aFormat)
61          throws ConversionException
62      {
63          try {
64              mRegexp = Utils.getRE(aFormat);
65              mFormat = aFormat;
66          }
67          catch (RESyntaxException e) {
68              throw new ConversionException("unable to parse " + aFormat, e);
69          }
70      }
71  
72      /** @return the regexp to match against */
73      public RE getRegexp()
74      {
75          return mRegexp;
76      }
77  
78      /** @return the regexp format */
79      public String getFormat()
80      {
81          return mFormat;
82      }
83  }