Corrections for #479
This commit is contained in:
@ -106,7 +106,7 @@ public interface PropertyDescriptor<T> extends Comparable<PropertyDescriptor<?>>
|
||||
|
||||
|
||||
/**
|
||||
* Retunrs the value represented by this string.
|
||||
* Returns the value represented by this string.
|
||||
*
|
||||
* @param propertyString The string to parse
|
||||
*
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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 <code>true</code> 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 <T> 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 <value> 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 <T> void setValue(Rule rule, PropertyDescriptor<T> 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<PropertyDescriptorField, Boolean> 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 <code>true</code> if the Rule would have the given name,
|
||||
* <code>false</code> 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")) {
|
||||
|
@ -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<PropertyDescriptorField, String> propertyValuesById = propertyDescriptor.attributeValuesById();
|
||||
for (Map.Entry<PropertyDescriptorField, String> entry : propertyValuesById.entrySet()) {
|
||||
propertyElement.setAttribute(entry.getKey().attributeName, entry.getValue());
|
||||
propertyElement.setAttribute(entry.getKey().attributeName(), entry.getValue());
|
||||
}
|
||||
|
||||
return propertyElement;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<PropertyDescriptor<?>> COMPARATOR_BY_ORDER = new Comparator<PropertyDescriptor<?>>() {
|
||||
@Override
|
||||
public int compare(PropertyDescriptor<?> pd1, PropertyDescriptor<?> pd2) {
|
||||
return pd2.uiOrder() > pd1.uiOrder() ? -1 : 1;
|
||||
}
|
||||
};
|
||||
|
||||
private static final Map<String, PropertyDescriptorFactory<?>> DESCRIPTOR_FACTORIES_BY_TYPE;
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user