Changed FileLength check to be a FileSetCheck.
This commit is contained in:
parent
67e304551b
commit
fc8a5ae78c
|
|
@ -32,6 +32,10 @@
|
|||
<property name="eachLine" value="false"/>
|
||||
</module>
|
||||
|
||||
<module name="FileLength">
|
||||
<property name="fileExtensions" value="java"/>
|
||||
</module>
|
||||
|
||||
<module name="TreeWalker">
|
||||
|
||||
<property name="tabWidth" value="4" />
|
||||
|
|
@ -48,7 +52,6 @@
|
|||
<module name="EmptyBlock"/>
|
||||
<module name="EmptyForIteratorPad"/>
|
||||
<module name="EqualsHashCode"/>
|
||||
<module name="FileLength" />
|
||||
<module name="Header">
|
||||
<property name="headerFile" value="${checkstyle.header.file}"/>
|
||||
</module>
|
||||
|
|
|
|||
|
|
@ -38,8 +38,7 @@ public final class DefaultConfiguration implements Configuration
|
|||
private final String mName;
|
||||
|
||||
/** the list of child Configurations */
|
||||
private final List<Configuration> mChildren =
|
||||
Lists.newArrayList();
|
||||
private final List<Configuration> mChildren = Lists.newArrayList();
|
||||
|
||||
/** the map from attribute names to attribute values */
|
||||
private final Map<String, String> mAttributeMap = Maps.newHashMap();
|
||||
|
|
|
|||
|
|
@ -16,11 +16,11 @@
|
|||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package com.puppycrawl.tools.checkstyle.checks.sizes;
|
||||
|
||||
import com.puppycrawl.tools.checkstyle.api.Check;
|
||||
import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
||||
import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
|
@ -52,7 +52,7 @@ import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
|||
* </pre>
|
||||
* @author Lars Kühne
|
||||
*/
|
||||
public class FileLengthCheck extends Check
|
||||
public class FileLengthCheck extends AbstractFileSetCheck
|
||||
{
|
||||
/** default maximum number of lines */
|
||||
private static final int DEFAULT_MAX_LINES = 2000;
|
||||
|
|
@ -61,17 +61,10 @@ public class FileLengthCheck extends Check
|
|||
private int mMaxFileLength = DEFAULT_MAX_LINES;
|
||||
|
||||
@Override
|
||||
public int[] getDefaultTokens()
|
||||
protected void processFiltered(File aFile, List<String> aLines)
|
||||
{
|
||||
return new int[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beginTree(DetailAST aRootAST)
|
||||
{
|
||||
final String[] lines = getLines();
|
||||
if (lines.length > mMaxFileLength) {
|
||||
log(1, "maxLen.file", lines.length, mMaxFileLength);
|
||||
if (aLines.size() > mMaxFileLength) {
|
||||
log(1, "maxLen.file", aLines.size(), mMaxFileLength);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,37 +1,50 @@
|
|||
package com.puppycrawl.tools.checkstyle.checks.sizes;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport;
|
||||
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
|
||||
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
|
||||
import com.puppycrawl.tools.checkstyle.api.Configuration;
|
||||
import org.junit.Test;
|
||||
|
||||
public class FileLengthCheckTest
|
||||
extends BaseCheckTestSupport
|
||||
{
|
||||
private void runIt(String aMax, String[] aExpected) throws Exception
|
||||
@Override
|
||||
protected DefaultConfiguration createCheckerConfig(
|
||||
Configuration aCheckConfig)
|
||||
{
|
||||
final DefaultConfiguration checkConfig =
|
||||
createCheckConfig(FileLengthCheck.class);
|
||||
checkConfig.addAttribute("max", aMax);
|
||||
verify(checkConfig, getPath("InputSimple.java"), aExpected);
|
||||
DefaultConfiguration dc = new DefaultConfiguration("root");
|
||||
dc.addChild(aCheckConfig);
|
||||
return dc;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAlarm() throws Exception
|
||||
{
|
||||
DefaultConfiguration checkConfig =
|
||||
createCheckConfig(FileLengthCheck.class);
|
||||
checkConfig.addAttribute("max", "20");
|
||||
final String[] expected = {
|
||||
"1: File length is 225 lines (max allowed is 20)."
|
||||
};
|
||||
runIt("20", expected);
|
||||
verify(createChecker(checkConfig),
|
||||
getPath("InputSimple.java"),
|
||||
getPath("InputSimple.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOK() throws Exception
|
||||
{
|
||||
DefaultConfiguration checkConfig =
|
||||
createCheckConfig(FileLengthCheck.class);
|
||||
checkConfig.addAttribute("max", "2000");
|
||||
final String[] expected = {
|
||||
};
|
||||
runIt("2000", expected);
|
||||
verify(createChecker(checkConfig),
|
||||
getPath("InputSimple.java"),
|
||||
getPath("InputSimple.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@
|
|||
|
||||
<subsection name="Parent Module">
|
||||
<p>
|
||||
<a href="config.html#treewalker">TreeWalker</a>
|
||||
<a href="config.html#Checker">Checker</a>
|
||||
</p>
|
||||
</subsection>
|
||||
</section>
|
||||
|
|
|
|||
|
|
@ -62,6 +62,10 @@
|
|||
character. It replaces <i>TabCharacterCheck</i> which was
|
||||
restricted to Java files.
|
||||
</li>
|
||||
<li>
|
||||
Changed <a href="config_sizes.html#FileLength">FileLength</a>
|
||||
check to be a FileSetCheck.
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<p>Fixed Bugs:</p>
|
||||
|
|
|
|||
Loading…
Reference in New Issue