diff --git a/config/checkstyle-checks.xml b/config/checkstyle-checks.xml index 0a3634526ee..f9e8baff808 100644 --- a/config/checkstyle-checks.xml +++ b/config/checkstyle-checks.xml @@ -61,7 +61,11 @@ - + + + + + diff --git a/config/checkstyle-examples-checks.xml b/config/checkstyle-examples-checks.xml index 1ea1741553d..d2e94d1ea83 100644 --- a/config/checkstyle-examples-checks.xml +++ b/config/checkstyle-examples-checks.xml @@ -12,7 +12,11 @@ - + + + + + diff --git a/config/checkstyle-examples-suppressions.xml b/config/checkstyle-examples-suppressions.xml index eda71019617..6ff27ac2d07 100644 --- a/config/checkstyle-examples-suppressions.xml +++ b/config/checkstyle-examples-suppressions.xml @@ -6,6 +6,10 @@ + + + diff --git a/config/jsoref-spellchecker/whitelist.words b/config/jsoref-spellchecker/whitelist.words index 4cd873098ed..e1aa7c593e2 100644 --- a/config/jsoref-spellchecker/whitelist.words +++ b/config/jsoref-spellchecker/whitelist.words @@ -917,7 +917,6 @@ NODESET noembed noenumtrailingcomma nofinalizer -NOI noinspection noinspectionreason nojavadoc @@ -1048,7 +1047,6 @@ Perror pgjdbc Pgpg Pgpgv -pguyot php picocli pid @@ -1147,7 +1145,6 @@ returnsreceiver reviewdog revwalk rfc -rfe Rgb rgba rhs @@ -1199,7 +1196,6 @@ SEO separatorwrap SERIALVERSIONUID servlet -SETPOINT severitymatchfilter sevntu shanegenschaw diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpCheck.java index 40e25ffa39a..4f329978a4a 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpCheck.java @@ -90,6 +90,19 @@ * if you want to match a < symbol you need to enter &lt;. * The regular expression should be entered on one line. *

+ * + *

+ * Note: To search for parentheses () in a regular expression + * you must escape them like \(\). This is required by the regexp engine, + * otherwise it will think they are special instruction characters. + *

+ * + *

+ * Note: To search for things that mean something in XML, like + * < you need to escape them like &lt;. This is required so the + * XML parser does not act on them, but instead passes the correct + * character to the regexp engine. + *

