From 7c5f94aafd422312a6c19a36f53796d547788827 Mon Sep 17 00:00:00 2001
From: Roman Ivanov
* The Check validate abbreviations(consecutive capital letters) length in
- * identifier name. Please read more at
+ * identifier name, it also allows to enforce camel case naming. Please read more at
*
- * Google Style Guide how to avoid long abbreviations in names
+ * Google Style Guide to get to know how to avoid long abbreviations in names.
*
* Option
- * Option
- * Option
@@ -58,20 +58,21 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
* ignore methods tagged with
+ * <module name="AbbreviationAsWordInName" />
+ *
+ *
* To configure to check variables and classes identifiers, do not ignore
* variables with static modifier
- * and allow no abbreviations to use (camel case phrase).
+ * and allow no abbreviations (enforce camel case phrase) but allow XML and URL abbreviations.
* allowedAbbreviationLength indicates on the allowed amount of capital
@@ -46,11 +46,11 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
* no spaces are allowed.
* ignoreFinal allow to skip variables with final modifier.
- * Default value is true.
+ * Option ignoreFinal allow to skip variables with final modifier.
+ * Default value is true.
* ignoreStatic allow to skip variables with static modifier.
+ * Option ignoreStatic allow to skip variables with static modifier.
* Default value is true.
* @Override annotation
* (that usually mean inherited name). Default value is true.
*
- * <module name="AbbreviationAsWordInName">
- * </module>
- *
*
* <module name="AbbreviationAsWordInName">
- * <property name="targets" value="VARIABLE_DEF"/>
+ * <property name="tokens" value="VARIABLE_DEF,CLASS_DEF"/>
* <property name="ignoreStatic" value="false"/>
- * <property name="allowedAbbreviations" value="1"/>
+ * <property name="allowedAbbreviationLength" value="1"/>
+ * <property name="allowedAbbreviations" value="XML,URL"/>
* </module>
*
*
@@ -170,15 +171,15 @@ public class AbbreviationAsWordInNameCheck extends Check
public int[] getDefaultTokens()
{
return new int[] {
- TokenTypes.CLASS_DEF,
- TokenTypes.INTERFACE_DEF,
- TokenTypes.ENUM_DEF,
- TokenTypes.ANNOTATION_DEF,
- TokenTypes.ANNOTATION_FIELD_DEF,
- TokenTypes.PARAMETER_DEF,
- TokenTypes.VARIABLE_DEF,
- TokenTypes.METHOD_DEF
- };
+ TokenTypes.CLASS_DEF,
+ TokenTypes.INTERFACE_DEF,
+ TokenTypes.ENUM_DEF,
+ TokenTypes.ANNOTATION_DEF,
+ TokenTypes.ANNOTATION_FIELD_DEF,
+ TokenTypes.PARAMETER_DEF,
+ TokenTypes.VARIABLE_DEF,
+ TokenTypes.METHOD_DEF,
+ };
}
@Override
diff --git a/src/main/resources/com/puppycrawl/tools/checkstyle/checks/messages.properties b/src/main/resources/com/puppycrawl/tools/checkstyle/checks/messages.properties
index 10649bfc7..ba80f815f 100644
--- a/src/main/resources/com/puppycrawl/tools/checkstyle/checks/messages.properties
+++ b/src/main/resources/com/puppycrawl/tools/checkstyle/checks/messages.properties
@@ -32,5 +32,3 @@ properties.duplicateproperty=Duplicated property ''{0}'' ({1} occurrence(s)).
unable.open.cause=Unable to open ''{0}'': {1}.
forbid.escaped.unicode.char=Unicode escape(s) usage should be avoided.
-
-abbreviation.as.word=Abbreviation in name must contain no more than ''{0}'' capital letters.
diff --git a/src/main/resources/com/puppycrawl/tools/checkstyle/checks/naming/messages.properties b/src/main/resources/com/puppycrawl/tools/checkstyle/checks/naming/messages.properties
index 2cd17035b..fe363cf84 100644
--- a/src/main/resources/com/puppycrawl/tools/checkstyle/checks/naming/messages.properties
+++ b/src/main/resources/com/puppycrawl/tools/checkstyle/checks/naming/messages.properties
@@ -2,3 +2,5 @@ name.invalidPattern=Name ''{0}'' must match pattern ''{1}''.
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 must contain no more than ''{0}'' capital letters.
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/AbbreviationAsWordInNameCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/AbbreviationAsWordInNameCheckTest.java
similarity index 87%
rename from src/test/java/com/puppycrawl/tools/checkstyle/checks/AbbreviationAsWordInNameCheckTest.java
rename to src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/AbbreviationAsWordInNameCheckTest.java
index 6ea2eaae5..841d5abcd 100644
--- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/AbbreviationAsWordInNameCheckTest.java
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/AbbreviationAsWordInNameCheckTest.java
@@ -16,9 +16,9 @@
// 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;
+package com.puppycrawl.tools.checkstyle.checks.naming;
-import static com.puppycrawl.tools.checkstyle.checks.AbbreviationAsWordInNameCheck.MSG_KEY;
+import static com.puppycrawl.tools.checkstyle.checks.naming.AbbreviationAsWordInNameCheck.MSG_KEY;
import static java.text.MessageFormat.format;
import org.junit.Test;
@@ -41,7 +41,7 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport
warningMessage = getCheckMessage(MSG_KEY, expectedCapitalCount);
checkConfig.addAttribute("allowedAbbreviationLength", String.valueOf(expectedCapitalCount));
checkConfig.addAttribute("allowedAbbreviations", "III");
- checkConfig.addAttribute("targets", "CLASS_DEF");
+ checkConfig.addAttribute("tokens", "CLASS_DEF");
checkConfig.addAttribute("ignoreOverriddenMethods", "true");
final String[] expected = {
@@ -51,7 +51,7 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport
"37: " + warningMessage,
};
- verify(checkConfig, getPath("InputAbbreviationAsWordInTypeNameCheck.java"), expected);
+ verify(checkConfig, getPath("naming/InputAbbreviationAsWordInTypeNameCheck.java"), expected);
}
@Test
@@ -63,14 +63,14 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport
final DefaultConfiguration checkConfig = createCheckConfig(AbbreviationAsWordInNameCheck.class);
checkConfig.addAttribute("allowedAbbreviationLength", String.valueOf(expectedCapitalCount));
checkConfig.addAttribute("allowedAbbreviations", "CLASS,FACTORY");
- checkConfig.addAttribute("targets", "CLASS_DEF");
+ checkConfig.addAttribute("tokens", "CLASS_DEF");
checkConfig.addAttribute("ignoreOverriddenMethods", "true");
final String[] expected = {
"32: " + warningMessage,
};
- verify(checkConfig, getPath("InputAbbreviationAsWordInTypeNameCheck.java"), expected);
+ verify(checkConfig, getPath("naming/InputAbbreviationAsWordInTypeNameCheck.java"), expected);
}
@Test
@@ -82,14 +82,14 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport
final DefaultConfiguration checkConfig = createCheckConfig(AbbreviationAsWordInNameCheck.class);
checkConfig.addAttribute("allowedAbbreviationLength", String.valueOf(expectedCapitalCount));
checkConfig.addAttribute("allowedAbbreviations", "CLASS");
- checkConfig.addAttribute("targets", "CLASS_DEF");
+ checkConfig.addAttribute("tokens", "CLASS_DEF");
checkConfig.addAttribute("ignoreOverriddenMethods", "true");
final String[] expected = {
"32: " + warningMessage,
"37: " + warningMessage,
};
- verify(checkConfig, getPath("InputAbbreviationAsWordInTypeNameCheck.java"), expected);
+ verify(checkConfig, getPath("naming/InputAbbreviationAsWordInTypeNameCheck.java"), expected);
}
@Test
@@ -101,7 +101,7 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport
final DefaultConfiguration checkConfig = createCheckConfig(AbbreviationAsWordInNameCheck.class);
checkConfig.addAttribute("allowedAbbreviationLength", String.valueOf(expectedCapitalCount));
checkConfig.addAttribute("allowedAbbreviations", "CLASS");
- checkConfig.addAttribute("targets", "CLASS_DEF"
+ checkConfig.addAttribute("tokens", "CLASS_DEF"
+ ",VARIABLE_DEF"
+ ",METHOD_DEF,ENUM_DEF,ENUM_CONSTANT_DEF"
+ ",PARAMETER_DEF,INTERFACE_DEF,ANNOTATION_DEF");
@@ -116,7 +116,7 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport
"58: " + warningMessage,
};
- verify(checkConfig, getPath("InputAbbreviationAsWordInTypeNameCheck.java"), expected);
+ verify(checkConfig, getPath("naming/InputAbbreviationAsWordInTypeNameCheck.java"), expected);
}
@Test
@@ -130,7 +130,7 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport
checkConfig.addAttribute("allowedAbbreviations", "NUMBER,MARAZMATIC,VARIABLE");
checkConfig.addAttribute("ignoreStatic", "false");
checkConfig.addAttribute("ignoreFinal", "false");
- checkConfig.addAttribute("targets", "CLASS_DEF"
+ checkConfig.addAttribute("tokens", "CLASS_DEF"
+ ",VARIABLE_DEF"
+ ",METHOD_DEF,ENUM_DEF,ENUM_CONSTANT_DEF"
+ ",PARAMETER_DEF,INTERFACE_DEF,ANNOTATION_DEF");
@@ -146,7 +146,7 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport
"84: " + warningMessage,
};
- verify(checkConfig, getPath("InputAbbreviationAsWordInTypeNameCheck.java"), expected);
+ verify(checkConfig, getPath("naming/InputAbbreviationAsWordInTypeNameCheck.java"), expected);
}
@Test
@@ -160,7 +160,7 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport
checkConfig.addAttribute("allowedAbbreviations", "NUMBER,MARAZMATIC,VARIABLE");
checkConfig.addAttribute("ignoreStatic", "true");
checkConfig.addAttribute("ignoreFinal", "true");
- checkConfig.addAttribute("targets", "CLASS_DEF"
+ checkConfig.addAttribute("tokens", "CLASS_DEF"
+ ",VARIABLE_DEF"
+ ",METHOD_DEF,ENUM_DEF,ENUM_CONSTANT_DEF"
+ ",PARAMETER_DEF,INTERFACE_DEF,ANNOTATION_DEF");
@@ -172,7 +172,7 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport
"38: " + warningMessage,
};
- verify(checkConfig, getPath("InputAbbreviationAsWordInTypeNameCheck.java"), expected);
+ verify(checkConfig, getPath("naming/InputAbbreviationAsWordInTypeNameCheck.java"), expected);
}
@Test
@@ -186,7 +186,7 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport
checkConfig.addAttribute("allowedAbbreviations", "MARAZMATIC,VARIABLE");
checkConfig.addAttribute("ignoreStatic", "false");
checkConfig.addAttribute("ignoreFinal", "true");
- checkConfig.addAttribute("targets", "CLASS_DEF"
+ checkConfig.addAttribute("tokens", "CLASS_DEF"
+ ",VARIABLE_DEF"
+ ",METHOD_DEF,ENUM_DEF,ENUM_CONSTANT_DEF"
+ ",PARAMETER_DEF,INTERFACE_DEF,ANNOTATION_DEF");
@@ -201,7 +201,7 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport
"60: " + warningMessage, // no ignore for static
};
- verify(checkConfig, getPath("InputAbbreviationAsWordInTypeNameCheck.java"), expected);
+ verify(checkConfig, getPath("naming/InputAbbreviationAsWordInTypeNameCheck.java"), expected);
}
@Test
@@ -215,7 +215,7 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport
checkConfig.addAttribute("allowedAbbreviations", "MARAZMATIC,VARIABLE");
checkConfig.addAttribute("ignoreStatic", "true");
checkConfig.addAttribute("ignoreFinal", "false");
- checkConfig.addAttribute("targets", "CLASS_DEF"
+ checkConfig.addAttribute("tokens", "CLASS_DEF"
+ ",VARIABLE_DEF"
+ ",METHOD_DEF,ENUM_DEF,ENUM_CONSTANT_DEF"
+ ",PARAMETER_DEF,INTERFACE_DEF,ANNOTATION_DEF");
@@ -229,7 +229,7 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport
"59: " + warningMessage, // no ignore for final
};
- verify(checkConfig, getPath("InputAbbreviationAsWordInTypeNameCheck.java"), expected);
+ verify(checkConfig, getPath("naming/InputAbbreviationAsWordInTypeNameCheck.java"), expected);
}
@Test
@@ -241,7 +241,7 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport
warningMessage = getCheckMessage(MSG_KEY, expectedCapitalCount);
checkConfig.addAttribute("allowedAbbreviationLength", String.valueOf(expectedCapitalCount));
checkConfig.addAttribute("allowedAbbreviations", "");
- checkConfig.addAttribute("targets", "CLASS_DEF, METHOD_DEF");
+ checkConfig.addAttribute("tokens", "CLASS_DEF, METHOD_DEF");
checkConfig.addAttribute("ignoreOverriddenMethods", "true");
final String[] expected = {
@@ -249,7 +249,7 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport
};
verify(checkConfig,
- getPath("InputAbbreviationAsWordInTypeNameCheckOverridableMethod.java"), expected);
+ getPath("naming/InputAbbreviationAsWordInTypeNameCheckOverridableMethod.java"), expected);
}
@Test
@@ -265,7 +265,7 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport
checkConfig.addAttribute("ignoreStatic", "false");
checkConfig.addAttribute("ignoreFinal", "false");
checkConfig.addAttribute("ignoreOverriddenMethods", "false");
- checkConfig.addAttribute("targets", "CLASS_DEF,INTERFACE_DEF,ENUM_DEF,"
+ checkConfig.addAttribute("tokens", "CLASS_DEF,INTERFACE_DEF,ENUM_DEF,"
+ "ANNOTATION_DEF,ANNOTATION_FIELD_DEF,ENUM_CONSTANT_DEF,"
+ "PARAMETER_DEF,VARIABLE_DEF,METHOD_DEF");
final String[] expected = {
@@ -296,7 +296,7 @@ public class AbbreviationAsWordInNameCheckTest extends BaseCheckTestSupport
"98: " + warningMessage,
};
verify(checkConfig,
- getPath("InputAbbreviationAsWordInTypeNameCheck.java"), expected);
+ getPath("naming/InputAbbreviationAsWordInTypeNameCheck.java"), expected);
}
/**
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/InputAbbreviationAsWordInTypeNameCheck.java b/src/test/resources/com/puppycrawl/tools/checkstyle/naming/InputAbbreviationAsWordInTypeNameCheck.java
similarity index 100%
rename from src/test/resources/com/puppycrawl/tools/checkstyle/InputAbbreviationAsWordInTypeNameCheck.java
rename to src/test/resources/com/puppycrawl/tools/checkstyle/naming/InputAbbreviationAsWordInTypeNameCheck.java
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/InputAbbreviationAsWordInTypeNameCheckOverridableMethod.java b/src/test/resources/com/puppycrawl/tools/checkstyle/naming/InputAbbreviationAsWordInTypeNameCheckOverridableMethod.java
similarity index 100%
rename from src/test/resources/com/puppycrawl/tools/checkstyle/InputAbbreviationAsWordInTypeNameCheckOverridableMethod.java
rename to src/test/resources/com/puppycrawl/tools/checkstyle/naming/InputAbbreviationAsWordInTypeNameCheckOverridableMethod.java
diff --git a/src/xdocs/availablechecks.xml b/src/xdocs/availablechecks.xml
index 1a8514974..893c9bf5b 100644
--- a/src/xdocs/availablechecks.xml
+++ b/src/xdocs/availablechecks.xml
@@ -19,8 +19,9 @@
| AbbreviationAsWordInName | -Check name of the targeted item to validate abbreviations(capital letters) length in it. | +AbbreviationAsWordInName | +The Check validate abbreviations(consecutive capital letters) + length in identifier name, it also allow in enforce camel case naming. | |||||||||||||||||||||||||||||||||||||||||||||||||
| AbstractClassName | diff --git a/src/xdocs/config_misc.xml b/src/xdocs/config_misc.xml index 5966daff8..d20e28b40 100755 --- a/src/xdocs/config_misc.xml +++ b/src/xdocs/config_misc.xml @@ -1616,87 +1616,6 @@ String unitAbbrev = "\u03bc\u03bc\u03bc"; -
| name | -description | -type | -default value | -
|---|---|---|---|
| targets | -Array of type forbidden annotation's target. | -stringSet | -null | -
| allowedAbbreviations | -List of abbreviations that must be skipped for checking. | -stringSet | -null | -
| ignoreFinal | -Allow to skip variables with final declarations. | -Boolean | -true | -
| ignoreStatic | -Allow to skip variables with static declarations. | -Boolean | -true | -
| ignoreOverriddenMethod | -Allows to ignore methods tagged with '@Override' annotation. | -Boolean | -true | -
| allowedAbbreviationLength | -Aallowed amount of capital letters in abbreviations. | -Integer | -true | -
- To configure to check variables definitions, forbid skipping - variables with static declarations and allow 'NUMBER' abbreviation. -
-- com.puppycrawl.tools.checkstyle.checks -
-- TreeWalker -
-+ The Check validate abbreviations(consecutive capital letters) + length in identifier name, it also allows to enforce camel case naming. Please read more at + + Google Style Guide + to get to know how to avoid long abbreviations in names. +
+| name | +description | +type | +default value | +
|---|---|---|---|
| allowedAbbreviationLength | +indicates on the allowed amount of capital letters in targeted identifiers + (abbreviations in the classes, interfaces, variables and methods names, ... ). | +3 | +true | +
| allowedAbbreviations | +list of abbreviations that must be skipped for checking. + Abbreviations should be separated by comma, no spaces are allowed. | +stringSet | +null | +
| ignoreFinal | +allow to skip variables with final modifier. | +Boolean | +true | +
| ignoreStatic | +allow to skip variables with static modifier. | +Boolean | +true | +
| ignoreOverriddenMethod | +Allows to ignore methods tagged with @Override annotation + (that usually mean inherited name). | +Boolean | +true | +
+ Default configuration
+
+ To configure to check variables and classes identifiers, + do not ignore variables with static modifier and allow + no abbreviations (enforce camel case phrase) and + allow no abbreviations to use (camel case phrase) and allow XML and URL abbreviations. +
++ com.puppycrawl.tools.checkstyle.checks.naming +
++ TreeWalker +
+