diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/PropertyDescriptor.java b/pmd-core/src/main/java/net/sourceforge/pmd/PropertyDescriptor.java index 342a12aacb..57bd7d7b2e 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/PropertyDescriptor.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/PropertyDescriptor.java @@ -106,7 +106,7 @@ public interface PropertyDescriptor extends Comparable> /** - * Retunrs the value represented by this string. + * Returns the value represented by this string. * * @param propertyString The string to parse * diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/PropertyDescriptorField.java b/pmd-core/src/main/java/net/sourceforge/pmd/PropertyDescriptorField.java index 356b5e9a0e..55f97a21a8 100755 --- a/pmd-core/src/main/java/net/sourceforge/pmd/PropertyDescriptorField.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/PropertyDescriptorField.java @@ -41,7 +41,7 @@ public enum PropertyDescriptorField { /** Default index for enumerated properties. */ DEFAULT_INDEX("defaultIndex"); - final String attributeName; + private final String attributeName; PropertyDescriptorField(String attributeName) { @@ -49,9 +49,19 @@ public enum PropertyDescriptorField { } - @Override - public String toString() { + /** + * Returns the String name of this attribute. + * + * @return The attribute's name + */ + public String attributeName() { return attributeName; } + + @Override + public String toString() { + return attributeName(); + } + } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java index 50982078fa..d3ccdc6233 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java @@ -723,14 +723,14 @@ public class RuleSetFactory { } } + /** * Check whether the given ruleName is contained in the given ruleset. * - * @param ruleSetReferenceId - * the ruleset to check - * @param ruleName - * the rule name to search for - * @return true if the ruleName exists + * @param ruleSetReferenceId the ruleset to check + * @param ruleName the rule name to search for + * + * @return {@code true} if the ruleName exists */ private boolean containsRule(RuleSetReferenceId ruleSetReferenceId, String ruleName) { boolean found = false; @@ -788,68 +788,39 @@ public class RuleSetFactory { return null; } + /** - * Parse a property node. + * Sets the value of a property. * - * @param rule - * The Rule to which the property should be added. //@param - * propertyNode Must be a property element node. + * @param rule The rule which has the property + * @param desc The property descriptor + * @param strValue The string value of the property, converted to a T + * @param The type of values of the property descriptor */ - // private static void parsePropertyNode(Rule rule, Node propertyNode) { - // Element propertyElement = (Element) propertyNode; - // String name = propertyElement.getAttribute("name"); - // String description = propertyElement.getAttribute("description"); - // String type = propertyElement.getAttribute("type"); - // String delimiter = propertyElement.getAttribute("delimiter"); - // String min = propertyElement.getAttribute("min"); - // String max = propertyElement.getAttribute("max"); - // String value = propertyElement.getAttribute("value"); - // - // // If value not provided, get from child element. - // if (StringUtil.isEmpty(value)) { - // for (int i = 0; i < propertyNode.getChildNodes().getLength(); i++) { - // Node node = propertyNode.getChildNodes().item(i); - // if ((node.getNodeType() == Node.ELEMENT_NODE) && - // node.getNodeName().equals("value")) { - // value = parseTextNode(node); - // } - // } - // } - // - // // Setting of existing property, or defining a new property? - // if (StringUtil.isEmpty(type)) { - // PropertyDescriptor propertyDescriptor = rule.getPropertyDescriptor(name); - // if (propertyDescriptor == null) { - // throw new IllegalArgumentException("Cannot set non-existant property '" + - // name + "' on Rule " + rule.getName()); - // } else { - // Object realValue = propertyDescriptor.valueFrom(value); - // rule.setProperty(propertyDescriptor, realValue); - // } - // } else { - // PropertyDescriptor propertyDescriptor = - // PropertyDescriptorFactory.createPropertyDescriptor(name, description, - // type, delimiter, min, max, value); - // rule.definePropertyDescriptor(propertyDescriptor); - // } - // } private static void setValue(Rule rule, PropertyDescriptor desc, String strValue) { T realValue = desc.valueFrom(strValue); rule.setProperty(desc, realValue); } + + /** + * Parse a property node. + * + * @param rule The Rule to which the property should be added. + * @param propertyNode Must be a property element node. + */ private static void parsePropertyNodeBR(Rule rule, Node propertyNode) { Element propertyElement = (Element) propertyNode; - String typeId = propertyElement.getAttribute(PropertyDescriptorField.TYPE.attributeName); - String strValue = propertyElement.getAttribute(PropertyDescriptorField.DEFAULT_VALUE.attributeName); + String typeId = propertyElement.getAttribute(PropertyDescriptorField.TYPE.attributeName()); + String strValue = propertyElement.getAttribute(PropertyDescriptorField.DEFAULT_VALUE.attributeName()); if (StringUtil.isEmpty(strValue)) { strValue = valueFrom(propertyElement); } // Setting of existing property, or defining a new property? if (StringUtil.isEmpty(typeId)) { - String name = propertyElement.getAttribute(PropertyDescriptorField.NAME.attributeName); + String name = propertyElement.getAttribute(PropertyDescriptorField.NAME.attributeName()); PropertyDescriptor propertyDescriptor = rule.getPropertyDescriptor(name); if (propertyDescriptor == null) { @@ -871,7 +842,7 @@ public class RuleSetFactory { // populate a map of values for an individual descriptor for (Map.Entry entry : valueKeys.entrySet()) { - String valueStr = propertyElement.getAttribute(entry.getKey().attributeName); + String valueStr = propertyElement.getAttribute(entry.getKey().attributeName()); if (entry.getValue() && StringUtil.isEmpty(valueStr)) { // TODO debug pt System.out.println("Missing required value for: " + entry.getKey()); @@ -911,16 +882,15 @@ public class RuleSetFactory { return buffer.toString(); } + /** * Determine if the specified rule element will represent a Rule with the * given name. * - * @param ruleElement - * The rule element. - * @param ruleName - * The Rule name. - * @return true if the Rule would have the given name, - * false otherwise. + * @param ruleElement The rule element. + * @param ruleName The Rule name. + * + * @return {@code true} if the Rule would have the given name, {@code false} otherwise. */ private boolean isRuleName(Element ruleElement, String ruleName) { if (ruleElement.hasAttribute("name")) { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetWriter.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetWriter.java index 2b4f421db0..428138e5fd 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetWriter.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetWriter.java @@ -333,45 +333,18 @@ public class RuleSetWriter { return propertyElement; } - // private Element createPropertyDefinitionElement(PropertyDescriptor - // propertyDescriptor) { - // Element propertyElement = createPropertyValueElement(propertyDescriptor, - // propertyDescriptor.defaultValue()); - // - // propertyElement.setAttribute("description", - // propertyDescriptor.description()); - // String type = - // PropertyDescriptorFactory.getPropertyDescriptorType(propertyDescriptor); - // propertyElement.setAttribute("type", type); - // - // if (propertyDescriptor.isMultiValue()) { - // propertyElement.setAttribute("delimiter", - // String.valueOf(propertyDescriptor.multiValueDelimiter())); - // } - // - // if (propertyDescriptor instanceof AbstractNumericProperty) { - // propertyElement.setAttribute("min", - // String.valueOf(((AbstractNumericProperty) - // propertyDescriptor).lowerLimit())); - // propertyElement.setAttribute("max", - // String.valueOf(((AbstractNumericProperty) - // propertyDescriptor).upperLimit())); - // } - // - // return propertyElement; - // } private Element createPropertyDefinitionElementBR(PropertyDescriptor propertyDescriptor) { final Element propertyElement = createPropertyValueElement(propertyDescriptor, propertyDescriptor.defaultValue()); - propertyElement.setAttribute(PropertyDescriptorField.TYPE.attributeName, + propertyElement.setAttribute(PropertyDescriptorField.TYPE.attributeName(), PropertyDescriptorUtil.typeIdFor(propertyDescriptor.type(), propertyDescriptor.isMultiValue())); Map propertyValuesById = propertyDescriptor.attributeValuesById(); for (Map.Entry entry : propertyValuesById.entrySet()) { - propertyElement.setAttribute(entry.getKey().attributeName, entry.getValue()); + propertyElement.setAttribute(entry.getKey().attributeName(), entry.getValue()); } return propertyElement; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/AbstractMultiNumericProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/AbstractMultiNumericProperty.java index 1a5a6189e3..104b9dc65f 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/AbstractMultiNumericProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/AbstractMultiNumericProperty.java @@ -60,8 +60,9 @@ import net.sourceforge.pmd.PropertyDescriptorField; private void checkNumber(T number) { - if (valueErrorFor(number) != null) { - throw new IllegalArgumentException(valueErrorFor(number)); + String error = valueErrorFor(number); + if (error != null) { + throw new IllegalArgumentException(error); } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/PropertyDescriptorUtil.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/PropertyDescriptorUtil.java index 7cad68b59f..5ac30e810e 100755 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/PropertyDescriptorUtil.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/PropertyDescriptorUtil.java @@ -5,11 +5,9 @@ package net.sourceforge.pmd.lang.rule.properties; import java.util.Collections; -import java.util.Comparator; import java.util.HashMap; import java.util.Map; -import net.sourceforge.pmd.PropertyDescriptor; import net.sourceforge.pmd.PropertyDescriptorFactory; /** @@ -17,13 +15,6 @@ import net.sourceforge.pmd.PropertyDescriptorFactory; */ public class PropertyDescriptorUtil { - public static final Comparator> COMPARATOR_BY_ORDER = new Comparator>() { - @Override - public int compare(PropertyDescriptor pd1, PropertyDescriptor pd2) { - return pd2.uiOrder() > pd1.uiOrder() ? -1 : 1; - } - }; - private static final Map> DESCRIPTOR_FACTORIES_BY_TYPE;