Abstract Class Name Check, updated default regex, issue #595
This commit is contained in:
parent
7c262e61e6
commit
3bcfcac9ee
|
|
@ -41,7 +41,7 @@ import com.puppycrawl.tools.checkstyle.checks.AbstractFormatCheck;
|
|||
public final class AbstractClassNameCheck extends AbstractFormatCheck
|
||||
{
|
||||
/** Default format for abstract class names */
|
||||
private static final String DEFAULT_FORMAT = "^Abstract.*$|^.*Factory$";
|
||||
private static final String DEFAULT_FORMAT = "^Abstract.+$|^.*Factory$";
|
||||
|
||||
/** whether to ignore checking the modifier */
|
||||
private boolean ignoreModifier;
|
||||
|
|
|
|||
|
|
@ -34,10 +34,10 @@ public class AbstractClassNameCheckTest extends BaseCheckTestSupport
|
|||
checkConfig.addAttribute("ignoreModifier", "true");
|
||||
|
||||
final String[] expected = {
|
||||
"3:1: Name 'InputAbstractClassName' must match pattern '^Abstract.*$|^.*Factory$'.",
|
||||
"6:1: Name 'NonAbstractClassName' must match pattern '^Abstract.*$|^.*Factory$'.",
|
||||
"9:1: Name 'FactoryWithBadName' must match pattern '^Abstract.*$|^.*Factory$'.",
|
||||
"13:5: Name 'NonAbstractInnerClass' must match pattern '^Abstract.*$|^.*Factory$'.",
|
||||
"3:1: Name 'InputAbstractClassName' must match pattern '^Abstract.+$|^.*Factory$'.",
|
||||
"6:1: Name 'NonAbstractClassName' must match pattern '^Abstract.+$|^.*Factory$'.",
|
||||
"9:1: Name 'FactoryWithBadName' must match pattern '^Abstract.+$|^.*Factory$'.",
|
||||
"13:5: Name 'NonAbstractInnerClass' must match pattern '^Abstract.+$|^.*Factory$'.",
|
||||
};
|
||||
|
||||
verify(checkConfig, getPath("naming" + File.separator + "InputAbstractClassName.java"), expected);
|
||||
|
|
@ -68,10 +68,10 @@ public class AbstractClassNameCheckTest extends BaseCheckTestSupport
|
|||
checkConfig.addAttribute("ignoreModifier", "false");
|
||||
|
||||
final String[] expected = {
|
||||
"3:1: Name 'InputAbstractClassName' must match pattern '^Abstract.*$|^.*Factory$'.",
|
||||
"6:1: Name 'NonAbstractClassName' must match pattern '^Abstract.*$|^.*Factory$'.",
|
||||
"9:1: Name 'FactoryWithBadName' must match pattern '^Abstract.*$|^.*Factory$'.",
|
||||
"13:5: Name 'NonAbstractInnerClass' must match pattern '^Abstract.*$|^.*Factory$'.",
|
||||
"3:1: Name 'InputAbstractClassName' must match pattern '^Abstract.+$|^.*Factory$'.",
|
||||
"6:1: Name 'NonAbstractClassName' must match pattern '^Abstract.+$|^.*Factory$'.",
|
||||
"9:1: Name 'FactoryWithBadName' must match pattern '^Abstract.+$|^.*Factory$'.",
|
||||
"13:5: Name 'NonAbstractInnerClass' must match pattern '^Abstract.+$|^.*Factory$'.",
|
||||
"26:1: Class 'AbstractClass' must be declared as 'abstract'.",
|
||||
"29:1: Class 'Class1Factory' must be declared as 'abstract'.",
|
||||
"33:5: Class 'AbstractInnerClass' must be declared as 'abstract'.",
|
||||
|
|
@ -80,4 +80,19 @@ public class AbstractClassNameCheckTest extends BaseCheckTestSupport
|
|||
|
||||
verify(checkConfig, getPath("naming" + File.separator + "InputAbstractClassName.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFalsePositive() throws Exception
|
||||
{
|
||||
final DefaultConfiguration checkConfig = createCheckConfig(AbstractClassNameCheck.class);
|
||||
// checkConfig.addAttribute("ignoreName", "false");
|
||||
// checkConfig.addAttribute("ignoreModifier", "false");
|
||||
|
||||
final String[] expected = {
|
||||
"9:5: Class 'AbstractClass' must be declared as 'abstract'.",
|
||||
};
|
||||
|
||||
verify(checkConfig, getPath("naming" + File.separator
|
||||
+ "InputAbstractClassNameFormerFalsePositive.java"), expected);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
package com.puppycrawl.tools.checkstyle.naming;
|
||||
|
||||
public class InputAbstractClassNameFormerFalsePositive
|
||||
{
|
||||
class Abstract {
|
||||
|
||||
}
|
||||
|
||||
class AbstractClass {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -46,7 +46,7 @@
|
|||
<tr>
|
||||
<td><code>AbstractClassName</code></td>
|
||||
<td><code>abstract</code> classes</td>
|
||||
<td><code>^Abstract.*$|^.*Factory$</code></td>
|
||||
<td><code>^Abstract.+$|^.*Factory$</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>ClassTypeParameterName</code></td>
|
||||
|
|
|
|||
Loading…
Reference in New Issue