Permalink
Browse files

Issue #2482: Exclude lines with package in LineLength check

  • Loading branch information...
1 parent f30512c commit 9a39d19a31f06c8614d33fcc9c3f7654ec9cdd9f @rnveach rnveach committed with romani Oct 31, 2015
@@ -37,7 +37,8 @@
* </p>
*
* <p>
- * Import statements (lines matching pattern {@code ^import .*}) are not verified by this check.
+ * Package statements and import statements (lines matching pattern
+ * {@code ^(package|import) .*}), and are not verified by this check.
* </p>
* <p>
* The default maximum allowable line length is 80 characters. To change the
@@ -84,8 +85,8 @@
/** Default maximum number of columns in a line. */
private static final int DEFAULT_MAX_COLUMNS = 80;
- /** Pattern matching import and import static statements. */
- private static final Pattern IMPORT_PATTERN = Pattern.compile("^import .*");
+ /** Patterns matching package, import, and import static statements. */
+ private static final Pattern IGNORE_PATTERN = Pattern.compile("^(package|import) .*");
/** The maximum number of columns in a line. */
private int max = DEFAULT_MAX_COLUMNS;
@@ -124,7 +125,7 @@ public void beginTree(DetailAST rootAST) {
final int realLength = CommonUtils.lengthExpandedTabs(
line, line.length(), getTabWidth());
- if (realLength > max && !IMPORT_PATTERN.matcher(line).find()
+ if (realLength > max && !IGNORE_PATTERN.matcher(line).find()
&& !ignorePattern.matcher(line).find()) {
log(i + 1, MSG_KEY, max, realLength);
}
@@ -38,6 +38,12 @@ protected String getPath(String filename) throws IOException {
+ "sizes" + File.separator + filename);
}
+ @Override
+ protected String getNonCompilablePath(String filename) throws IOException {
+ return super.getNonCompilablePath("checks" + File.separator
+ + "sizes" + File.separator + filename);
+ }
+
@Test
public void testGetRequiredTokens() {
final LineLengthCheck checkObj = new LineLengthCheck();
@@ -89,4 +95,15 @@ public void shouldNotLogLongImportStatements() throws Exception {
};
verify(checkConfig, getPath("InputLongImportStatements.java"), expected);
}
+
+ @Test
+ public void shouldNotLogLongPackageStatements() throws Exception {
+ final DefaultConfiguration checkConfig =
+ createCheckConfig(LineLengthCheck.class);
+ checkConfig.addAttribute("max", "80");
+ final String[] expected = {
+ "6: " + getCheckMessage(MSG_KEY, 80, 88),
+ };
+ verify(checkConfig, getNonCompilablePath("InputLongPackageStatement.java"), expected);
+ }
}
@@ -0,0 +1,8 @@
+package com.nameofcompany.nameofdivision.nameofproject.systemtests.parallel.areaoftest.featuretested.flowtested;
+
+public class InputLongImportStatements {
+ @Override
+ public String toString() {
+ return "This is very long line that should be logged because it is not package";
+ }
+}
@@ -245,7 +245,7 @@
property <code>tabWidth</code> for <code>LineLength</code> alone.
</li>
<li>
- Import statements (lines matching pattern <code>^import .*</code>) are not verified by
+ Package and import statements (lines matching pattern <code>^(package|import) .*</code>) are not verified by
this check.
</li>
</ul>

0 comments on commit 9a39d19

Please sign in to comment.