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:
Tom Copeland
2002-08-01 17:34:08 +00:00
parent 7290a1c45b
commit 4aafb24d51
3 changed files with 6 additions and 4 deletions

View File

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

View File

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

View File

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