KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > checks > sizes > FileLengthCheck


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

20 package com.puppycrawl.tools.checkstyle.checks.sizes;
21
22 import com.puppycrawl.tools.checkstyle.api.Check;
23 import com.puppycrawl.tools.checkstyle.api.DetailAST;
24
25 /**
26  * <p>
27  * Checks for long source files.
28  * </p>
29  * <p>
30  * Rationale: If a source file becomes very long it is hard to understand.
31  * Therefore long classes should usually be refactored into several
32  * individual classes that focus on a specific task.
33  * </p>
34  * <p>
35  * The default maximum file length is 2000 lines. To change the maximum
36  * number of lines, set property max.
37  * </p>
38  * <p>
39  * An example of how to configure the check is:
40  * </p>
41  * <pre>
42  * &lt;module name="FileLength"/&gt;
43  * </pre>
44  * <p>
45  * An example of how to configure the check so that it accepts files with at
46  * most 1500 lines is:
47  * </p>
48  * <pre>
49  * &lt;module name="FileLength"&gt;
50  * &lt;property name="max" value="1500"/&gt;
51  * &lt;/module&gt;
52  * </pre>
53  * @author Lars Kühne
54  */

55 public class FileLengthCheck extends Check
56 {
57     /** default maximum number of lines */
58     private static final int DEFAULT_MAX_LINES = 2000;
59
60     /** the maximum number of lines */
61     private int mMaxFileLength = DEFAULT_MAX_LINES;
62
63     /** {@inheritDoc} */
64     public int[] getDefaultTokens()
65     {
66         return new int[0];
67     }
68
69     /** {@inheritDoc} */
70     public void beginTree(DetailAST aRootAST)
71     {
72         final String JavaDoc[] lines = getLines();
73         if (lines.length > mMaxFileLength) {
74             log(1, "maxLen.file",
75                     new Integer JavaDoc(lines.length),
76                     new Integer JavaDoc(mMaxFileLength));
77         }
78     }
79
80     /**
81      * @param aLength the maximum length of a Java source file
82      */

83     public void setMax(int aLength)
84     {
85         mMaxFileLength = aLength;
86     }
87
88 }
89
Popular Tags