diff --git a/pmd/src/net/sourceforge/pmd/AbstractRule.java b/pmd/src/net/sourceforge/pmd/AbstractRule.java index 9fc33e41cc..c3b53ff6d7 100644 --- a/pmd/src/net/sourceforge/pmd/AbstractRule.java +++ b/pmd/src/net/sourceforge/pmd/AbstractRule.java @@ -92,119 +92,145 @@ public abstract class AbstractRule extends JavaParserVisitorAdapter implements R this.properties.putAll(properties); } - public double[] getDoubleProperties(String name) { + public double[] getDoubleProperties(PropertyDescriptor descriptor) { - Number[] values = (Number[])getProperties(name, properties.getProperty(name)); + Number[] values = (Number[])getProperties(descriptor); double[] doubles = new double[values.length]; for (int i=0; i 1) propertyGetError(descriptor, true); + String rawValue = properties.getProperty(descriptor.name()); + return rawValue == null || rawValue.length() == 0 ? descriptor.defaultValue() : descriptor.valueFrom(rawValue); } - public void setProperty(String propertyName, Object value) { - - PropertyDescriptor descriptor = propertyDescriptorFor(propertyName); - + public void setProperty(PropertyDescriptor descriptor, Object value) { + if (descriptor.maxValueCount() > 1) propertySetError(descriptor, true); - properties.setProperty(propertyName, descriptor.asDelimitedString(value)); + properties.setProperty(descriptor.name(), descriptor.asDelimitedString(value)); } - private Object[] getProperties(String propertyName, String rawValue) { - - PropertyDescriptor descriptor = propertyDescriptorFor(propertyName); - + private Object[] getProperties(PropertyDescriptor descriptor) { + if (descriptor.maxValueCount() == 1) propertyGetError(descriptor, false); + String rawValue = properties.getProperty(descriptor.name()); + return rawValue == null || rawValue.length() == 0 ? (Object[])descriptor.defaultValue() : (Object[])descriptor.valueFrom(rawValue); } - public void setProperties(String propertyName, Object[] values) { - - PropertyDescriptor descriptor = propertyDescriptorFor(propertyName); - + public void setProperties(PropertyDescriptor descriptor, Object[] values) { + if (descriptor.maxValueCount() == 1) propertySetError(descriptor, false); - properties.setProperty(propertyName, descriptor.asDelimitedString(values)); + properties.setProperty(descriptor.name(), descriptor.asDelimitedString(values)); } private void propertyGetError(PropertyDescriptor descriptor, boolean requestedSingleValue) { diff --git a/pmd/src/net/sourceforge/pmd/rules/AvoidDeeplyNestedIfStmtsRule.java b/pmd/src/net/sourceforge/pmd/rules/AvoidDeeplyNestedIfStmtsRule.java index 59ea725b86..9f27c798cf 100644 --- a/pmd/src/net/sourceforge/pmd/rules/AvoidDeeplyNestedIfStmtsRule.java +++ b/pmd/src/net/sourceforge/pmd/rules/AvoidDeeplyNestedIfStmtsRule.java @@ -27,7 +27,7 @@ public class AvoidDeeplyNestedIfStmtsRule extends AbstractRule { public Object visit(ASTCompilationUnit node, Object data) { depth = 0; - depthLimit = getIntProperty("problemDepth"); + depthLimit = getIntProperty(problemDepthDescriptor); return super.visit(node, data); } diff --git a/pmd/src/net/sourceforge/pmd/rules/design/TooManyFields.java b/pmd/src/net/sourceforge/pmd/rules/design/TooManyFields.java index 261a7df9f1..b81ca83d0e 100644 --- a/pmd/src/net/sourceforge/pmd/rules/design/TooManyFields.java +++ b/pmd/src/net/sourceforge/pmd/rules/design/TooManyFields.java @@ -37,8 +37,7 @@ public class TooManyFields extends AbstractRule { public Object visit(ASTCompilationUnit node, Object data) { - // TODO - remove hasProperty check once new system is in place, default supplied automatically - maxFields = hasProperty("maxfields") ? getIntProperty("maxfields") : DEFAULT_MAXFIELDS; + maxFields = getIntProperty(maxFieldsDescriptor); stats = new HashMap(5); nodes = new HashMap(5);