Issue #3721: expanded message and documentation AbbreviationAsWordInName

This commit is contained in:
rnveach 2017-02-13 11:09:45 -05:00 committed by Roman Ivanov
parent 1aa8bcf788
commit a103ccf92b
5 changed files with 46 additions and 26 deletions

View File

@ -42,7 +42,7 @@ public class AbbreviationAsWordInNameTest extends BaseCheckTestSupport {
@Test
public void abbreviationAsWordInNameTest() throws Exception {
final int maxCapitalCount = 1;
final int maxCapitalCount = 2;
final String[] expected = {
"50: " + getWarningMessage("newCustomerID", maxCapitalCount),

View File

@ -40,6 +40,16 @@ import com.puppycrawl.tools.checkstyle.utils.CommonUtils;
* Google Style Guide</a> to get to know how to avoid long abbreviations in names.
* </p>
* <p>
* {@code allowedAbbreviationLength} specifies how many consecutive capital letters are
* allowed in the identifier.
* A value of <i>3</i> indicates that up to 4 consecutive capital letters are allowed,
* one after the other, before a violation is printed. The identifier 'MyTEST' would be
* allowed, but 'MyTESTS' would not be.
* A value of <i>0</i> indicates that only 1 consecutive capital letter is allowed. This
* is what should be used to enforce strict camel casing. The identifier 'MyTest' would
* be allowed, but 'MyTEst' would not be.
* </p>
* <p>
* Option {@code allowedAbbreviationLength} indicates on the allowed amount of capital
* letters in abbreviations in the classes, interfaces,
* variables and methods names. Default value is '3'.
@ -209,7 +219,7 @@ public class AbbreviationAsWordInNameCheck extends AbstractCheck {
final String abbr = getDisallowedAbbreviation(typeName);
if (abbr != null) {
log(nameAst.getLineNo(), MSG_KEY, typeName, allowedAbbreviationLength);
log(nameAst.getLineNo(), MSG_KEY, typeName, allowedAbbreviationLength + 1);
}
}
}

View File

@ -3,4 +3,4 @@ illegal.abstract.class.name=Name ''{0}'' must match pattern ''{1}''.
method.name.equals.class.name=Method Name ''{0}'' must not equal the enclosing class name.
no.abstract.class.modifier=Class ''{0}'' must be declared as ''abstract''.
abbreviation.as.word=Abbreviation in name ''{0}'' must contain no more than ''{1}'' capital letters.
abbreviation.as.word=Abbreviation in name ''{0}'' must contain no more than ''{1}'' consecutive capital letters.

View File

@ -43,11 +43,11 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport {
final DefaultConfiguration checkConfig =
createCheckConfig(AbbreviationAsWordInNameCheck.class);
final int expectedCapitalCount = 3;
checkConfig.addAttribute("allowedAbbreviationLength", String.valueOf(expectedCapitalCount));
checkConfig.addAttribute("allowedAbbreviationLength", "3");
checkConfig.addAttribute("allowedAbbreviations", "III");
checkConfig.addAttribute("tokens", "CLASS_DEF");
checkConfig.addAttribute("ignoreOverriddenMethods", "true");
final int expectedCapitalCount = 4;
final String[] expected = {
"9: " + getWarningMessage("FactoryWithBADNAme", expectedCapitalCount),
@ -62,13 +62,13 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport {
@Test
public void testTypeNamesForFourPermittedCapitalLetters() throws Exception {
final int expectedCapitalCount = 4;
final DefaultConfiguration checkConfig =
createCheckConfig(AbbreviationAsWordInNameCheck.class);
checkConfig.addAttribute("allowedAbbreviationLength", String.valueOf(expectedCapitalCount));
checkConfig.addAttribute("allowedAbbreviationLength", "4");
checkConfig.addAttribute("allowedAbbreviations", "CLASS,FACTORY");
checkConfig.addAttribute("tokens", "CLASS_DEF");
checkConfig.addAttribute("ignoreOverriddenMethods", "true");
final int expectedCapitalCount = 5;
final String[] expected = {
"32: " + getWarningMessage("AbstractINNERRClass", expectedCapitalCount),
@ -80,13 +80,13 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport {
@Test
public void testTypeNamesForFivePermittedCapitalLetters() throws Exception {
final int expectedCapitalCount = 5;
final DefaultConfiguration checkConfig =
createCheckConfig(AbbreviationAsWordInNameCheck.class);
checkConfig.addAttribute("allowedAbbreviationLength", String.valueOf(expectedCapitalCount));
checkConfig.addAttribute("allowedAbbreviationLength", "5");
checkConfig.addAttribute("allowedAbbreviations", "CLASS");
checkConfig.addAttribute("tokens", "CLASS_DEF");
checkConfig.addAttribute("ignoreOverriddenMethods", "true");
final int expectedCapitalCount = 6;
final String[] expected = {
"32: " + getWarningMessage("AbstractINNERRClass", expectedCapitalCount),
"37: " + getWarningMessage("WellNamedFACTORY", expectedCapitalCount),
@ -98,16 +98,16 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport {
@Test
public void testTypeAndVariablesAndMethodNames() throws Exception {
final int expectedCapitalCount = 5;
final DefaultConfiguration checkConfig =
createCheckConfig(AbbreviationAsWordInNameCheck.class);
checkConfig.addAttribute("allowedAbbreviationLength", String.valueOf(expectedCapitalCount));
checkConfig.addAttribute("allowedAbbreviationLength", "5");
checkConfig.addAttribute("allowedAbbreviations", "CLASS");
checkConfig.addAttribute("tokens", "CLASS_DEF"
+ ",VARIABLE_DEF"
+ ",METHOD_DEF,ENUM_DEF,ENUM_CONSTANT_DEF"
+ ",PARAMETER_DEF,INTERFACE_DEF,ANNOTATION_DEF");
checkConfig.addAttribute("ignoreOverriddenMethods", "true");
final int expectedCapitalCount = 6;
final String[] expected = {
"32: " + getWarningMessage("AbstractINNERRClass", expectedCapitalCount),
@ -124,10 +124,9 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport {
@Test
public void testTypeAndVariablesAndMethodNamesWithNoIgnores() throws Exception {
final int expectedCapitalCount = 5;
final DefaultConfiguration checkConfig =
createCheckConfig(AbbreviationAsWordInNameCheck.class);
checkConfig.addAttribute("allowedAbbreviationLength", String.valueOf(expectedCapitalCount));
checkConfig.addAttribute("allowedAbbreviationLength", "5");
checkConfig.addAttribute("allowedAbbreviations", "NUMBER,MARAZMATIC,VARIABLE");
checkConfig.addAttribute("ignoreStatic", "false");
checkConfig.addAttribute("ignoreFinal", "false");
@ -136,6 +135,7 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport {
+ ",METHOD_DEF,ENUM_DEF,ENUM_CONSTANT_DEF"
+ ",PARAMETER_DEF,INTERFACE_DEF,ANNOTATION_DEF");
checkConfig.addAttribute("ignoreOverriddenMethods", "true");
final int expectedCapitalCount = 6;
final String[] expected = {
"32: " + getWarningMessage("AbstractINNERRClass", expectedCapitalCount),
@ -153,10 +153,9 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport {
@Test
public void testTypeAndVariablesAndMethodNamesWithIgnores() throws Exception {
final int expectedCapitalCount = 5;
final DefaultConfiguration checkConfig =
createCheckConfig(AbbreviationAsWordInNameCheck.class);
checkConfig.addAttribute("allowedAbbreviationLength", String.valueOf(expectedCapitalCount));
checkConfig.addAttribute("allowedAbbreviationLength", "5");
checkConfig.addAttribute("allowedAbbreviations", "NUMBER,MARAZMATIC,VARIABLE");
checkConfig.addAttribute("ignoreStatic", "true");
checkConfig.addAttribute("ignoreFinal", "true");
@ -165,6 +164,7 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport {
+ ",METHOD_DEF,ENUM_DEF,ENUM_CONSTANT_DEF"
+ ",PARAMETER_DEF,INTERFACE_DEF,ANNOTATION_DEF");
checkConfig.addAttribute("ignoreOverriddenMethods", "true");
final int expectedCapitalCount = 6;
final String[] expected = {
"32: " + getWarningMessage("AbstractINNERRClass", expectedCapitalCount),
@ -178,10 +178,9 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport {
@Test
public void testTypeAndVariablesAndMethodNamesWithIgnoresFinal() throws Exception {
final int expectedCapitalCount = 4;
final DefaultConfiguration checkConfig =
createCheckConfig(AbbreviationAsWordInNameCheck.class);
checkConfig.addAttribute("allowedAbbreviationLength", String.valueOf(expectedCapitalCount));
checkConfig.addAttribute("allowedAbbreviationLength", "4");
checkConfig.addAttribute("allowedAbbreviations", "MARAZMATIC,VARIABLE");
checkConfig.addAttribute("ignoreStatic", "false");
checkConfig.addAttribute("ignoreFinal", "true");
@ -190,6 +189,7 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport {
+ ",METHOD_DEF,ENUM_DEF,ENUM_CONSTANT_DEF"
+ ",PARAMETER_DEF,INTERFACE_DEF,ANNOTATION_DEF");
checkConfig.addAttribute("ignoreOverriddenMethods", "true");
final int expectedCapitalCount = 5;
final String[] expected = {
"12: " + getWarningMessage("AbstractCLASSName", expectedCapitalCount),
@ -207,10 +207,9 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport {
@Test
public void testTypeAndVariablesAndMethodNamesWithIgnoresStatic() throws Exception {
final int expectedCapitalCount = 5;
final DefaultConfiguration checkConfig =
createCheckConfig(AbbreviationAsWordInNameCheck.class);
checkConfig.addAttribute("allowedAbbreviationLength", String.valueOf(expectedCapitalCount));
checkConfig.addAttribute("allowedAbbreviationLength", "5");
checkConfig.addAttribute("allowedAbbreviations", "MARAZMATIC,VARIABLE");
checkConfig.addAttribute("ignoreStatic", "true");
checkConfig.addAttribute("ignoreFinal", "false");
@ -219,6 +218,7 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport {
+ ",METHOD_DEF,ENUM_DEF,ENUM_CONSTANT_DEF"
+ ",PARAMETER_DEF,INTERFACE_DEF,ANNOTATION_DEF");
checkConfig.addAttribute("ignoreOverriddenMethods", "true");
final int expectedCapitalCount = 6;
final String[] expected = {
"32: " + getWarningMessage("AbstractINNERRClass", expectedCapitalCount),
@ -238,11 +238,11 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport {
final DefaultConfiguration checkConfig =
createCheckConfig(AbbreviationAsWordInNameCheck.class);
final int expectedCapitalCount = 3;
checkConfig.addAttribute("allowedAbbreviationLength", String.valueOf(expectedCapitalCount));
checkConfig.addAttribute("allowedAbbreviationLength", "3");
checkConfig.addAttribute("allowedAbbreviations", "");
checkConfig.addAttribute("tokens", "CLASS_DEF, METHOD_DEF");
checkConfig.addAttribute("ignoreOverriddenMethods", "true");
final int expectedCapitalCount = 4;
final String[] expected = {
"22: " + getWarningMessage("oveRRRRRrriddenMethod", expectedCapitalCount),
@ -256,9 +256,8 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport {
public void testTypeNamesForZeroPermittedCapitalLetter() throws Exception {
final DefaultConfiguration checkConfig =
createCheckConfig(AbbreviationAsWordInNameCheck.class);
final int expectedCapitalCount = 0;
checkConfig.addAttribute("allowedAbbreviationLength",
String.valueOf(expectedCapitalCount));
"0");
checkConfig.addAttribute("allowedAbbreviations", "");
checkConfig.addAttribute("ignoreStatic", "false");
checkConfig.addAttribute("ignoreFinal", "false");
@ -266,6 +265,7 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport {
checkConfig.addAttribute("tokens", "CLASS_DEF,INTERFACE_DEF,ENUM_DEF,"
+ "ANNOTATION_DEF,ANNOTATION_FIELD_DEF,ENUM_CONSTANT_DEF,"
+ "PARAMETER_DEF,VARIABLE_DEF,METHOD_DEF");
final int expectedCapitalCount = 1;
final String[] expected = {
"3: " + getWarningMessage("IIIInputAbstractClassName", expectedCapitalCount),
"6: " + getWarningMessage("NonAAAAbstractClassName", expectedCapitalCount),
@ -306,8 +306,7 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport {
final DefaultConfiguration checkConfig =
createCheckConfig(AbbreviationAsWordInNameCheck.class);
final int expectedCapitalCount = 1;
checkConfig.addAttribute("allowedAbbreviationLength", String.valueOf(expectedCapitalCount));
checkConfig.addAttribute("allowedAbbreviationLength", "2");
checkConfig.addAttribute("ignoreFinal", "false");
checkConfig.addAttribute("allowedAbbreviations", null);

View File

@ -40,6 +40,17 @@
Google Style Guide</a>
to get to know how to avoid long abbreviations in names.
</p>
<p>
<i>allowedAbbreviationLength</i> specifies how many consecutive capital letters are
allowed in the identifier.
A value of <i>3</i> indicates that up to 4 consecutive capital letters are allowed,
one after the other, before a violation is printed. The identifier 'MyTEST' would be
allowed, but 'MyTESTS' would not be.
A value of <i>0</i> indicates that only 1 consecutive capital letter is allowed. This
is what should be used to enforce strict camel casing. The identifier 'MyTest' would
be allowed, but 'MyTEst' would not be.
</p>
</subsection>
<subsection name="Properties">
@ -52,7 +63,7 @@
</tr>
<tr>
<td>allowedAbbreviationLength</td>
<td>indicates on the allowed amount of capital letters in targeted identifiers
<td>indicates on the number of consecutive capital letters allowed in targeted identifiers
(abbreviations in the classes, interfaces, variables and methods names, ... ).</td>
<td><a href="property_types.html#integer">Integer</a></td>
<td>3</td>