modified to use a rule property
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@590 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -21,6 +21,7 @@ public class LongVariableRuleTest
|
||||
public void setUp() {
|
||||
rule = new LongVariableRule();
|
||||
rule.setMessage("Avoid long names like {0}");
|
||||
rule.addProperty("minimumLength", "12");
|
||||
}
|
||||
|
||||
public void testLongVariableField() throws Throwable {
|
||||
|
@ -35,8 +35,11 @@ public class Something {
|
||||
class="net.sourceforge.pmd.rules.LongVariableRule">
|
||||
<description>
|
||||
Long Variable: detects when a field, formal or local variable is declared
|
||||
with a name larger than 12 characters.
|
||||
with a big name.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="minimumLength" value="12"/>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Something {
|
||||
|
@ -10,13 +10,11 @@ import java.text.MessageFormat;
|
||||
public class LongVariableRule
|
||||
extends AbstractRule
|
||||
{
|
||||
public static final int LONG_VARIABLE_LIMIT = 12;
|
||||
|
||||
public Object visit(ASTVariableDeclaratorId decl, Object data) {
|
||||
RuleContext ctx = (RuleContext) data;
|
||||
String image = decl.getImage();
|
||||
|
||||
if (image.length() > LONG_VARIABLE_LIMIT) {
|
||||
if (image.length() > getIntProperty("minimumLength")) {
|
||||
String msg = MessageFormat.format(getMessage(), new Object[] {image});
|
||||
ctx.getReport().addRuleViolation(createRuleViolation(ctx, decl.getBeginLine(), msg));
|
||||
}
|
||||
|
Reference in New Issue
Block a user