Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
FileLengthCheck |
|
| 1.5;1.5 |
1 | //////////////////////////////////////////////////////////////////////////////// | |
2 | // checkstyle: Checks Java source code for adherence to a set of rules. | |
3 | // Copyright (C) 2001-2014 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.sizes; | |
20 | ||
21 | import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck; | |
22 | import java.io.File; | |
23 | import java.util.List; | |
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 | * <module name="FileLength"/> | |
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 | * <module name="FileLength"> | |
50 | * <property name="max" value="1500"/> | |
51 | * </module> | |
52 | * </pre> | |
53 | * @author Lars Kühne | |
54 | */ | |
55 | 3 | public class FileLengthCheck extends AbstractFileSetCheck |
56 | { | |
57 | /** default maximum number of lines */ | |
58 | private static final int DEFAULT_MAX_LINES = 2000; | |
59 | ||
60 | /** the maximum number of lines */ | |
61 | 3 | private int mMaxFileLength = DEFAULT_MAX_LINES; |
62 | ||
63 | @Override | |
64 | protected void processFiltered(File aFile, List<String> aLines) | |
65 | { | |
66 | 2 | if (aLines.size() > mMaxFileLength) { |
67 | 1 | log(1, "maxLen.file", aLines.size(), mMaxFileLength); |
68 | } | |
69 | 2 | } |
70 | ||
71 | /** | |
72 | * @param aLength the maximum length of a Java source file | |
73 | */ | |
74 | public void setMax(int aLength) | |
75 | { | |
76 | 2 | mMaxFileLength = aLength; |
77 | 2 | } |
78 | ||
79 | } |