From fc8a5ae78cffc8f6d5951a72fc722c52dedc1d04 Mon Sep 17 00:00:00 2001 From: Oliver Burn Date: Sun, 9 Nov 2008 12:12:27 +0000 Subject: [PATCH] Changed FileLength check to be a FileSetCheck. --- checkstyle_checks.xml | 5 +++- .../checkstyle/DefaultConfiguration.java | 3 +-- .../checks/sizes/FileLengthCheck.java | 21 +++++---------- .../checks/sizes/FileLengthCheckTest.java | 27 ++++++++++++++----- src/xdocs/config_sizes.xml | 2 +- src/xdocs/releasenotes.xml | 4 +++ 6 files changed, 37 insertions(+), 25 deletions(-) diff --git a/checkstyle_checks.xml b/checkstyle_checks.xml index 40c9b2eca..798d0840f 100755 --- a/checkstyle_checks.xml +++ b/checkstyle_checks.xml @@ -32,6 +32,10 @@ + + + + @@ -48,7 +52,6 @@ - diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/DefaultConfiguration.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/DefaultConfiguration.java index 6a75a3e12..18fb16c72 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/DefaultConfiguration.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/DefaultConfiguration.java @@ -38,8 +38,7 @@ public final class DefaultConfiguration implements Configuration private final String mName; /** the list of child Configurations */ - private final List mChildren = - Lists.newArrayList(); + private final List mChildren = Lists.newArrayList(); /** the map from attribute names to attribute values */ private final Map mAttributeMap = Maps.newHashMap(); diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/sizes/FileLengthCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/sizes/FileLengthCheck.java index 75885de45..1da256612 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/sizes/FileLengthCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/sizes/FileLengthCheck.java @@ -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; /** *

@@ -52,7 +52,7 @@ import com.puppycrawl.tools.checkstyle.api.DetailAST; * * @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 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); } } diff --git a/src/tests/com/puppycrawl/tools/checkstyle/checks/sizes/FileLengthCheckTest.java b/src/tests/com/puppycrawl/tools/checkstyle/checks/sizes/FileLengthCheckTest.java index 69e2d1303..7ab69a3bd 100644 --- a/src/tests/com/puppycrawl/tools/checkstyle/checks/sizes/FileLengthCheckTest.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/checks/sizes/FileLengthCheckTest.java @@ -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 diff --git a/src/xdocs/config_sizes.xml b/src/xdocs/config_sizes.xml index cd680409f..e08f24124 100755 --- a/src/xdocs/config_sizes.xml +++ b/src/xdocs/config_sizes.xml @@ -130,7 +130,7 @@

- TreeWalker + Checker

diff --git a/src/xdocs/releasenotes.xml b/src/xdocs/releasenotes.xml index e4f2333f1..ffd63f282 100755 --- a/src/xdocs/releasenotes.xml +++ b/src/xdocs/releasenotes.xml @@ -62,6 +62,10 @@ character. It replaces TabCharacterCheck which was restricted to Java files. +
  • + Changed FileLength + check to be a FileSetCheck. +
  • Fixed Bugs: