001//////////////////////////////////////////////////////////////////////////////// 002// checkstyle: Checks Java source code for adherence to a set of rules. 003// Copyright (C) 2001-2014 Oliver Burn 004// 005// This library is free software; you can redistribute it and/or 006// modify it under the terms of the GNU Lesser General Public 007// License as published by the Free Software Foundation; either 008// version 2.1 of the License, or (at your option) any later version. 009// 010// This library is distributed in the hope that it will be useful, 011// but WITHOUT ANY WARRANTY; without even the implied warranty of 012// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013// Lesser General Public License for more details. 014// 015// You should have received a copy of the GNU Lesser General Public 016// License along with this library; if not, write to the Free Software 017// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 018//////////////////////////////////////////////////////////////////////////////// 019package com.puppycrawl.tools.checkstyle.checks.sizes; 020 021import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck; 022import java.io.File; 023import java.util.List; 024 025/** 026 * <p> 027 * Checks for long source files. 028 * </p> 029 * <p> 030 * Rationale: If a source file becomes very long it is hard to understand. 031 * Therefore long classes should usually be refactored into several 032 * individual classes that focus on a specific task. 033 * </p> 034 * <p> 035 * The default maximum file length is 2000 lines. To change the maximum 036 * number of lines, set property max. 037 * </p> 038 * <p> 039 * An example of how to configure the check is: 040 * </p> 041 * <pre> 042 * <module name="FileLength"/> 043 * </pre> 044 * <p> 045 * An example of how to configure the check so that it accepts files with at 046 * most 1500 lines is: 047 * </p> 048 * <pre> 049 * <module name="FileLength"> 050 * <property name="max" value="1500"/> 051 * </module> 052 * </pre> 053 * @author Lars Kühne 054 */ 055public class FileLengthCheck extends AbstractFileSetCheck 056{ 057 /** default maximum number of lines */ 058 private static final int DEFAULT_MAX_LINES = 2000; 059 060 /** the maximum number of lines */ 061 private int maxFileLength = DEFAULT_MAX_LINES; 062 063 @Override 064 protected void processFiltered(File file, List<String> lines) 065 { 066 if (lines.size() > maxFileLength) { 067 log(1, "maxLen.file", lines.size(), maxFileLength); 068 } 069 } 070 071 /** 072 * @param length the maximum length of a Java source file 073 */ 074 public void setMax(int length) 075 { 076 maxFileLength = length; 077 } 078 079}