*
    *
  • * Property {@code duplicateLimit} - Control whether to check for duplicates diff --git a/src/main/resources/com/puppycrawl/tools/checkstyle/meta/checks/regexp/RegexpCheck.xml b/src/main/resources/com/puppycrawl/tools/checkstyle/meta/checks/regexp/RegexpCheck.xml index 51ecda7dacd..0c1ff6160e4 100644 --- a/src/main/resources/com/puppycrawl/tools/checkstyle/meta/checks/regexp/RegexpCheck.xml +++ b/src/main/resources/com/puppycrawl/tools/checkstyle/meta/checks/regexp/RegexpCheck.xml @@ -62,6 +62,19 @@ the XML config file you must also take into account the XML rules. e.g. if you want to match a &lt; symbol you need to enter &amp;lt;. The regular expression should be entered on one line. + </p> + + <p> + <b>Note:</b> To search for parentheses () in a regular expression + you must escape them like \(\). This is required by the regexp engine, + otherwise it will think they are special instruction characters. + </p> + + <p> + <b>Note:</b> To search for things that mean something in XML, like + &lt; you need to escape them like &amp;lt;. This is required so the + XML parser does not act on them, but instead passes the correct + character to the regexp engine. </p> diff --git a/src/site/xdoc/checks/regexp/regexp.xml b/src/site/xdoc/checks/regexp/regexp.xml index d6241472d00..32941cba521 100644 --- a/src/site/xdoc/checks/regexp/regexp.xml +++ b/src/site/xdoc/checks/regexp/regexp.xml @@ -54,6 +54,15 @@ you want to match a < symbol you need to enter &lt;. The regular expression should be entered on one line.

    +

    Note: To search for parentheses () in a regular expression + you must escape them like \(\). This is required by the regexp engine, + otherwise it will think they are special instruction characters. +

    +

    Note: To search for things that mean something in XML, like + < you need to escape them like &lt;. This is required so the + XML parser does not act on them, but instead passes the correct + character to the regexp engine. +

    @@ -113,101 +122,128 @@ -

    - To configure the check: -

    -

    - The following examples are mainly copied from the other 3 checks - mentioned above, to show how the same results can be achieved using - this check in place of them. -

    -

    - To use like Required Regexp check: -

    -

    +

    Default configuration does nothing:

    + +<module name="Checker"> + <module name="TreeWalker"> + <module name="Regexp"/> + </module> +</module> + +

    An example of how to configure the check to make sure a copyright statement is included in the file:

    -

    The statement.

    - -// This code is copyrighted - -

    The check.

    <module name="Checker"> <module name="TreeWalker"> <module name="Regexp"> - <property name="format" value="// This code is copyrighted"/> + <property name="format" value="// This code is copyrighted\."/> </module> </module> </module> -

    Your statement may be multiline.

    +

    Example1:

    -// This code is copyrighted -// (c) MyCompany +// This code is copyrighted. +public class Example1 {} -

    Then the check would be.

    +

    Example2 with violation:

    + +/* violation on first line 'Required pattern missing in a file.' */ +/* + * Some Copyright + */ +public class Example2 {} + +

    Your statement may be multiline.

    <module name="Checker"> <module name="TreeWalker"> <module name="Regexp"> - <property name="format" value="// This code is copyrighted\n// \(c\) MyCompany"/> + <property name="format" + value="// This code is copyrighted\n// \(c\) MyCompany"/> </module> </module> </module> -

    Note: To search for parentheses () in a regular expression - you must escape them like \(\). This is required by the regexp engine, - otherwise it will think they are special instruction characters. -

    -

    - And to make sure it appears only once: -

    +

    Example3:

    + +// This code is copyrighted +// (c) MyCompany +public class Example3 {} + +

    Configure Check to make sure that it appear only once:

    <module name="Checker"> <module name="TreeWalker"> <module name="Regexp"> - <property name="format" value="// This code is copyrighted\n// \(c\) MyCompany"/> + <property name="format" + value="// This code is copyrighted\n// \(c\) MyCompany"/> <property name="duplicateLimit" value="0"/> </module> </module> </module> -

    - It can also be useful to attach a meaningful message to the check: +

    Example4:

    + +// This code is copyrighted +// (c) MyCompany +public class Example4 {} + +// violation below 'Found duplicate pattern' +// This code is copyrighted +// (c) MyCompany +class Example41 {} + +

    Instead of printing whole regexp that might be unnecessary for + user, you can substitute it to some static text:

    <module name="Checker"> <module name="TreeWalker"> <module name="Regexp"> - <property name="format" value="// This code is copyrighted\n// \(c\) MyCompany"/> + <property name="format" + value="// This code is copyrighted\n// \(c\) MyCompany"/> <property name="message" value="Copyright"/> </module> </module> </module> -

    - To use like illegal regexp check: -

    -

    - An example of how to configure the check to make sure there are no - calls to System.out.println: +

    Example5 with violation:

    + +/* + * violation on first line 'Required pattern 'Copyright' missing in file.' +*/ +public class Example5 {} + + +

    + Configure the check to make sure there are no calls to System.out.println:

    <module name="Checker"> <module name="TreeWalker"> <module name="Regexp"> - <!-- . matches any character, so we need to escape it and use \. to match dots. --> <property name="format" value="System\.out\.println"/> <property name="illegalPattern" value="true"/> </module> </module> </module> -

    - You may want to make the above check ignore comments, like this: -

    +

    Example6:

    + +public class Example6 { + private void foo() { + System.out.println(""); // violation, 'Line matches the illegal pattern' + System.out. + println(""); + // System.out.println("debug"); + // violation above, 'Line matches the illegal pattern' + } +} + +

    Configure to ignore comments:

    <module name="Checker"> <module name="TreeWalker"> @@ -219,9 +255,20 @@ </module> </module> -

    - An example of how to configure the check to find trailing whitespace - at the end of a line: +

    Example7:

    + +public class Example7 { + private void foo() { + System.out.println(""); // violation, 'Line matches the illegal pattern' + System.out. + println(""); + // System.out.println("debug"); + + } +} + +

    + Configure the check to find trailing whitespace at the end of a line:

    <module name="Checker"> @@ -234,15 +281,22 @@ </module> </module> -

    - An example of how to configure the check to find case-insensitive - occurrences of "debug": +

    Example8:

    + +public class Example8 { + private void foo() { + // violation above 'Trailing whitespace' + } +} + +

    + Configure the check to find case-insensitive occurrences of "debug":

    <module name="Checker"> <module name="TreeWalker"> <module name="Regexp"> - <property name="format" value="(?i)debug"/> + <property name="format" value="(?i)fix me\."/> <property name="illegalPattern" value="true"/> </module> </module> @@ -252,237 +306,68 @@ Note: The (?i) at the beginning of the regular expression tells the regexp engine to ignore the case.

    -

    +

    Example9:

    + +public class Example9 { + private void foo() { + // fix me. + // violation above, 'Line matches the illegal pattern.' + } +} + +

    There is also a feature to limit the number of violations reported. When the limit is reached the check aborts with a message reporting that the limit has been reached. - The default limit setting is 100, but this can be change as shown in - the following example.

    <module name="Checker"> <module name="TreeWalker"> <module name="Regexp"> - <property name="format" value="(?i)debug"/> + <property name="format" value="(?i)fix me\."/> <property name="illegalPattern" value="true"/> - <property name="errorLimit" value="1000"/> - </module> - </module> -</module> - -

    - To use like RegexpHeader - : -

    -

    - To configure the check to verify that each file starts with the - following multiline header. -

    -

    Note the following:

    -
      -
    • \A means the start of the file.
    • -
    • The date can be any 4-digit number.
    • -
    - - -// Copyright (C) 2004 MyCompany -// All rights reserved - -

    The check would be:

    - -<module name="Checker"> - <module name="TreeWalker"> - <module name="Regexp"> - <property - name="format" - value="\A// Copyright \(C\) \d\d\d\d MyCompany\n// All rights reserved"/> - </module> - </module> -</module> - -

    - A more complex example. Note how the import and javadoc multilines are - handled, there can be any number of them. -

    - -/////////////////////////////////////////////////////////////////////// -// checkstyle: -// Checks Java source code for adherence to a set of rules. -// Copyright (C) 2004 Oliver Burn -// Last modification by $Author A.N.Other$ -/////////////////////////////////////////////////////////////////////// - -package com.puppycrawl.checkstyle; - -import java.util.thing1; -import java.util.thing2; -import java.util.thing3; - -/** -* javadoc line 1 -* javadoc line 2 -* javadoc line 3 -*/ - -

    The check would be:

    - -<module name="Checker"> - <module name="TreeWalker"> - <module name="Regexp"> - <property - name="format" - value="\A/{71}\n// checkstyle:\n// Checks Java source code for - adherence to a set of rules\.\n// Copyright \(C\) \d\d\d\d Oliver Burn\n - // Last modification by \$Author.*\$\n/{71}\n\npackage [\w\.]*;\n\n - (import [\w\.]*;\n)*\n/\*\*\n( \*[^/]*\n)* \*/"/> + <property name="errorLimit" value="1"/> </module> </module> </module> -

    - More examples: -

    -

    - The next 2 examples deal with the following example Java source file: -

    +

    Example10:

    -/* -* PID.java -* -* Copyright (c) 2001 ACME -* 123 Some St. -* Somewhere. -* -* This software is the confidential and proprietary information of ACME. -* ("Confidential Information"). You shall not disclose such -* Confidential Information and shall use it only in accordance with -* the terms of the license agreement you entered into with ACME. -* -* $Log: config_misc.xml,v $ -* Revision 1.7 2007/01/16 12:16:35 oburn -* Removing all reference to mailing lists -* -* Revision 1.6 2005/12/25 16:13:10 o_sukhodolsky -* Fix for rfe 1248106 (TYPECAST is now accepted by NoWhitespaceAfter) -* -* Fix for rfe 953266 (thanks to Paul Guyot (pguyot) for submitting patch) -* IllegalType can be configured to accept some abstract classes which -* matches to regexp of illegal type names (property legalAbstractClassNames) -* -* TrailingComment now can be configured to accept some trailing comments -* (such as NOI18N) (property legalComment, rfe 1385344). -* -* Revision 1.5 2005/11/06 11:54:12 oburn -* Incorporate excellent patch [ 1344344 ] Consolidation of regexp checks. -* -* Revision 1.3.8.1 2005/10/11 14:26:32 someone -* Fix for bug 251. The broken bit is fixed -*/ - -package com.acme.tools; - -import com.acme.thing1; -import com.acme.thing2; -import com.acme.thing3; +public class Example10 { + private void foo() { + // fix me. + // violation above, 'Line matches the illegal pattern' + } + private void foo1() { + // fix me. -/** -* -* <P> -* <I>This software is the confidential and proprietary information of -* ACME (<B>"Confidential Information"</B>). You shall not -* disclose such Confidential Information and shall use it only in -* accordance with the terms of the license agreement you entered into -* with ACME.</I> -* </P> -* -* &#169; copyright 2002 ACME -* -* @author Some Body -*/ -public class PID extends StateMachine implements WebObject.Constants { - -/** javadoc. */ -public static final int A_SETPOINT = 1; -. -. -. -} // class PID + } +} -

    - This checks for the presence of the header, the first 16 lines. +

    + To configure the check to verify that each file has the + multiline header where year could be any digits.

    -

    Note the following:

    -
      -
    • Line 2 and 13 contain the file name. These are checked to - make sure they are the same, and that they match the class name.
    • -
    • The date can be any 4-digit number.
    • -
    -

    The check would be:

    <module name="Checker"> <module name="TreeWalker"> <module name="Regexp"> <property name="format" - value="\A/\*\n \* (\w*)\.java\n \*\n \* Copyright \(c\) - \d\d\d\d ACME\n \* 123 Some St\.\n \* Somewhere\.\n \*\n - \* This software is the confidential and proprietary information - of ACME\.\n \* \(&quot;Confidential Information&quot;\)\. You - shall not disclose such\n \* Confidential Information and shall - use it only in accordance with\n \* the terms of the license - agreement you entered into with ACME\.\n \*\n - \* \$Log: config_misc\.xml,v $ - \* Revision 1\.7 2007/01/16 12:16:35 oburn - \* Removing all reference to mailing lists - \* \ - \* Revision 1.6 2005/12/25 16:13:10 o_sukhodolsky - \* Fix for rfe 1248106 \(TYPECAST is now accepted by NoWhitespaceAfter\) - \* \ - \* Fix for rfe 953266 \(thanks to Paul Guyot \(pguyot\) for submitting patch\) - \* IllegalType can be configured to accept some abstract classes which - \* matches to regexp of illegal type names \(property legalAbstractClassNames\) - \* - \* TrailingComment now can be configured to accept some trailing comments - \* \(such as NOI18N\) \(property legalComment, rfe 1385344\). - \* - \* Revision 1.5 2005/11/06 11:54:12 oburn - \* Incorporate excellent patch \[ 1344344 \] Consolidation of regexp checks. - \* \\n(.*\n)*([\w|\s]*( class | interface )\1)"/> - <property name="message" value="Correct header not found"/> + value="// Copyright \(C\) \d\d\d\d MyCompany\n// All rights reserved"/> </module> </module> </module> -

    - This checks for the presence of a copyright notice within the class - javadoc, lines 24 to 37. -

    +

    Example:

    -<module name="Checker"> - <module name="TreeWalker"> - <module name="Regexp"> - <property - name="format" - value="(/\*\*\n)( \*.*\n)*( \* &lt;P&gt;\n \* &lt;I&gt; - This software is the confidential and proprietary information of\n - \* ACME \(&lt;B&gt;&quot;Confidential Information&quot;&lt;/B&gt; - \)\. You shall not\n \* disclose such Confidential Information - and shall use it only in\n \* accordance with the terms of the - license agreement you entered into\n \* with ACME\.&lt;/I&gt;\n - \* &lt;/P&gt;\n \*\n \* &#169; copyright \d\d\d\d ACME\n - \*\n \* @author .*)(\n\s\*.*)*/\n[\w|\s]*( class | interface )"/> - <property name="message" - value="Copyright in class/interface Javadoc"/> - <property name="duplicateLimit" value="0"/> - </module> - </module> -</module> +// Copyright (C) 2004 MyCompany +// All rights reserved +public class Example11 {}

    - Note: To search for things that mean something in XML, like - < you need to escape them like &lt;. This is required so the - XML parser does not act on them, but instead passes the correct - character to the regexp engine. + To configure the check to verify that each file start with the + multiline header, you should append '\A' to 'regexp' at left.

    diff --git a/src/site/xdoc/checks/regexp/regexp.xml.template b/src/site/xdoc/checks/regexp/regexp.xml.template index 2784999e0f7..be72f6ec6d5 100644 --- a/src/site/xdoc/checks/regexp/regexp.xml.template +++ b/src/site/xdoc/checks/regexp/regexp.xml.template @@ -54,6 +54,15 @@ you want to match a < symbol you need to enter &lt;. The regular expression should be entered on one line.

    +

    Note: To search for parentheses () in a regular expression + you must escape them like \(\). This is required by the regexp engine, + otherwise it will think they are special instruction characters. +

    +

    Note: To search for things that mean something in XML, like + < you need to escape them like &lt;. This is required so the + XML parser does not act on them, but instead passes the correct + character to the regexp engine. +

    @@ -66,199 +75,164 @@ -

    - To configure the check: -

    -

    - The following examples are mainly copied from the other 3 checks - mentioned above, to show how the same results can be achieved using - this check in place of them. -

    -

    - To use like Required Regexp check: -

    -

    +

    Default configuration does nothing:

    + + + + +

    An example of how to configure the check to make sure a copyright statement is included in the file:

    -

    The statement.

    + value="resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example1.java"/> + + +

    Example1:

    + + + + +

    Example2 with violation:

    + + -

    The check.

    +

    Your statement may be multiline.

    + value="resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example3.java"/> -

    Your statement may be multiline.

    +

    Example3:

    + value="resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example3.java"/> -

    Then the check would be.

    +

    Configure Check to make sure that it appear only once:

    + value="resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example4.java"/> -

    Note: To search for parentheses () in a regular expression - you must escape them like \(\). This is required by the regexp engine, - otherwise it will think they are special instruction characters. -

    -

    - And to make sure it appears only once: -

    +

    Example4:

    - + value="resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example4.java"/> + -

    - It can also be useful to attach a meaningful message to the check: +

    Instead of printing whole regexp that might be unnecessary for + user, you can substitute it to some static text:

    + value="resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example5.java"/> -

    - To use like illegal regexp check: -

    -

    - An example of how to configure the check to make sure there are no - calls to System.out.println: -

    +

    Example5 with violation:

    - + value="resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example5.java"/> + +

    - You may want to make the above check ignore comments, like this: + Configure the check to make sure there are no calls to System.out.println:

    + value="resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example6.java"/> -

    - An example of how to configure the check to find trailing whitespace - at the end of a line: -

    +

    Example6:

    - + value="resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example6.java"/> + -

    - An example of how to configure the check to find case-insensitive - occurrences of "debug": -

    +

    Configure to ignore comments:

    + value="resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example7.java"/> -

    - Note: The (?i) at the beginning of the regular expression - tells the regexp engine to ignore the case. -

    -

    - There is also a feature to limit the number of violations reported. - When the limit is reached the check aborts with a message - reporting that the limit has been reached. - The default limit setting is 100, but this can be change as shown in - the following example. +

    Example7:

    + + + + +

    + Configure the check to find trailing whitespace at the end of a line:

    + value="resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example8.java"/> -

    - To use like RegexpHeader - : -

    -

    - To configure the check to verify that each file starts with the - following multiline header. -

    -

    Note the following:

    -
      -
    • \A means the start of the file.
    • -
    • The date can be any 4-digit number.
    • -
    - +

    Example8:

    + value="resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example8.java"/> -

    The check would be:

    +

    + Configure the check to find case-insensitive occurrences of "debug": +

    + value="resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example9.java"/> -

    - A more complex example. Note how the import and javadoc multilines are - handled, there can be any number of them. +

    + Note: The (?i) at the beginning of the regular expression + tells the regexp engine to ignore the case.

    +

    Example9:

    + value="resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example9.java"/> -

    The check would be:

    +

    + There is also a feature to limit the number of violations reported. + When the limit is reached the check aborts with a message + reporting that the limit has been reached. +

    + value="resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example10.java"/> -

    - More examples: -

    -

    - The next 2 examples deal with the following example Java source file: -

    +

    Example10:

    + value="resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example10.java"/> -

    - This checks for the presence of the header, the first 16 lines. +

    + To configure the check to verify that each file has the + multiline header where year could be any digits.

    -

    Note the following:

    -
      -
    • Line 2 and 13 contain the file name. These are checked to - make sure they are the same, and that they match the class name.
    • -
    • The date can be any 4-digit number.
    • -
    -

    The check would be:

    + value="resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example11.java"/> -

    - This checks for the presence of a copyright notice within the class - javadoc, lines 24 to 37. -

    +

    Example:

    - + value="resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example11.java"/> +

    - Note: To search for things that mean something in XML, like - < you need to escape them like &lt;. This is required so the - XML parser does not act on them, but instead passes the correct - character to the regexp engine. + To configure the check to verify that each file start with the + multiline header, you should append '\A' to 'regexp' at left.

    diff --git a/src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpCheckExamplesTest.java b/src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpCheckExamplesTest.java index cbcc16ce84a..b2ee2e2bb1b 100644 --- a/src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpCheckExamplesTest.java +++ b/src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpCheckExamplesTest.java @@ -19,34 +19,41 @@ package com.puppycrawl.tools.checkstyle.checks.regexp; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import com.puppycrawl.tools.checkstyle.AbstractExamplesModuleTestSupport; -@Disabled("until https://github.com/checkstyle/checkstyle/issues/13345") public class RegexpCheckExamplesTest extends AbstractExamplesModuleTestSupport { @Override protected String getPackageLocation() { return "com/puppycrawl/tools/checkstyle/checks/regexp/regexp"; } + @Test + public void testExample0() throws Exception { + final String[] expected = { + + }; + + verifyWithInlineConfigParser(getPath("Example0.java"), expected); + } + @Test public void testExample1() throws Exception { final String[] expected = { }; - verifyWithInlineConfigParser(getPath("Example1.txt"), expected); + verifyWithInlineConfigParser(getPath("Example1.java"), expected); } @Test public void testExample2() throws Exception { final String[] expected = { - + "1: Required pattern '// This code is copyrighted\\.' missing in file.", }; - verifyWithInlineConfigParser(getPath("Example2.txt"), expected); + verifyWithInlineConfigParser(getPath("Example2.java"), expected); } @Test @@ -55,70 +62,73 @@ public void testExample3() throws Exception { }; - verifyWithInlineConfigParser(getPath("Example3.txt"), expected); + verifyWithInlineConfigParser(getPath("Example3.java"), expected); } @Test public void testExample4() throws Exception { final String[] expected = { - + "21: Found duplicate pattern '// This code is copyrighted\\n// \\(c\\) MyCompany'.", }; - verifyWithInlineConfigParser(getPath("Example4.txt"), expected); + verifyWithInlineConfigParser(getPath("Example4.java"), expected); } @Test public void testExample5() throws Exception { final String[] expected = { - + "1: Required pattern 'Copyright' missing in file.", }; - verifyWithInlineConfigParser(getPath("Example5.txt"), expected); + verifyWithInlineConfigParser(getPath("Example5.java"), expected); } @Test public void testExample6() throws Exception { final String[] expected = { - + "17: Line matches the illegal pattern 'System\\.out\\.println'.", + "20: Line matches the illegal pattern 'System\\.out\\.println'.", }; - verifyWithInlineConfigParser(getPath("Example6.txt"), expected); + verifyWithInlineConfigParser(getPath("Example6.java"), expected); } @Test public void testExample7() throws Exception { final String[] expected = { - + "18: Line matches the illegal pattern 'System\\.out\\.println'.", }; - verifyWithInlineConfigParser(getPath("Example7.txt"), expected); + verifyWithInlineConfigParser(getPath("Example7.java"), expected); } @Test public void testExample8() throws Exception { final String[] expected = { - + "17: Line matches the illegal pattern 'Trailing whitespace'.", }; - verifyWithInlineConfigParser(getPath("Example8.txt"), expected); + verifyWithInlineConfigParser(getPath("Example8.java"), expected); } @Test public void testExample9() throws Exception { final String[] expected = { - + "17: Line matches the illegal pattern '(?i)fix me\\.'.", }; - verifyWithInlineConfigParser(getPath("Example9.txt"), expected); + verifyWithInlineConfigParser(getPath("Example9.java"), expected); } @Test public void testExample10() throws Exception { final String[] expected = { - + "18: Line matches the illegal pattern" + + " 'The error limit has been exceeded, the check is aborting," + + " there may be more unreported errors.(?i)fix me\\.'.", }; - verifyWithInlineConfigParser(getPath("Example10.txt"), expected); + verifyWithInlineConfigParser(getPath("Example10.java"), expected); } @Test @@ -127,24 +137,6 @@ public void testExample11() throws Exception { }; - verifyWithInlineConfigParser(getPath("Example11.txt"), expected); - } - - @Test - public void testExample12() throws Exception { - final String[] expected = { - - }; - - verifyWithInlineConfigParser(getPath("Example12.txt"), expected); - } - - @Test - public void testExample13() throws Exception { - final String[] expected = { - - }; - - verifyWithInlineConfigParser(getPath("Example13.txt"), expected); + verifyWithInlineConfigParser(getPath("Example11.java"), expected); } } diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example0.java b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example0.java new file mode 100644 index 00000000000..3e2fce2f167 --- /dev/null +++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example0.java @@ -0,0 +1,14 @@ +/*xml + + + + + +*/ + +package com.puppycrawl.tools.checkstyle.checks.regexp.regexp; + +public class Example0 {} + +// xdoc section -- start +// xdoc section -- end diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example1.txt b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example1.java similarity index 65% rename from src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example1.txt rename to src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example1.java index 0178f1d10f6..ba9d835671e 100644 --- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example1.txt +++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example1.java @@ -2,12 +2,15 @@ - + */ +package com.puppycrawl.tools.checkstyle.checks.regexp.regexp; + // xdoc section -- start -// This code is copyrighted +// This code is copyrighted. +public class Example1 {} // xdoc section -- end diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example10.java b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example10.java new file mode 100644 index 00000000000..23d350fa8cd --- /dev/null +++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example10.java @@ -0,0 +1,26 @@ +/*xml + + + + + + + + + +*/ + +package com.puppycrawl.tools.checkstyle.checks.regexp.regexp; + +// xdoc section -- start +public class Example10 { + private void foo() { + // fix me. + // violation above, 'Line matches the illegal pattern' + } + private void foo1() { + // fix me. + + } +} +// xdoc section -- end diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example10.txt b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example11.java similarity index 61% rename from src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example10.txt rename to src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example11.java index 036d0c397ef..b9662fc815b 100644 --- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example10.txt +++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example11.java @@ -4,13 +4,16 @@ + value="// Copyright \(C\) \d\d\d\d MyCompany\n// All rights reserved"/> */ +package com.puppycrawl.tools.checkstyle.checks.regexp.regexp; + // xdoc section -- start // Copyright (C) 2004 MyCompany // All rights reserved +public class Example11 {} // xdoc section -- end diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example11.txt b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example11.txt deleted file mode 100644 index e0fb4c3678d..00000000000 --- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example11.txt +++ /dev/null @@ -1,35 +0,0 @@ -/*xml - - - - - - - -*/ - -// xdoc section -- start -/////////////////////////////////////////////////////////////////////// -// checkstyle: -// Checks Java source code for adherence to a set of rules. -// Copyright (C) 2004 Oliver Burn -// Last modification by $Author A.N.Other$ -/////////////////////////////////////////////////////////////////////// - -package com.puppycrawl.checkstyle; - -import java.util.thing1; -import java.util.thing2; -import java.util.thing3; - -/** -* javadoc line 1 -* javadoc line 2 -* javadoc line 3 -*/ -// xdoc section -- end diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example12.txt b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example12.txt deleted file mode 100644 index f061ee2d2d0..00000000000 --- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example12.txt +++ /dev/null @@ -1,99 +0,0 @@ -/*xml - - - - - - - - -*/ - -// xdoc section -- start -/* -* PID.java -* -* Copyright (c) 2001 ACME -* 123 Some St. -* Somewhere. -* -* This software is the confidential and proprietary information of ACME. -* ("Confidential Information"). You shall not disclose such -* Confidential Information and shall use it only in accordance with -* the terms of the license agreement you entered into with ACME. -* -* $Log: config_misc.xml,v $ -* Revision 1.7 2007/01/16 12:16:35 oburn -* Removing all reference to mailing lists -* -* Revision 1.6 2005/12/25 16:13:10 o_sukhodolsky -* Fix for rfe 1248106 (TYPECAST is now accepted by NoWhitespaceAfter) -* -* Fix for rfe 953266 (thanks to Paul Guyot (pguyot) for submitting patch) -* IllegalType can be configured to accept some abstract classes which -* matches to regexp of illegal type names (property legalAbstractClassNames) -* -* TrailingComment now can be configured to accept some trailing comments -* (such as NOI18N) (property legalComment, rfe 1385344). -* -* Revision 1.5 2005/11/06 11:54:12 oburn -* Incorporate excellent patch [ 1344344 ] Consolidation of regexp checks. -* -* Revision 1.3.8.1 2005/10/11 14:26:32 someone -* Fix for bug 251. The broken bit is fixed -*/ - -package com.acme.tools; - -import com.acme.thing1; -import com.acme.thing2; -import com.acme.thing3; - -/** -* -*

    -* This software is the confidential and proprietary information of -* ACME ("Confidential Information"). You shall not -* disclose such Confidential Information and shall use it only in -* accordance with the terms of the license agreement you entered into -* with ACME. -*

    -* -* © copyright 2002 ACME -* -* @author Some Body -*/ -public class PID extends StateMachine implements WebObject.Constants { - -/** javadoc. */ -public static final int A_SETPOINT = 1; -. -. -. -} // class PID -// xdoc section -- end diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example13.txt b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example13.txt deleted file mode 100644 index 6e319626d80..00000000000 --- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example13.txt +++ /dev/null @@ -1,85 +0,0 @@ -/*xml - - - - - - - - - -*/ - -// xdoc section -- start -/* -* PID.java -* -* Copyright (c) 2001 ACME -* 123 Some St. -* Somewhere. -* -* This software is the confidential and proprietary information of ACME. -* ("Confidential Information"). You shall not disclose such -* Confidential Information and shall use it only in accordance with -* the terms of the license agreement you entered into with ACME. -* -* $Log: config_misc.xml,v $ -* Revision 1.7 2007/01/16 12:16:35 oburn -* Removing all reference to mailing lists -* -* Revision 1.6 2005/12/25 16:13:10 o_sukhodolsky -* Fix for rfe 1248106 (TYPECAST is now accepted by NoWhitespaceAfter) -* -* Fix for rfe 953266 (thanks to Paul Guyot (pguyot) for submitting patch) -* IllegalType can be configured to accept some abstract classes which -* matches to regexp of illegal type names (property legalAbstractClassNames) -* -* TrailingComment now can be configured to accept some trailing comments -* (such as NOI18N) (property legalComment, rfe 1385344). -* -* Revision 1.5 2005/11/06 11:54:12 oburn -* Incorporate excellent patch [ 1344344 ] Consolidation of regexp checks. -* -* Revision 1.3.8.1 2005/10/11 14:26:32 someone -* Fix for bug 251. The broken bit is fixed -*/ - -package com.acme.tools; - -import com.acme.thing1; -import com.acme.thing2; -import com.acme.thing3; - -/** -* -*

    -* This software is the confidential and proprietary information of -* ACME ("Confidential Information"). You shall not -* disclose such Confidential Information and shall use it only in -* accordance with the terms of the license agreement you entered into -* with ACME. -*

    -* -* © copyright 2002 ACME -* -* @author Some Body -*/ -public class PID extends StateMachine implements WebObject.Constants { - -/** javadoc. */ -public static final int A_SETPOINT = 1; -. -. -. -} // class PID -// xdoc section -- end diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example4.txt b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example2.java similarity index 50% rename from src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example4.txt rename to src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example2.java index 10ce011c499..50207d76a82 100644 --- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example4.txt +++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example2.java @@ -2,12 +2,19 @@ - - + */ +// violation 9 lines above 'missing in file.' + +package com.puppycrawl.tools.checkstyle.checks.regexp.regexp; // xdoc section -- start +/* violation on first line 'Required pattern missing in a file.' */ +/* + * Some Copyright + */ +public class Example2 {} // xdoc section -- end diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example2.txt b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example3.java similarity index 54% rename from src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example2.txt rename to src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example3.java index 6bb8da8b9be..b9ee92eecab 100644 --- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example2.txt +++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example3.java @@ -2,13 +2,17 @@ - + */ +package com.puppycrawl.tools.checkstyle.checks.regexp.regexp; + // xdoc section -- start // This code is copyrighted // (c) MyCompany +public class Example3 {} // xdoc section -- end diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example3.txt b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example3.txt deleted file mode 100644 index b2e508b7299..00000000000 --- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example3.txt +++ /dev/null @@ -1,13 +0,0 @@ -/*xml - - - - - - - - -*/ - -// xdoc section -- start -// xdoc section -- end diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example4.java b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example4.java new file mode 100644 index 00000000000..9c5fe67b3c6 --- /dev/null +++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example4.java @@ -0,0 +1,24 @@ +/*xml + + + + + + + + +*/ + +package com.puppycrawl.tools.checkstyle.checks.regexp.regexp; + +// xdoc section -- start +// This code is copyrighted +// (c) MyCompany +public class Example4 {} + +// violation below 'Found duplicate pattern' +// This code is copyrighted +// (c) MyCompany +class Example41 {} +// xdoc section -- end diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example5.java b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example5.java new file mode 100644 index 00000000000..e7ebb526348 --- /dev/null +++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example5.java @@ -0,0 +1,21 @@ +/*xml + + + + + + + + +*/ +// violation 11 lines above 'Required pattern 'Copyright' missing in file.' + +package com.puppycrawl.tools.checkstyle.checks.regexp.regexp; + +// xdoc section -- start +/* + * violation on first line 'Required pattern 'Copyright' missing in file.' +*/ +public class Example5 {} +// xdoc section -- end diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example5.txt b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example5.txt deleted file mode 100644 index 3109bfa5d6c..00000000000 --- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example5.txt +++ /dev/null @@ -1,14 +0,0 @@ -/*xml - - - - - - - - - -*/ - -// xdoc section -- start -// xdoc section -- end diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example6.java b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example6.java new file mode 100644 index 00000000000..ddd82401194 --- /dev/null +++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example6.java @@ -0,0 +1,24 @@ +/*xml + + + + + + + + +*/ + +package com.puppycrawl.tools.checkstyle.checks.regexp.regexp; + +// xdoc section -- start +public class Example6 { + private void foo() { + System.out.println(""); // violation, 'Line matches the illegal pattern' + System.out. + println(""); + // System.out.println("debug"); + // violation above, 'Line matches the illegal pattern' + } +} +// xdoc section -- end diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example6.txt b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example7.java similarity index 55% rename from src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example6.txt rename to src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example7.java index ceed9ce6395..422aab790f2 100644 --- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example6.txt +++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example7.java @@ -10,5 +10,16 @@ */ +package com.puppycrawl.tools.checkstyle.checks.regexp.regexp; + // xdoc section -- start +public class Example7 { + private void foo() { + System.out.println(""); // violation, 'Line matches the illegal pattern' + System.out. + println(""); + // System.out.println("debug"); + + } +} // xdoc section -- end diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example7.txt b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example8.java similarity index 67% rename from src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example7.txt rename to src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example8.java index 7b92fdb00e8..70caa79d3ae 100644 --- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example7.txt +++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example8.java @@ -10,5 +10,12 @@ */ +package com.puppycrawl.tools.checkstyle.checks.regexp.regexp; + // xdoc section -- start +public class Example8 { + private void foo() { + // violation above 'Trailing whitespace' + } +} // xdoc section -- end diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example8.txt b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example8.txt deleted file mode 100644 index 6985591ff59..00000000000 --- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example8.txt +++ /dev/null @@ -1,13 +0,0 @@ -/*xml - - - - - - - - -*/ - -// xdoc section -- start -// xdoc section -- end diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example9.java b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example9.java new file mode 100644 index 00000000000..e5e505e84d9 --- /dev/null +++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example9.java @@ -0,0 +1,21 @@ +/*xml + + + + + + + + +*/ + +package com.puppycrawl.tools.checkstyle.checks.regexp.regexp; + +// xdoc section -- start +public class Example9 { + private void foo() { + // fix me. + // violation above, 'Line matches the illegal pattern.' + } +} +// xdoc section -- end diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example9.txt b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example9.txt deleted file mode 100644 index 01e4e21c91c..00000000000 --- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexp/Example9.txt +++ /dev/null @@ -1,14 +0,0 @@ -/*xml - - - - - - - - - -*/ - -// xdoc section -- start -// xdoc section -- end