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/FileLengthCheck.java


1   ////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code for adherence to a set of rules.
3   // Copyright (C) 2001-2002  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  
20  package com.puppycrawl.tools.checkstyle.checks;
21  
22  import com.puppycrawl.tools.checkstyle.api.Check;
23  
24  /**
25   * <p>
26   * Checks for long source files.
27   * </p>
28   * <p>
29   * Rationale: If a source file becomes very long it is hard to understand.
30   * Therefore long classes should usually be refactored into several
31   * individual classes that focus on a specific task.
32   * </p>
33   * <p>
34   * The default maximum file length is 2000 lines. To change the maximum
35   * number of lines, set property max.
36   * </p>
37   * <p>
38   * An example of how to configure the check is:
39   * </p>
40   * <pre>
41   * &lt;module name="FileLength"/&gt;
42   * </pre>
43   * <p>
44   * An example of how to configure the check so that it accepts files with at
45   * most 1500 lines is:
46   * </p>
47   * <pre>
48   * &lt;module name="FileLength"&gt;
49   *    &lt;property name="max" value="1500"/&gt;
50   * &lt;/module&gt;
51   * </pre>
52   * @author Lars Kühne
53   */
54  public class FileLengthCheck extends Check
55  {
56      /** the maximum number of lines */
57      private int mMaxFileLength = 2000;
58  
59      /** @see com.puppycrawl.tools.checkstyle.api.Check */
60      public int[] getDefaultTokens()
61      {
62          return new int[0];
63      }
64  
65      /** @see com.puppycrawl.tools.checkstyle.api.Check */
66      public void beginTree()
67      {
68          final String[] lines = getLines();
69          if (lines.length > mMaxFileLength) {
70              log(1, "maxLen.file",
71                      new Integer(lines.length),
72                      new Integer(mMaxFileLength));
73          }
74      }
75  
76      /**
77       * @param aLength the maximum length of a Java source file
78       */
79      public void setMax(int aLength)
80      {
81          mMaxFileLength = aLength;
82      }
83  
84  }