AbbreviationAsAWordInName moved to naming package , documentation was rewritten, mTarget was removed from Check (fix after non problematic rebase)

This commit is contained in:
Roman Ivanov 2014-08-02 10:49:46 -07:00
parent 9c9ba5466d
commit 7c5f94aafd
9 changed files with 142 additions and 129 deletions

View File

@ -16,7 +16,7 @@
// 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 java.util.Arrays;
import java.util.HashSet;
@ -31,9 +31,9 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
/**
* <p>
* 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
* <a href="http://google-styleguide.googlecode.com/svn/trunk/javaguide.html#s5.3-camel-case">
* Google Style Guide</a> how to avoid long abbreviations in names
* Google Style Guide</a> to get to know how to avoid long abbreviations in names.
* </p>
* <p>
* Option <code>allowedAbbreviationLength</code> indicates on the allowed amount of capital
@ -46,11 +46,11 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
* no spaces are allowed.
* </p>
* <p>
* Option <code>ignoreFinal</code> allow to skip variables with <code>final<code> modifier.
* Default value is <code>true</code>.
* Option <code>ignoreFinal</code> allow to skip variables with <code>final</code> modifier.
* Default value is <code>true</code>.
* </p>
* <p>
* Option <code>ignoreStatic</code> allow to skip variables with <code>static<code> modifier.
* Option <code>ignoreStatic</code> allow to skip variables with <code>static</code> modifier.
* Default value is <code>true</code>.
* </p>
* <p>
@ -58,20 +58,21 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
* ignore methods tagged with <code>@Override</code> annotation
* (that usually mean inherited name). Default value is <code>true</code>.
* </p>
* Default configuration
* Default configuration
* <pre>
* &lt;module name="AbbreviationAsWordInName"&gt;
* &lt;/module&gt;
* </pre> * <p>
* &lt;module name="AbbreviationAsWordInName" /&gt;
* </pre>
* <p>
* 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.
* </p>
* <pre>
* &lt;module name="AbbreviationAsWordInName"&gt;
* &lt;property name="targets" value="VARIABLE_DEF"/&gt;
* &lt;property name="tokens" value="VARIABLE_DEF,CLASS_DEF"/&gt;
* &lt;property name="ignoreStatic" value="false"/&gt;
* &lt;property name="allowedAbbreviations" value="1"/&gt;
* &lt;property name="allowedAbbreviationLength" value="1"/&gt;
* &lt;property name="allowedAbbreviations" value="XML,URL"/&gt;
* &lt;/module&gt;
* </pre>
*
@ -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

View File

@ -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.

View File

@ -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.

View File

@ -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);
}
/**

View File

@ -19,8 +19,9 @@
</p>
<table>
<tr>
<td><a href="config_misc.html#AbbreviationAsWordInName">AbbreviationAsWordInName</a></td>
<td>Check name of the targeted item to validate abbreviations(capital letters) length in it.</td>
<td><a href="config_naming.html#AbbreviationAsWordInName">AbbreviationAsWordInName</a></td>
<td>The Check validate abbreviations(consecutive capital letters)
length in identifier name, it also allow in enforce camel case naming.</td>
</tr>
<tr>
<td><a href="config_naming.html#AbstractClassName">AbstractClassName</a></td>

View File

@ -1616,87 +1616,6 @@ String unitAbbrev = "\u03bc\u03bc\u03bc";
</p>
</subsection>
</section>
<section name="AbbreviationAsWordInName">
<subsection name="Description">
<p>
Check name of the targeted item to validate
abbreviations(capital letters) length in it.
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
</tr>
<tr>
<td>targets</td>
<td>Array of type forbidden annotation's target.</td>
<td><a href="property_types.html#StringSet">stringSet</a></td>
<td>null</td>
</tr>
<tr>
<td>allowedAbbreviations</td>
<td>List of abbreviations that must be skipped for checking.</td>
<td><a href="property_types.html#StringSet">stringSet</a></td>
<td>null</td>
</tr>
<tr>
<td>ignoreFinal</td>
<td>Allow to skip variables with final declarations.</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td>true</td>
</tr>
<tr>
<td>ignoreStatic</td>
<td>Allow to skip variables with static declarations.</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td>true</td>
</tr>
<tr>
<td>ignoreOverriddenMethod</td>
<td>Allows to ignore methods tagged with '@Override' annotation.</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td>true</td>
</tr>
<tr>
<td>allowedAbbreviationLength</td>
<td>Aallowed amount of capital letters in abbreviations.</td>
<td><a href="property_types.html#integer">Integer</a></td>
<td>true</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure to check variables definitions, forbid skipping
variables with static declarations and allow 'NUMBER' abbreviation.
</p>
<source>
&lt;module name="AbbreviationAsWordInName"&gt;
&lt;property name="targets" value="VARIABLE_DEF"/&gt;
&lt;property name="ignoreStatic" value="false"/&gt;
&lt;property name="allowedAbbreviations" value="NUMBER"/&gt;
&lt;/module&gt;
</source>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="UniqueProperties">
<subsection name="Description">

View File

@ -340,5 +340,97 @@ class MyClass {
&lt;/module&gt;
</source>
</section>
<section name="AbbreviationAsWordInName">
<subsection name="Description">
<p>
The Check validate abbreviations(consecutive capital letters)
length in identifier name, it also allows to enforce camel case naming. Please read more at
<a href="http://google-styleguide.googlecode.com/svn/trunk/javaguide.html#s5.3-camel-case">
Google Style Guide</a>
to get to know how to avoid long abbreviations in names.
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
</tr>
<tr>
<td>allowedAbbreviationLength</td>
<td> indicates on the allowed amount of capital letters in targeted identifiers
(abbreviations in the classes, interfaces, variables and methods names, ... ).</td>
<td><a href="property_types.html#integer">3</a></td>
<td>true</td>
</tr>
<tr>
<td>allowedAbbreviations</td>
<td>list of abbreviations that must be skipped for checking.
Abbreviations should be separated by comma, no spaces are allowed.</td>
<td><a href="property_types.html#StringSet">stringSet</a></td>
<td>null</td>
</tr>
<tr>
<td>ignoreFinal</td>
<td>allow to skip variables with final modifier.</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td>true</td>
</tr>
<tr>
<td>ignoreStatic</td>
<td>allow to skip variables with static modifier.</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td>true</td>
</tr>
<tr>
<td>ignoreOverriddenMethod</td>
<td>Allows to ignore methods tagged with @Override annotation
(that usually mean inherited name).</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td>true</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
Default configuration
<source>
&lt;module name="AbbreviationAsWordInName"/&gt;
</source>
</p>
<p>
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.
</p>
<source>
&lt;module name="AbbreviationAsWordInName"&gt;
&lt;property name="tokens" value="VARIABLE_DEF,CLASS_DEF"/&gt;
&lt;property name="ignoreStatic" value="false"/&gt;
&lt;property name="allowedAbbreviationLength" value="1"/&gt;
&lt;property name="allowedAbbreviation" value="XML,URL"/&gt;
&lt;/module&gt;
</source>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.naming
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
</body>
</document>