From 5e57af605c6a974370efa64fc9bf6b74c90f9bf5 Mon Sep 17 00:00:00 2001 From: oowekyala Date: Thu, 13 Jul 2017 16:46:05 +0200 Subject: [PATCH] Removed need for wrappers --- ...=> AbstractPropertyDescriptorFactory.java} | 64 +++++++++++++------ .../pmd/MultiValuePropertyDescriptor.java | 7 ++ .../sourceforge/pmd/PropertyDescriptor.java | 12 ++++ .../pmd/PropertyDescriptorFactory.java | 2 +- .../net/sourceforge/pmd/RuleSetFactory.java | 6 +- .../net/sourceforge/pmd/RuleSetWriter.java | 8 +-- .../AbstractMultiNumericProperty.java | 4 +- .../AbstractMultiPackagedProperty.java | 10 +-- .../AbstractMultiValueProperty.java | 13 ++-- .../properties/AbstractNumericProperty.java | 9 +-- .../properties/AbstractPackagedProperty.java | 9 +-- .../rule/properties/AbstractProperty.java | 10 ++- .../AbstractSingleValueProperty.java | 5 +- .../rule/properties/BooleanMultiProperty.java | 15 +++-- .../lang/rule/properties/BooleanProperty.java | 15 +++-- .../properties/CharacterMultiProperty.java | 37 ++++++----- .../rule/properties/CharacterProperty.java | 15 +++-- .../rule/properties/DoubleMultiProperty.java | 14 ++-- .../lang/rule/properties/DoubleProperty.java | 18 ++++-- .../properties/EnumeratedMultiProperty.java | 25 +++++--- .../rule/properties/EnumeratedProperty.java | 54 ++++++++++++---- .../lang/rule/properties/FileProperty.java | 22 ++++++- .../rule/properties/FloatMultiProperty.java | 17 +++-- .../lang/rule/properties/FloatProperty.java | 19 ++++-- .../rule/properties/IntegerMultiProperty.java | 17 +++-- .../lang/rule/properties/IntegerProperty.java | 13 +++- .../rule/properties/LongMultiProperty.java | 16 +++-- .../lang/rule/properties/LongProperty.java | 18 ++++-- .../rule/properties/MethodMultiProperty.java | 30 +++++---- .../lang/rule/properties/MethodProperty.java | 33 ++++++++-- .../MultiValuePropertyDescriptorFactory.java | 6 +- .../properties/PropertyDescriptorWrapper.java | 6 ++ .../SingleValuePropertyDescriptorFactory.java | 6 +- .../rule/properties/StringMultiProperty.java | 18 ++++-- .../lang/rule/properties/StringProperty.java | 16 ++++- .../rule/properties/TypeMultiProperty.java | 29 +++------ .../lang/rule/properties/TypeProperty.java | 19 ++++-- .../pmd/lang/rule/properties/ValueParser.java | 9 +++ .../NonRuleWithAllPropertyTypes.java | 3 +- .../pmd/properties/TypePropertyTest.java | 28 +++++--- 40 files changed, 467 insertions(+), 210 deletions(-) rename pmd-core/src/main/java/net/sourceforge/pmd/{lang/rule/properties/BasicPropertyDescriptorFactory.java => AbstractPropertyDescriptorFactory.java} (75%) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/BasicPropertyDescriptorFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/AbstractPropertyDescriptorFactory.java similarity index 75% rename from pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/BasicPropertyDescriptorFactory.java rename to pmd-core/src/main/java/net/sourceforge/pmd/AbstractPropertyDescriptorFactory.java index cbfd86114c..9aae00a602 100755 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/BasicPropertyDescriptorFactory.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/AbstractPropertyDescriptorFactory.java @@ -2,7 +2,7 @@ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ -package net.sourceforge.pmd.lang.rule.properties; +package net.sourceforge.pmd; import static net.sourceforge.pmd.PropertyDescriptorField.DEFAULT_VALUE; import static net.sourceforge.pmd.PropertyDescriptorField.DELIMITER; @@ -18,19 +18,18 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import net.sourceforge.pmd.PropertyDescriptorFactory; -import net.sourceforge.pmd.PropertyDescriptorField; +import net.sourceforge.pmd.lang.rule.properties.ValueParser; import net.sourceforge.pmd.util.CollectionUtil; import net.sourceforge.pmd.util.StringUtil; /** * Basic implementation of a property descriptor factory. * - * @param + * @param The type of values property descriptor returned by this factory. This can be a list. * * @author Brian Remedios */ -public abstract class BasicPropertyDescriptorFactory implements PropertyDescriptorFactory { +public abstract class AbstractPropertyDescriptorFactory implements PropertyDescriptorFactory { protected static final Map CORE_FIELD_TYPES_BY_KEY = CollectionUtil.mapFrom(new PropertyDescriptorField[] {NAME, DESCRIPTION, DEFAULT_VALUE, DELIMITER}, @@ -41,13 +40,13 @@ public abstract class BasicPropertyDescriptorFactory implements PropertyDescr private final Map fieldTypesByKey; - public BasicPropertyDescriptorFactory(Class theValueType) { + public AbstractPropertyDescriptorFactory(Class theValueType) { valueType = theValueType; fieldTypesByKey = Collections.unmodifiableMap(CORE_FIELD_TYPES_BY_KEY); } - public BasicPropertyDescriptorFactory(Class theValueType, Map additionalFieldTypesByKey) { + public AbstractPropertyDescriptorFactory(Class theValueType, Map additionalFieldTypesByKey) { valueType = theValueType; Map temp @@ -114,7 +113,7 @@ public abstract class BasicPropertyDescriptorFactory implements PropertyDescr protected static String[] labelsIn(Map valuesById) { return StringUtil.substringsOf(valuesById.get(PropertyDescriptorField.LABELS), - AbstractMultiValueProperty.DEFAULT_DELIMITER); + MultiValuePropertyDescriptor.DEFAULT_DELIMITER); } @@ -140,7 +139,7 @@ public abstract class BasicPropertyDescriptorFactory implements PropertyDescr protected static char delimiterIn(Map valuesById) { - return delimiterIn(valuesById, AbstractMultiValueProperty.DEFAULT_DELIMITER); + return delimiterIn(valuesById, MultiValuePropertyDescriptor.DEFAULT_DELIMITER); } @@ -185,8 +184,8 @@ public abstract class BasicPropertyDescriptorFactory implements PropertyDescr } - public static Map expectedFieldTypesWith(PropertyDescriptorField[] otherKeys, Boolean[] - otherValues) { + public static Map expectedFieldTypesWith(PropertyDescriptorField[] otherKeys, + Boolean[] otherValues) { Map largerMap = new HashMap<>( otherKeys.length + CORE_FIELD_TYPES_BY_KEY.size()); largerMap.putAll(CORE_FIELD_TYPES_BY_KEY); @@ -196,13 +195,38 @@ public abstract class BasicPropertyDescriptorFactory implements PropertyDescr return largerMap; } - // protected static Map - // factoriesByTypeIdFrom(PropertyDescriptorFactory[] factories) { - // Map factoryMap = new HashMap(factories.length); - // for (PropertyDescriptorFactory factory : factories) - // factoryMap.put(factory.typeId(), factory); - // return factoryMap; - // } - // + + @Override + public final PropertyDescriptor createWith(Map valuesById) { + return createWith(valuesById, false); + } + + + /** + * Creates a new property descriptor which was defined externally. + * + * @param valuesById The map of values + * + * @return A new and initialized {@link PropertyDescriptor} + * + * @see PropertyDescriptor#isDefinedExternally() + */ + /* default */ + final PropertyDescriptor createExternalWith(Map valuesById) { + return createWith(valuesById, true); + } + + + /** + * Creates a new property descriptor specifying whether the descriptor is externally defined or not. This is + * meant to be implemented by subclasses. + * + * @param valuesById The map of values + * @param isExternallyDefined Whether the descriptor is externally defined + * + * @return A new and initialized {@link PropertyDescriptor} + */ + protected abstract PropertyDescriptor createWith(Map valuesById, boolean isExternallyDefined); + + } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/MultiValuePropertyDescriptor.java b/pmd-core/src/main/java/net/sourceforge/pmd/MultiValuePropertyDescriptor.java index c010060f9d..092bd6edf5 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/MultiValuePropertyDescriptor.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/MultiValuePropertyDescriptor.java @@ -17,6 +17,13 @@ import java.util.List; */ public interface MultiValuePropertyDescriptor extends PropertyDescriptor> { + /** Default delimiter for multi-valued properties other than numeric ones. */ + char DEFAULT_DELIMITER = '|'; + + /** Default delimiter for numeric multi-valued properties. */ + char DEFAULT_NUMERIC_DELIMITER = ','; + + /** * Return the character being used to delimit multiple property values within a single string. You must ensure that * this character does not appear within any rule property values to avoid deserialization errors. 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 57bd7d7b2e..1fbf7a8694 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/PropertyDescriptor.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/PropertyDescriptor.java @@ -156,4 +156,16 @@ public interface PropertyDescriptor extends Comparable> * @return map */ Map attributeValuesById(); + + + /** + * True if this descriptor was defined in the ruleset xml. This precision is + * necessary for the {@link RuleSetWriter} to write out the property correctly: + * if it was defined externally, then its definition must be written out, otherwise + * only its value. + * + * @return True if the descriptor was defined in xml + */ + boolean isDefinedExternally(); + } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/PropertyDescriptorFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/PropertyDescriptorFactory.java index 746f26df48..0990938b6e 100755 --- a/pmd-core/src/main/java/net/sourceforge/pmd/PropertyDescriptorFactory.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/PropertyDescriptorFactory.java @@ -9,7 +9,7 @@ import java.util.Map; /** * A factory to create {@link PropertyDescriptor}s based on a map of values. * - * @param the type of values property descriptor returned by this factory. This can be a list. + * @param The type of values property descriptor returned by this factory. This can be a list. * * @author Brian Remedios */ 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 d3ccdc6233..cc1c3751d9 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java @@ -38,7 +38,6 @@ import net.sourceforge.pmd.lang.rule.MockRule; import net.sourceforge.pmd.lang.rule.RuleReference; import net.sourceforge.pmd.lang.rule.XPathRule; import net.sourceforge.pmd.lang.rule.properties.PropertyDescriptorUtil; -import net.sourceforge.pmd.lang.rule.properties.PropertyDescriptorWrapper; import net.sourceforge.pmd.util.ResourceLoader; import net.sourceforge.pmd.util.StringUtil; @@ -850,10 +849,9 @@ public class RuleSetFactory { values.put(entry.getKey(), valueStr); } - PropertyDescriptor desc = pdFactory.createWith(values); - PropertyDescriptorWrapper wrapper = PropertyDescriptorWrapper.getWrapper(desc); + PropertyDescriptor desc = ((AbstractPropertyDescriptorFactory) pdFactory).createExternalWith(values); - rule.definePropertyDescriptor(wrapper); + rule.definePropertyDescriptor(desc); setValue(rule, desc, strValue); } 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 428138e5fd..09104f3da0 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetWriter.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetWriter.java @@ -33,7 +33,6 @@ import net.sourceforge.pmd.lang.rule.ImmutableLanguage; import net.sourceforge.pmd.lang.rule.RuleReference; import net.sourceforge.pmd.lang.rule.XPathRule; import net.sourceforge.pmd.lang.rule.properties.PropertyDescriptorUtil; -import net.sourceforge.pmd.lang.rule.properties.PropertyDescriptorWrapper; /** * This class represents a way to serialize a RuleSet to an XML configuration @@ -268,14 +267,13 @@ public class RuleSetWriter { for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { // For each provided PropertyDescriptor - if (propertyDescriptor instanceof PropertyDescriptorWrapper) { - // Any wrapper property needs to go out as a definition. + if (propertyDescriptor.isDefinedExternally()) { + // Any externally defined property needs to go out as a definition. if (propertiesElement == null) { propertiesElement = createPropertiesElement(); } - Element propertyElement = createPropertyDefinitionElementBR( - ((PropertyDescriptorWrapper) propertyDescriptor).getPropertyDescriptor()); + Element propertyElement = createPropertyDefinitionElementBR(propertyDescriptor); propertiesElement.appendChild(propertyElement); } else { if (propertiesByPropertyDescriptor != null) { 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 104b9dc65f..6559bd517d 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 @@ -42,8 +42,8 @@ import net.sourceforge.pmd.PropertyDescriptorField; * the bounds */ AbstractMultiNumericProperty(String theName, String theDescription, T lower, T upper, List theDefault, - float theUIOrder) { - super(theName, theDescription, theDefault, theUIOrder); + float theUIOrder, boolean isDefinedExternally) { + super(theName, theDescription, theDefault, theUIOrder, isDefinedExternally); lowerLimit = lower; upperLimit = upper; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/AbstractMultiPackagedProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/AbstractMultiPackagedProperty.java index cf433e480d..5b73987465 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/AbstractMultiPackagedProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/AbstractMultiPackagedProperty.java @@ -12,6 +12,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import net.sourceforge.pmd.AbstractPropertyDescriptorFactory; import net.sourceforge.pmd.PropertyDescriptorField; /** @@ -28,8 +29,8 @@ import net.sourceforge.pmd.PropertyDescriptorField; protected static final char DELIMITER = '|'; /** Required keys in the map. */ protected static final Map PACKAGED_FIELD_TYPES_BY_KEY - = BasicPropertyDescriptorFactory.expectedFieldTypesWith(new PropertyDescriptorField[] {LEGAL_PACKAGES}, - new Boolean[] {false}); + = AbstractPropertyDescriptorFactory.expectedFieldTypesWith(new PropertyDescriptorField[] {LEGAL_PACKAGES}, + new Boolean[] {false}); private static final char PACKAGE_NAME_DELIMITER = ' '; private String[] legalPackageNames; @@ -46,8 +47,9 @@ import net.sourceforge.pmd.PropertyDescriptorField; * @throws IllegalArgumentException */ protected AbstractMultiPackagedProperty(String theName, String theDescription, List theDefault, - String[] theLegalPackageNames, float theUIOrder) { - super(theName, theDescription, theDefault, theUIOrder); + String[] theLegalPackageNames, float theUIOrder, + boolean isDefinedExternally) { + super(theName, theDescription, theDefault, theUIOrder, isDefinedExternally); checkValidPackages(theDefault, theLegalPackageNames); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/AbstractMultiValueProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/AbstractMultiValueProperty.java index e37b9e0112..7b9ce94008 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/AbstractMultiValueProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/AbstractMultiValueProperty.java @@ -26,11 +26,7 @@ import net.sourceforge.pmd.util.StringUtil; /* default */ abstract class AbstractMultiValueProperty extends AbstractProperty> implements MultiValuePropertyDescriptor { - /** Default delimiter for multi-valued properties other than numeric ones. */ - public static final char DEFAULT_DELIMITER = '|'; - /** Default delimiter for numeric multi-valued properties. */ - public static final char DEFAULT_NUMERIC_DELIMITER = ','; /** The default value. */ private final List defaultValue; @@ -47,8 +43,9 @@ import net.sourceforge.pmd.util.StringUtil; * * @throws IllegalArgumentException If name or description are empty, or UI order is negative. */ - AbstractMultiValueProperty(String theName, String theDescription, List theDefault, float theUIOrder) { - this(theName, theDescription, theDefault, theUIOrder, DEFAULT_DELIMITER); + AbstractMultiValueProperty(String theName, String theDescription, List theDefault, float theUIOrder, + boolean isDefinedExternally) { + this(theName, theDescription, theDefault, theUIOrder, DEFAULT_DELIMITER, isDefinedExternally); } @@ -64,9 +61,9 @@ import net.sourceforge.pmd.util.StringUtil; * @throws IllegalArgumentException If name or description are empty, or UI order is negative. */ AbstractMultiValueProperty(String theName, String theDescription, List theDefault, - float theUIOrder, char delimiter) { + float theUIOrder, char delimiter, boolean isDefinedExternally) { - super(theName, theDescription, theUIOrder); + super(theName, theDescription, theUIOrder, isDefinedExternally); defaultValue = Collections.unmodifiableList(theDefault); multiValueDelimiter = delimiter; } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/AbstractNumericProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/AbstractNumericProperty.java index f338437454..1ef679fb64 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/AbstractNumericProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/AbstractNumericProperty.java @@ -9,6 +9,7 @@ import static net.sourceforge.pmd.PropertyDescriptorField.MIN; import java.util.Map; +import net.sourceforge.pmd.AbstractPropertyDescriptorFactory; import net.sourceforge.pmd.NumericPropertyDescriptor; import net.sourceforge.pmd.PropertyDescriptorField; @@ -25,8 +26,8 @@ import net.sourceforge.pmd.PropertyDescriptorField; implements NumericPropertyDescriptor { public static final Map NUMBER_FIELD_TYPES_BY_KEY - = BasicPropertyDescriptorFactory.expectedFieldTypesWith(new PropertyDescriptorField[] {MIN, MAX}, - new Boolean[] {true, true}); + = AbstractPropertyDescriptorFactory.expectedFieldTypesWith(new PropertyDescriptorField[] {MIN, MAX}, + new Boolean[] {true, true}); private T lowerLimit; private T upperLimit; @@ -46,8 +47,8 @@ import net.sourceforge.pmd.PropertyDescriptorField; * bounds */ protected AbstractNumericProperty(String theName, String theDescription, T lower, T upper, T theDefault, - float theUIOrder) { - super(theName, theDescription, theDefault, theUIOrder); + float theUIOrder, boolean isDefinedExternally) { + super(theName, theDescription, theDefault, theUIOrder, isDefinedExternally); lowerLimit = lower; upperLimit = upper; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/AbstractPackagedProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/AbstractPackagedProperty.java index c2c1d9e3b2..0b657c7fe4 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/AbstractPackagedProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/AbstractPackagedProperty.java @@ -10,6 +10,7 @@ import java.util.Arrays; import java.util.Map; import java.util.regex.Pattern; +import net.sourceforge.pmd.AbstractPropertyDescriptorFactory; import net.sourceforge.pmd.PropertyDescriptorField; import net.sourceforge.pmd.util.StringUtil; @@ -26,8 +27,8 @@ import net.sourceforge.pmd.util.StringUtil; /** Required keys in the map. */ protected static final Map PACKAGED_FIELD_TYPES_BY_KEY - = BasicPropertyDescriptorFactory.expectedFieldTypesWith(new PropertyDescriptorField[] {LEGAL_PACKAGES}, - new Boolean[] {false}); + = AbstractPropertyDescriptorFactory.expectedFieldTypesWith(new PropertyDescriptorField[] {LEGAL_PACKAGES}, + new Boolean[] {false}); private static final char PACKAGE_NAME_DELIMITER = ' '; private static Pattern packageNamePattern = Pattern.compile("(\\w+)(\\.\\w+)*"); @@ -46,8 +47,8 @@ import net.sourceforge.pmd.util.StringUtil; * @throws IllegalArgumentException */ protected AbstractPackagedProperty(String theName, String theDescription, T theDefault, - String[] theLegalPackageNames, float theUIOrder) { - super(theName, theDescription, theDefault, theUIOrder); + String[] theLegalPackageNames, float theUIOrder, boolean isDefinedExternally) { + super(theName, theDescription, theDefault, theUIOrder, isDefinedExternally); checkValidPackages(theDefault, theLegalPackageNames); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/AbstractProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/AbstractProperty.java index d66f84010b..24ef0fb376 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/AbstractProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/AbstractProperty.java @@ -28,6 +28,7 @@ import net.sourceforge.pmd.util.StringUtil; private final String name; private final String description; private final float uiOrder; + private final boolean isDefinedExternally; /** @@ -39,8 +40,7 @@ import net.sourceforge.pmd.util.StringUtil; * * @throws IllegalArgumentException If name or description are empty, or UI order is negative. */ - protected AbstractProperty(String theName, String theDescription, - float theUIOrder) { + protected AbstractProperty(String theName, String theDescription, float theUIOrder, boolean isDefinedExternally) { if (theUIOrder < 0) { throw new IllegalArgumentException("Property attribute 'UI order' cannot be null or blank"); } @@ -48,6 +48,7 @@ import net.sourceforge.pmd.util.StringUtil; name = checkNotEmpty(theName, NAME); description = checkNotEmpty(theDescription, DESCRIPTION); uiOrder = theUIOrder; + this.isDefinedExternally = isDefinedExternally; } @@ -156,4 +157,9 @@ import net.sourceforge.pmd.util.StringUtil; */ /* default */ abstract PropertyDescriptorWrapper getWrapper(); + + @Override + public boolean isDefinedExternally() { + return isDefinedExternally; + } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/AbstractSingleValueProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/AbstractSingleValueProperty.java index d1f37748be..44e83b085c 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/AbstractSingleValueProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/AbstractSingleValueProperty.java @@ -31,8 +31,9 @@ import net.sourceforge.pmd.SingleValuePropertyDescriptor; * * @throws IllegalArgumentException If name or description are empty, or UI order is negative. */ - protected AbstractSingleValueProperty(String theName, String theDescription, T theDefault, float theUIOrder) { - super(theName, theDescription, theUIOrder); + protected AbstractSingleValueProperty(String theName, String theDescription, T theDefault, + float theUIOrder, boolean isDefinedExternally) { + super(theName, theDescription, theUIOrder, isDefinedExternally); defaultValue = theDefault; } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/BooleanMultiProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/BooleanMultiProperty.java index 3fc5e35d07..997855fe29 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/BooleanMultiProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/BooleanMultiProperty.java @@ -24,12 +24,13 @@ public final class BooleanMultiProperty extends AbstractMultiValueProperty> FACTORY // @formatter:off = new MultiValuePropertyDescriptorFactory(Boolean.class) { @Override - public BooleanMultiProperty createWith(Map valuesById) { + public BooleanMultiProperty createWith(Map valuesById, boolean isDefinedExternally) { char delimiter = delimiterIn(valuesById); return new BooleanMultiProperty(nameIn(valuesById), descriptionIn(valuesById), parsePrimitives(defaultValueIn(valuesById), delimiter, BOOLEAN_PARSER), - 0f); + 0f, + isDefinedExternally); } }; // @formatter:on @@ -43,7 +44,7 @@ public final class BooleanMultiProperty extends AbstractMultiValueProperty defaultValues, float theUIOrder) { - super(theName, theDescription, defaultValues, theUIOrder); + this(theName, theDescription, defaultValues, theUIOrder, false); + } + + + private BooleanMultiProperty(String theName, String theDescription, List defaultValues, + float theUIOrder, boolean isDefinedExternally) { + super(theName, theDescription, defaultValues, theUIOrder, isDefinedExternally); } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/BooleanProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/BooleanProperty.java index e7a47e1348..ffbb43a3cd 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/BooleanProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/BooleanProperty.java @@ -23,11 +23,12 @@ public final class BooleanProperty extends AbstractSingleValueProperty public static final PropertyDescriptorFactory FACTORY // @formatter:off = new SingleValuePropertyDescriptorFactory(Boolean.class) { @Override - public BooleanProperty createWith(Map valuesById) { + public BooleanProperty createWith(Map valuesById, boolean isDefinedExternally) { return new BooleanProperty(nameIn(valuesById), descriptionIn(valuesById), BOOLEAN_PARSER.valueOf(defaultValueIn(valuesById)), - 0f); + 0f, + isDefinedExternally); } }; // @formatter:on @@ -41,10 +42,10 @@ public final class BooleanProperty extends AbstractSingleValueProperty * @param defaultBoolStr String representing the default value. * @param theUIOrder UI order * - * @deprecated ? + * @deprecated will be removed in 7.0.0 */ public BooleanProperty(String theName, String theDescription, String defaultBoolStr, float theUIOrder) { - this(theName, theDescription, Boolean.valueOf(defaultBoolStr), theUIOrder); + this(theName, theDescription, Boolean.valueOf(defaultBoolStr), theUIOrder, false); } @@ -57,10 +58,14 @@ public final class BooleanProperty extends AbstractSingleValueProperty * @param theUIOrder UI order */ public BooleanProperty(String theName, String theDescription, boolean defaultValue, float theUIOrder) { - super(theName, theDescription, defaultValue, theUIOrder); + this(theName, theDescription, defaultValue, theUIOrder, false); } + private BooleanProperty(String theName, String theDescription, boolean defaultValue, float theUIOrder, boolean isDefinedExternally) { + super(theName, theDescription, defaultValue, theUIOrder, isDefinedExternally); + } + @Override public Class type() { return Boolean.class; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/CharacterMultiProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/CharacterMultiProperty.java index 811f3352fd..5b2ef644db 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/CharacterMultiProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/CharacterMultiProperty.java @@ -25,13 +25,14 @@ public final class CharacterMultiProperty extends AbstractMultiValueProperty> FACTORY // @formatter:off = new MultiValuePropertyDescriptorFactory(Character.class) { @Override - public CharacterMultiProperty createWith(Map valuesById) { + public CharacterMultiProperty createWith(Map valuesById, boolean isDefinedExternally) { char delimiter = delimiterIn(valuesById); return new CharacterMultiProperty(nameIn(valuesById), descriptionIn(valuesById), parsePrimitives(defaultValueIn(valuesById), delimiter, ValueParser.CHARACTER_PARSER), 0.0f, - delimiter); + delimiter, + isDefinedExternally); } }; // @formatter:on @@ -47,9 +48,22 @@ public final class CharacterMultiProperty extends AbstractMultiValueProperty defaultValues, float theUIOrder, + char delimiter, boolean isDefinedExternally) { + super(theName, theDescription, defaultValues, theUIOrder, delimiter, isDefinedExternally); + + if (defaultValues != null) { + for (Character c : defaultValues) { + if (c == delimiter) { + throw new IllegalArgumentException("Cannot include the delimiter in the set of defaults"); + } + } + } } @@ -64,17 +78,8 @@ public final class CharacterMultiProperty extends AbstractMultiValueProperty defaultValues, float theUIOrder, - char delimiter) { - super(theName, theDescription, defaultValues, theUIOrder, delimiter); - - if (defaultValues != null) { - for (Character c : defaultValues) { - if (c == delimiter) { - throw new IllegalArgumentException("Cannot include the delimiter in the set of defaults"); - } - } - } + public CharacterMultiProperty(String theName, String theDescription, List defaultValues, float theUIOrder, char delimiter) { + this(theName, theDescription, defaultValues, theUIOrder, delimiter, false); } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/CharacterProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/CharacterProperty.java index 43af6603a8..6c2426acab 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/CharacterProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/CharacterProperty.java @@ -22,12 +22,13 @@ public final class CharacterProperty extends AbstractSingleValueProperty FACTORY // @formatter:off = new SingleValuePropertyDescriptorFactory(Character.class) { @Override - public CharacterProperty createWith(Map valuesById) { + public CharacterProperty createWith(Map valuesById, boolean isDefinedExternally) { return new CharacterProperty(nameIn(valuesById), descriptionIn(valuesById), defaultValueIn(valuesById) == null ? null : defaultValueIn(valuesById).charAt(0), - 0f); + 0f, + isDefinedExternally); } }; // @formatter:on @@ -41,9 +42,10 @@ public final class CharacterProperty extends AbstractSingleValueProperty> FACTORY // @formatter:off = new MultiValuePropertyDescriptorFactory(Double.class, NUMBER_FIELD_TYPES_BY_KEY) { @Override - public DoubleMultiProperty createWith(Map valuesById) { + public DoubleMultiProperty createWith(Map valuesById, boolean isDefinedExternally) { String[] minMax = minMaxFrom(valuesById); char delimiter = delimiterIn(valuesById, DEFAULT_NUMERIC_DELIMITER); List defaultValues = parsePrimitives(numericDefaultValueIn(valuesById), delimiter, DOUBLE_PARSER); @@ -35,7 +35,8 @@ public final class DoubleMultiProperty extends AbstractMultiNumericProperty defaultValues, float theUIOrder) { - super(theName, theDescription, min, max, defaultValues, theUIOrder); + this(theName, theDescription, min, max, defaultValues, theUIOrder, false); + } + + private DoubleMultiProperty(String theName, String theDescription, Double min, Double max, + List defaultValues, float theUIOrder, boolean isDefinedExternally) { + super(theName, theDescription, min, max, defaultValues, theUIOrder, isDefinedExternally); } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/DoubleProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/DoubleProperty.java index 2b3f1da8ae..a2650ad8c8 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/DoubleProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/DoubleProperty.java @@ -23,14 +23,16 @@ public final class DoubleProperty extends AbstractNumericProperty { public static final PropertyDescriptorFactory FACTORY // @formatter:off = new SingleValuePropertyDescriptorFactory(Double.class, NUMBER_FIELD_TYPES_BY_KEY) { @Override - public DoubleProperty createWith(Map valuesById) { + public DoubleProperty createWith(Map valuesById, + boolean isDefinedExternally) { final String[] minMax = minMaxFrom(valuesById); return new DoubleProperty(nameIn(valuesById), descriptionIn(valuesById), DOUBLE_PARSER.valueOf(minMax[0]), DOUBLE_PARSER.valueOf(minMax[1]), DOUBLE_PARSER.valueOf(numericDefaultValueIn(valuesById)), - 0f); + 0f, + isDefinedExternally); } }; // @formatter:on @@ -47,11 +49,11 @@ public final class DoubleProperty extends AbstractNumericProperty { * @param theUIOrder UI order * * @throws IllegalArgumentException if min > max or one of the defaults is not between the bounds - * @deprecated ? + * @deprecated will be removed in 7.0.0 */ public DoubleProperty(String theName, String theDescription, String minStr, String maxStr, String defaultStr, float theUIOrder) { - this(theName, theDescription, doubleFrom(minStr), doubleFrom(maxStr), doubleFrom(defaultStr), theUIOrder); + this(theName, theDescription, doubleFrom(minStr), doubleFrom(maxStr), doubleFrom(defaultStr), theUIOrder, false); } @@ -69,7 +71,13 @@ public final class DoubleProperty extends AbstractNumericProperty { */ public DoubleProperty(String theName, String theDescription, Double min, Double max, Double theDefault, float theUIOrder) { - super(theName, theDescription, min, max, theDefault, theUIOrder); + this(theName, theDescription, min, max, theDefault, theUIOrder, false); + } + + + private DoubleProperty(String theName, String theDescription, Double min, Double max, Double theDefault, + float theUIOrder, boolean isDefinedExternally) { + super(theName, theDescription, min, max, theDefault, theUIOrder, isDefinedExternally); } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/EnumeratedMultiProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/EnumeratedMultiProperty.java index 3f1c52e09a..f53f28d76b 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/EnumeratedMultiProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/EnumeratedMultiProperty.java @@ -16,7 +16,7 @@ import net.sourceforge.pmd.util.CollectionUtil; /** * Multi-valued property which can take only a fixed set of values of any type, then selected via String labels. The - * choices method returns the set of mappings between the labels and their values. + * mappings method returns the set of mappings between the labels and their values. * * @param The type of the values * @@ -30,14 +30,15 @@ public final class EnumeratedMultiProperty extends AbstractMultiValueProperty public static final PropertyDescriptorFactory> FACTORY // @formatter:off = new MultiValuePropertyDescriptorFactory(Object.class) { // TODO:cf is Object the right type? @Override - public EnumeratedMultiProperty createWith(Map valuesById) { + public EnumeratedMultiProperty createWith(Map valuesById, boolean isDefinedExternally) { + Object[] choices = choicesIn(valuesById); return new EnumeratedMultiProperty<>(nameIn(valuesById), descriptionIn(valuesById), - labelsIn(valuesById), - choicesIn(valuesById), - indicesIn(valuesById), + CollectionUtil.mapFrom(labelsIn(valuesById), choices), + selection(indicesIn(valuesById), choices), classIn(valuesById), - 0f); + 0f, + isDefinedExternally); } }; // @formatter:on @@ -60,10 +61,9 @@ public final class EnumeratedMultiProperty extends AbstractMultiValueProperty public EnumeratedMultiProperty(String theName, String theDescription, String[] theLabels, E[] theChoices, int[] choiceIndices, Class valueType, float theUIOrder) { this(theName, theDescription, CollectionUtil.mapFrom(theLabels, theChoices), - selection(choiceIndices, theChoices), valueType, theUIOrder); + selection(choiceIndices, theChoices), valueType, theUIOrder, false); } - /** * Constructor using a map to define the label-value mappings. The default values are specified with a list. * @@ -75,7 +75,14 @@ public final class EnumeratedMultiProperty extends AbstractMultiValueProperty */ public EnumeratedMultiProperty(String theName, String theDescription, Map choices, List defaultValues, Class valueType, float theUIOrder) { - super(theName, theDescription, defaultValues, theUIOrder); + this(theName, theDescription, choices, defaultValues, valueType, theUIOrder, false); + } + + + private EnumeratedMultiProperty(String theName, String theDescription, Map choices, + List defaultValues, Class valueType, float theUIOrder, + boolean isDefinedExternally) { + super(theName, theDescription, defaultValues, theUIOrder, isDefinedExternally); checkDefaults(defaultValues, choices); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/EnumeratedProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/EnumeratedProperty.java index fd386b6e67..db6c8f1539 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/EnumeratedProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/EnumeratedProperty.java @@ -14,12 +14,12 @@ import net.sourceforge.pmd.PropertyDescriptorField; import net.sourceforge.pmd.util.CollectionUtil; /** - * Defines a datatype with a set of preset values of any type as held within a - * pair of maps. While the values are not serialized out, the labels are and - * serve as keys to obtain the values. The choices() method provides the ordered - * selections to be used in an editor widget. + * Property which can take only a fixed set of values of any type, then selected via String labels. The + * mappings method returns the set of mappings between the labels and their values. * - * @param Type of the choices + *

This property currently doesn't support serialization and cannot be defined in a ruleset file.z + * + * @param Type of the values * * @author Brian Remedios * @version Refactored June 2017 (6.0.0) @@ -32,14 +32,16 @@ public final class EnumeratedProperty extends AbstractSingleValueProperty = new SingleValuePropertyDescriptorFactory(Enumeration.class) { // TODO:cf Enumeration? Object? @Override - public EnumeratedProperty createWith(Map valuesById) { + public EnumeratedProperty createWith(Map valuesById, boolean isDefinedExternally) { + Map labelsToChoices = CollectionUtil.mapFrom(labelsIn(valuesById), // this is not implemented + choicesIn(valuesById)); // ditto return new EnumeratedProperty<>(nameIn(valuesById), descriptionIn(valuesById), - labelsIn(valuesById), // this is not implemented - choicesIn(valuesById), // ditto - indexIn(valuesById), // ditto + labelsToChoices, + choicesIn(valuesById)[indexIn(valuesById)], classIn(valuesById), - 0f); + 0f, + isDefinedExternally); } }; // @formatter:on @@ -49,16 +51,44 @@ public final class EnumeratedProperty extends AbstractSingleValueProperty private final Class valueType; + /** + * Constructor using arrays to define the label-value mappings. The correct construction of the property depends + * on the correct ordering of the arrays. + * + * @param theName Name + * @param theDescription Description + * @param theLabels Labels of the choices + * @param theChoices Values that can be chosen + * @param defaultIndex The index of the default value. + * @param theUIOrder UI order + * + * @deprecated will be removed in 7.0.0. Use a map. + */ public EnumeratedProperty(String theName, String theDescription, String[] theLabels, E[] theChoices, int defaultIndex, Class valueType, float theUIOrder) { this(theName, theDescription, CollectionUtil.mapFrom(theLabels, theChoices), - theChoices[defaultIndex], valueType, theUIOrder); + theChoices[defaultIndex], valueType, theUIOrder, false); } + /** + * Constructor using a map to define the label-value mappings. + * + * @param theName Name + * @param theDescription Description + * @param labelsToChoices Map of labels to values + * @param defaultValue Default value + * @param theUIOrder UI order + */ public EnumeratedProperty(String theName, String theDescription, Map labelsToChoices, E defaultValue, Class valueType, float theUIOrder) { - super(theName, theDescription, defaultValue, theUIOrder); + this(theName, theDescription, labelsToChoices, defaultValue, valueType, theUIOrder, false); + } + + + private EnumeratedProperty(String theName, String theDescription, Map labelsToChoices, + E defaultValue, Class valueType, float theUIOrder, boolean isDefinedExternally) { + super(theName, theDescription, defaultValue, theUIOrder, isDefinedExternally); this.valueType = valueType; choicesByLabel = Collections.unmodifiableMap(labelsToChoices); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/FileProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/FileProperty.java index bfed9815e1..a1055fdfe5 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/FileProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/FileProperty.java @@ -23,17 +23,33 @@ public final class FileProperty extends AbstractSingleValueProperty { public static final PropertyDescriptorFactory FACTORY // @formatter:off = new SingleValuePropertyDescriptorFactory(File.class) { @Override - public FileProperty createWith(Map valuesById) { - return new FileProperty(nameIn(valuesById), descriptionIn(valuesById), null, 0f); + public FileProperty createWith(Map valuesById, boolean isDefinedExternally) { + return new FileProperty(nameIn(valuesById), + descriptionIn(valuesById), + null, + 0f, + isDefinedExternally); } }; // @formatter:on + /** + * Constructor for file property. + * + * @param theName Name of the property + * @param theDescription Description + * @param theDefault Default value + * @param theUIOrder UI order + */ public FileProperty(String theName, String theDescription, File theDefault, float theUIOrder) { - super(theName, theDescription, theDefault, theUIOrder); + super(theName, theDescription, theDefault, theUIOrder, false); } + private FileProperty(String theName, String theDescription, File theDefault, float theUIOrder, boolean isDefinedExternally) { + super(theName, theDescription, theDefault, theUIOrder, isDefinedExternally); + } + @Override public Class type() { return File.class; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/FloatMultiProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/FloatMultiProperty.java index 99382bd738..6ba7af0bbc 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/FloatMultiProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/FloatMultiProperty.java @@ -26,7 +26,8 @@ public final class FloatMultiProperty extends AbstractMultiNumericProperty> FACTORY // @formatter:off = new MultiValuePropertyDescriptorFactory(Float.class, NUMBER_FIELD_TYPES_BY_KEY) { @Override - public FloatMultiProperty createWith(Map valuesById) { + public FloatMultiProperty createWith(Map valuesById, + boolean isDefinedExternally) { String[] minMax = minMaxFrom(valuesById); char delimiter = delimiterIn(valuesById, DEFAULT_NUMERIC_DELIMITER); List defaultValues = parsePrimitives(numericDefaultValueIn(valuesById), delimiter, FLOAT_PARSER); @@ -34,7 +35,9 @@ public final class FloatMultiProperty extends AbstractMultiNumericProperty defaultValues, float theUIOrder) { - super(theName, theDescription, min, max, defaultValues, theUIOrder); + this(theName, theDescription, min, max, defaultValues, theUIOrder, false); + } + + + private FloatMultiProperty(String theName, String theDescription, Float min, Float max, + List defaultValues, float theUIOrder, boolean isDefinedExternally) { + super(theName, theDescription, min, max, defaultValues, theUIOrder, isDefinedExternally); } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/FloatProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/FloatProperty.java index d7b8503d90..4240e88138 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/FloatProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/FloatProperty.java @@ -23,13 +23,15 @@ public final class FloatProperty extends AbstractNumericProperty { public static final PropertyDescriptorFactory FACTORY // @formatter:off = new SingleValuePropertyDescriptorFactory(Float.class, NUMBER_FIELD_TYPES_BY_KEY) { @Override - public FloatProperty createWith(Map valuesById) { + public FloatProperty createWith(Map valuesById, boolean isDefinedExternally) { final String[] minMax = minMaxFrom(valuesById); return new FloatProperty(nameIn(valuesById), descriptionIn(valuesById), FLOAT_PARSER.valueOf(minMax[0]), FLOAT_PARSER.valueOf(minMax[1]), - FLOAT_PARSER.valueOf(numericDefaultValueIn(valuesById)), 0f); + FLOAT_PARSER.valueOf(numericDefaultValueIn(valuesById)), + 0f, + isDefinedExternally); } }; // @formatter:on @@ -46,11 +48,12 @@ public final class FloatProperty extends AbstractNumericProperty { * @param theUIOrder UI order * * @throws IllegalArgumentException if min > max or one of the defaults is not between the bounds - * @deprecated ? + * @deprecated will be removed in 7.0.0 */ public FloatProperty(String theName, String theDescription, String minStr, String maxStr, String defaultStr, float theUIOrder) { - this(theName, theDescription, FLOAT_PARSER.valueOf(minStr), FLOAT_PARSER.valueOf(maxStr), FLOAT_PARSER.valueOf(defaultStr), theUIOrder); + this(theName, theDescription, FLOAT_PARSER.valueOf(minStr), + FLOAT_PARSER.valueOf(maxStr), FLOAT_PARSER.valueOf(defaultStr), theUIOrder, false); } @@ -68,7 +71,13 @@ public final class FloatProperty extends AbstractNumericProperty { */ public FloatProperty(String theName, String theDescription, Float min, Float max, Float theDefault, float theUIOrder) { - super(theName, theDescription, min, max, theDefault, theUIOrder); + this(theName, theDescription, min, max, theDefault, theUIOrder, false); + } + + + private FloatProperty(String theName, String theDescription, Float min, Float max, Float theDefault, + float theUIOrder, boolean isDefinedExternally) { + super(theName, theDescription, min, max, theDefault, theUIOrder, isDefinedExternally); } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/IntegerMultiProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/IntegerMultiProperty.java index 51f02f1588..a6ce64db55 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/IntegerMultiProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/IntegerMultiProperty.java @@ -26,7 +26,8 @@ public final class IntegerMultiProperty extends AbstractMultiNumericProperty> FACTORY // @formatter:off = new MultiValuePropertyDescriptorFactory(Integer.class, NUMBER_FIELD_TYPES_BY_KEY) { @Override - public IntegerMultiProperty createWith(Map valuesById) { + public IntegerMultiProperty createWith(Map valuesById, boolean + isDefinedExternally) { String[] minMax = minMaxFrom(valuesById); char delimiter = delimiterIn(valuesById, DEFAULT_NUMERIC_DELIMITER); List defaultValues = parsePrimitives(numericDefaultValueIn(valuesById), delimiter, INTEGER_PARSER); @@ -35,7 +36,8 @@ public final class IntegerMultiProperty extends AbstractMultiNumericProperty defaultValues, float theUIOrder) { - super(theName, theDescription, min, max, defaultValues, theUIOrder); + this(theName, theDescription, min, max, defaultValues, theUIOrder, false); + } + + + private IntegerMultiProperty(String theName, String theDescription, Integer min, Integer max, + List defaultValues, float theUIOrder, boolean isDefinedExternally) { + + super(theName, theDescription, min, max, defaultValues, theUIOrder, isDefinedExternally); } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/IntegerProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/IntegerProperty.java index bbe2e29bb7..694349e9d7 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/IntegerProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/IntegerProperty.java @@ -22,14 +22,15 @@ public final class IntegerProperty extends AbstractNumericProperty { public static final PropertyDescriptorFactory FACTORY // @formatter:off = new SingleValuePropertyDescriptorFactory(Integer.class, NUMBER_FIELD_TYPES_BY_KEY) { @Override - public IntegerProperty createWith(Map valuesById) { + public IntegerProperty createWith(Map valuesById, boolean isDefinedExternally) { final String[] minMax = minMaxFrom(valuesById); return new IntegerProperty(nameIn(valuesById), descriptionIn(valuesById), INTEGER_PARSER.valueOf(minMax[0]), INTEGER_PARSER.valueOf(minMax[1]), INTEGER_PARSER.valueOf(numericDefaultValueIn(valuesById)), - 0f); + 0f, + isDefinedExternally); } }; // @formatter:on @@ -48,7 +49,13 @@ public final class IntegerProperty extends AbstractNumericProperty { */ public IntegerProperty(String theName, String theDescription, Integer min, Integer max, Integer theDefault, float theUIOrder) { - super(theName, theDescription, min, max, theDefault, theUIOrder); + this(theName, theDescription, min, max, theDefault, theUIOrder, false); + } + + + private IntegerProperty(String theName, String theDescription, Integer min, Integer max, Integer theDefault, + float theUIOrder, boolean isDefinedExternally) { + super(theName, theDescription, min, max, theDefault, theUIOrder, isDefinedExternally); } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/LongMultiProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/LongMultiProperty.java index 12f7616385..8eaf0af35d 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/LongMultiProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/LongMultiProperty.java @@ -26,7 +26,7 @@ public final class LongMultiProperty extends AbstractMultiNumericProperty public static final PropertyDescriptorFactory> FACTORY // @formatter:off = new MultiValuePropertyDescriptorFactory(Long.class, NUMBER_FIELD_TYPES_BY_KEY) { @Override - public LongMultiProperty createWith(Map valuesById) { + public LongMultiProperty createWith(Map valuesById, boolean isDefinedExternally) { String[] minMax = minMaxFrom(valuesById); char delimiter = delimiterIn(valuesById, DEFAULT_NUMERIC_DELIMITER); List defaultValues = parsePrimitives(defaultValueIn(valuesById), delimiter, LONG_PARSER); @@ -34,7 +34,9 @@ public final class LongMultiProperty extends AbstractMultiNumericProperty descriptionIn(valuesById), LONG_PARSER.valueOf(minMax[0]), LONG_PARSER.valueOf(minMax[1]), - defaultValues, 0f); + defaultValues, + 0f, + isDefinedExternally); } }; // @formatter:on @@ -53,7 +55,7 @@ public final class LongMultiProperty extends AbstractMultiNumericProperty */ public LongMultiProperty(String theName, String theDescription, Long min, Long max, Long[] defaultValues, float theUIOrder) { - super(theName, theDescription, min, max, Arrays.asList(defaultValues), theUIOrder); + this(theName, theDescription, min, max, Arrays.asList(defaultValues), theUIOrder, false); } @@ -71,7 +73,13 @@ public final class LongMultiProperty extends AbstractMultiNumericProperty */ public LongMultiProperty(String theName, String theDescription, Long min, Long max, List defaultValues, float theUIOrder) { - super(theName, theDescription, min, max, defaultValues, theUIOrder); + this(theName, theDescription, min, max, defaultValues, theUIOrder, false); + } + + + private LongMultiProperty(String theName, String theDescription, Long min, Long max, + List defaultValues, float theUIOrder, boolean isDefinedExternally) { + super(theName, theDescription, min, max, defaultValues, theUIOrder, isDefinedExternally); } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/LongProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/LongProperty.java index a4adba5aa9..2683d0c86a 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/LongProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/LongProperty.java @@ -23,13 +23,15 @@ public final class LongProperty extends AbstractNumericProperty { public static final PropertyDescriptorFactory FACTORY // @formatter:off = new SingleValuePropertyDescriptorFactory(Long.class, NUMBER_FIELD_TYPES_BY_KEY) { @Override - public LongProperty createWith(Map valuesById) { + public LongProperty createWith(Map valuesById, boolean isDefinedExternally) { final String[] minMax = minMaxFrom(valuesById); return new LongProperty(nameIn(valuesById), descriptionIn(valuesById), LONG_PARSER.valueOf(minMax[0]), LONG_PARSER.valueOf(minMax[1]), - LONG_PARSER.valueOf(numericDefaultValueIn(valuesById)), 0f); + LONG_PARSER.valueOf(numericDefaultValueIn(valuesById)), + 0f, + isDefinedExternally); } }; // @formatter:on @@ -47,11 +49,12 @@ public final class LongProperty extends AbstractNumericProperty { * @param theUIOrder UI order * * @throws IllegalArgumentException if min > max or one of the defaults is not between the bounds - * @deprecated ? + * @deprecated will be removed in 7.0.0 */ public LongProperty(String theName, String theDescription, String minStr, String maxStr, String defaultStr, float theUIOrder) { - this(theName, theDescription, Long.valueOf(minStr), Long.valueOf(maxStr), Long.valueOf(defaultStr), theUIOrder); + this(theName, theDescription, Long.valueOf(minStr), Long.valueOf(maxStr), + Long.valueOf(defaultStr), theUIOrder, false); } @@ -68,7 +71,12 @@ public final class LongProperty extends AbstractNumericProperty { * @throws IllegalArgumentException if min > max or one of the defaults is not between the bounds */ public LongProperty(String theName, String theDescription, Long min, Long max, Long theDefault, float theUIOrder) { - super(theName, theDescription, min, max, theDefault, theUIOrder); + this(theName, theDescription, min, max, theDefault, theUIOrder, false); + } + + private LongProperty(String theName, String theDescription, Long min, Long max, Long theDefault, + float theUIOrder, boolean isDefinedExternally) { + super(theName, theDescription, min, max, theDefault, theUIOrder, isDefinedExternally); } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/MethodMultiProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/MethodMultiProperty.java index 747c7ccf6c..71e01afb9c 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/MethodMultiProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/MethodMultiProperty.java @@ -31,10 +31,14 @@ public final class MethodMultiProperty extends AbstractMultiPackagedProperty> FACTORY // @formatter:off = new MultiValuePropertyDescriptorFactory(Method.class, PACKAGED_FIELD_TYPES_BY_KEY) { @Override - public MethodMultiProperty createWith(Map valuesById) { + public MethodMultiProperty createWith(Map valuesById, boolean isDefinedExternally) { char delimiter = delimiterIn(valuesById); - return new MethodMultiProperty(nameIn(valuesById), descriptionIn(valuesById), defaultValueIn(valuesById), - legalPackageNamesIn(valuesById, delimiter), 0f); + return new MethodMultiProperty(nameIn(valuesById), + descriptionIn(valuesById), + methodsFrom(defaultValueIn(valuesById)), + legalPackageNamesIn(valuesById, delimiter), + 0f, + isDefinedExternally); } }; // @formatter:on @@ -58,7 +62,13 @@ public final class MethodMultiProperty extends AbstractMultiPackagedProperty theDefaults, String[] legalPackageNames, float theUIOrder) { - super(theName, theDescription, theDefaults, legalPackageNames, theUIOrder); + this(theName, theDescription, theDefaults, legalPackageNames, theUIOrder, false); + } + + + private MethodMultiProperty(String theName, String theDescription, List theDefaults, + String[] legalPackageNames, float theUIOrder, boolean isDefinedExternally) { + super(theName, theDescription, theDefaults, legalPackageNames, theUIOrder, isDefinedExternally); } @@ -75,7 +85,7 @@ public final class MethodMultiProperty extends AbstractMultiPackagedProperty otherParams, float theUIOrder) { - this(theName, theDescription, methodsFrom(methodDefaults), packageNamesIn(otherParams), theUIOrder); - } - - @Override public String asString(Method value) { return value == null ? "" : MethodProperty.asStringFor(value); @@ -113,8 +116,7 @@ public final class MethodMultiProperty extends AbstractMultiPackagedProperty { public static final PropertyDescriptorFactory FACTORY // @formatter:off = new SingleValuePropertyDescriptorFactory(Method.class, PACKAGED_FIELD_TYPES_BY_KEY) { @Override - public MethodProperty createWith(Map valuesById) { + public MethodProperty createWith(Map valuesById, boolean isDefinedExternally) { char delimiter = delimiterIn(valuesById); return new MethodProperty(nameIn(valuesById), descriptionIn(valuesById), - defaultValueIn(valuesById), + methodFrom(defaultValueIn(valuesById)), legalPackageNamesIn(valuesById, delimiter), - 0f); + 0f, + isDefinedExternally); } }; // @formatter:on private static final String ARRAY_FLAG = "[]"; @@ -48,15 +49,37 @@ public final class MethodProperty extends AbstractPackagedProperty { public MethodProperty(String theName, String theDescription, Method theDefault, String[] legalPackageNames, float theUIOrder) { - super(theName, theDescription, theDefault, legalPackageNames, theUIOrder); + this(theName, theDescription, theDefault, legalPackageNames, theUIOrder, false); } + /** + * Constructor for MethodProperty using a string as a default value. + * + * @param theName Name of the property + * @param theDescription Description + * @param defaultMethodStr Default value, that will be parsed into a Method object + * @param legalPackageNames Legal packages + * @param theUIOrder UI order + */ public MethodProperty(String theName, String theDescription, String defaultMethodStr, String[] legalPackageNames, float theUIOrder) { - super(theName, theDescription, methodFrom(defaultMethodStr), legalPackageNames, theUIOrder); + this(theName, theDescription, methodFrom(defaultMethodStr), legalPackageNames, theUIOrder, false); } + /** + * Constructor for MethodProperty. + * + * @param theName Name of the property + * @param theDescription Description + * @param theDefault Default value + * @param legalPackageNames Legal packages + * @param theUIOrder UI order + */ + private MethodProperty(String theName, String theDescription, Method theDefault, String[] legalPackageNames, + float theUIOrder, boolean isDefinedExternally) { + super(theName, theDescription, theDefault, legalPackageNames, theUIOrder, isDefinedExternally); + } @Override protected String asString(Method value) { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/MultiValuePropertyDescriptorFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/MultiValuePropertyDescriptorFactory.java index c77b67aa49..e256ae0ad7 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/MultiValuePropertyDescriptorFactory.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/MultiValuePropertyDescriptorFactory.java @@ -7,6 +7,7 @@ package net.sourceforge.pmd.lang.rule.properties; import java.util.List; import java.util.Map; +import net.sourceforge.pmd.AbstractPropertyDescriptorFactory; import net.sourceforge.pmd.MultiValuePropertyDescriptor; import net.sourceforge.pmd.PropertyDescriptorField; @@ -18,7 +19,7 @@ import net.sourceforge.pmd.PropertyDescriptorField; * @author Clément Fournier * @since 6.0.0 */ -public abstract class MultiValuePropertyDescriptorFactory extends BasicPropertyDescriptorFactory> { +public abstract class MultiValuePropertyDescriptorFactory extends AbstractPropertyDescriptorFactory> { public MultiValuePropertyDescriptorFactory(Class theValueType) { super(theValueType); @@ -32,7 +33,8 @@ public abstract class MultiValuePropertyDescriptorFactory extends BasicProper @Override - public abstract MultiValuePropertyDescriptor createWith(Map valuesById); + protected abstract MultiValuePropertyDescriptor createWith(Map valuesById, + boolean isDefinedExternally); @Override diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/PropertyDescriptorWrapper.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/PropertyDescriptorWrapper.java index 00947d4869..fe76361d8c 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/PropertyDescriptorWrapper.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/PropertyDescriptorWrapper.java @@ -110,6 +110,12 @@ public class PropertyDescriptorWrapper implements PropertyDescriptor { } + @Override + public boolean isDefinedExternally() { + return false; + } + + @Override public boolean equals(Object obj) { if (obj instanceof PropertyDescriptorWrapper) { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/SingleValuePropertyDescriptorFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/SingleValuePropertyDescriptorFactory.java index beb4c70a30..c04b829170 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/SingleValuePropertyDescriptorFactory.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/SingleValuePropertyDescriptorFactory.java @@ -6,6 +6,7 @@ package net.sourceforge.pmd.lang.rule.properties; import java.util.Map; +import net.sourceforge.pmd.AbstractPropertyDescriptorFactory; import net.sourceforge.pmd.PropertyDescriptorField; import net.sourceforge.pmd.SingleValuePropertyDescriptor; @@ -17,7 +18,7 @@ import net.sourceforge.pmd.SingleValuePropertyDescriptor; * @author Clément Fournier * @since 6.0.0 */ -public abstract class SingleValuePropertyDescriptorFactory extends BasicPropertyDescriptorFactory { +public abstract class SingleValuePropertyDescriptorFactory extends AbstractPropertyDescriptorFactory { public SingleValuePropertyDescriptorFactory(Class theValueType) { super(theValueType); @@ -31,7 +32,8 @@ public abstract class SingleValuePropertyDescriptorFactory extends BasicPrope @Override - public abstract SingleValuePropertyDescriptor createWith(Map valuesById); + public abstract SingleValuePropertyDescriptor createWith(Map valuesById, + boolean isDefinedExternally); @Override diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/StringMultiProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/StringMultiProperty.java index 56b4b3687b..e1eb927dff 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/StringMultiProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/StringMultiProperty.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.lang.rule.properties; +import static net.sourceforge.pmd.lang.rule.properties.ValueParser.STRING_PARSER; + import java.util.Arrays; import java.util.List; import java.util.Map; @@ -25,13 +27,14 @@ public final class StringMultiProperty extends AbstractMultiValueProperty> FACTORY // @formatter:off = new MultiValuePropertyDescriptorFactory(String.class) { @Override - public StringMultiProperty createWith(Map valuesById) { + public StringMultiProperty createWith(Map valuesById, boolean isDefinedExternally) { char delimiter = delimiterIn(valuesById); return new StringMultiProperty(nameIn(valuesById), descriptionIn(valuesById), - StringUtil.substringsOf(defaultValueIn(valuesById), delimiter), + parsePrimitives(defaultValueIn(valuesById), delimiter, STRING_PARSER), 0.0f, - delimiter); + delimiter, + isDefinedExternally); } }; // @formatter:on @@ -68,7 +71,14 @@ public final class StringMultiProperty extends AbstractMultiValueProperty defaultValues, float theUIOrder, char delimiter) { - super(theName, theDescription, defaultValues, theUIOrder, delimiter); + this(theName, theDescription, defaultValues, theUIOrder, delimiter, false); + } + + + /** For external defition. */ + private StringMultiProperty(String theName, String theDescription, List defaultValues, float theUIOrder, + char delimiter, boolean isDefinedExternally) { + super(theName, theDescription, defaultValues, theUIOrder, delimiter, isDefinedExternally); checkDefaults(defaultValues, delimiter); } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/StringProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/StringProperty.java index 83f8426b94..58f94d757c 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/StringProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/StringProperty.java @@ -21,8 +21,12 @@ public final class StringProperty extends AbstractSingleValueProperty { public static final PropertyDescriptorFactory FACTORY // @formatter:off = new SingleValuePropertyDescriptorFactory(String.class) { @Override - public StringProperty createWith(Map valuesById) { - return new StringProperty(nameIn(valuesById), descriptionIn(valuesById), defaultValueIn(valuesById), 0f); + public StringProperty createWith(Map valuesById, boolean isDefinedExternally) { + return new StringProperty(nameIn(valuesById), + descriptionIn(valuesById), + defaultValueIn(valuesById), + 0f, + isDefinedExternally); } }; // @formatter:on @@ -36,7 +40,13 @@ public final class StringProperty extends AbstractSingleValueProperty { * @param theUIOrder UI order */ public StringProperty(String theName, String theDescription, String defaultValue, float theUIOrder) { - super(theName, theDescription, defaultValue, theUIOrder); + this(theName, theDescription, defaultValue, theUIOrder, false); + } + + + private StringProperty(String theName, String theDescription, String defaultValue, float theUIOrder, boolean + isDefinedExternally) { + super(theName, theDescription, defaultValue, theUIOrder, isDefinedExternally); } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/TypeMultiProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/TypeMultiProperty.java index 766b08f56f..7db4f1be85 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/TypeMultiProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/TypeMultiProperty.java @@ -5,7 +5,6 @@ package net.sourceforge.pmd.lang.rule.properties; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Map; @@ -27,7 +26,7 @@ public final class TypeMultiProperty extends AbstractMultiPackagedProperty> FACTORY // @formatter:off = new MultiValuePropertyDescriptorFactory(Class.class, PACKAGED_FIELD_TYPES_BY_KEY) { @Override - public TypeMultiProperty createWith(Map valuesById) { + public TypeMultiProperty createWith(Map valuesById, boolean isDefinedExternally) { char delimiter = delimiterIn(valuesById); return new TypeMultiProperty(nameIn(valuesById), descriptionIn(valuesById), @@ -38,23 +37,6 @@ public final class TypeMultiProperty extends AbstractMultiPackagedProperty theDefaults, String[] legalPackageNames, float theUIOrder) { - super(theName, theDescription, theDefaults, legalPackageNames, theUIOrder); + this(theName, theDescription, theDefaults, legalPackageNames, theUIOrder, false); } @@ -86,11 +68,16 @@ public final class TypeMultiProperty extends AbstractMultiPackagedProperty theTypeDefaults, + String[] legalPackageNames, float theUIOrder, boolean isDefinedExternally) { + super(theName, theDescription, theTypeDefaults, legalPackageNames, theUIOrder, isDefinedExternally); + } + /** * Returns a list of Class objects parsed from the input string. * diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/TypeProperty.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/TypeProperty.java index 884882a1a1..0751cc2387 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/TypeProperty.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/TypeProperty.java @@ -25,13 +25,14 @@ public final class TypeProperty extends AbstractPackagedProperty { public static final PropertyDescriptorFactory FACTORY // @formatter:off = new SingleValuePropertyDescriptorFactory(Class.class, PACKAGED_FIELD_TYPES_BY_KEY) { @Override - public TypeProperty createWith(Map valuesById) { + public TypeProperty createWith(Map valuesById, boolean isDefinedExternally) { char delimiter = delimiterIn(valuesById); return new TypeProperty(nameIn(valuesById), descriptionIn(valuesById), - defaultValueIn(valuesById), + classFrom(defaultValueIn(valuesById)), legalPackageNamesIn(valuesById, delimiter), - 0f); + 0f, + isDefinedExternally); } }; // @formatter:on @@ -46,10 +47,11 @@ public final class TypeProperty extends AbstractPackagedProperty { * @param theUIOrder float * * @throws IllegalArgumentException if the default string could not be parsed into a Class + * @deprecated will be removed in 7.0.0 */ public TypeProperty(String theName, String theDescription, String defaultTypeStr, String[] legalPackageNames, float theUIOrder) { - this(theName, theDescription, classFrom(defaultTypeStr), legalPackageNames, theUIOrder); + this(theName, theDescription, classFrom(defaultTypeStr), legalPackageNames, theUIOrder, false); } @@ -62,11 +64,16 @@ public final class TypeProperty extends AbstractPackagedProperty { * @param legalPackageNames String[] * @param theUIOrder float * - * @throws IllegalArgumentException */ public TypeProperty(String theName, String theDescription, Class theDefault, String[] legalPackageNames, float theUIOrder) { - super(theName, theDescription, theDefault, legalPackageNames, theUIOrder); + this(theName, theDescription, theDefault, legalPackageNames, theUIOrder, false); + } + + + private TypeProperty(String theName, String theDescription, Class theDefault, String[] legalPackageNames, + float theUIOrder, boolean isDefinedExternally) { + super(theName, theDescription, theDefault, legalPackageNames, theUIOrder, isDefinedExternally); } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/ValueParser.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/ValueParser.java index 21cd075f4c..d66f9370e4 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/ValueParser.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/properties/ValueParser.java @@ -24,6 +24,15 @@ public interface ValueParser { } }; + + /** Extracts strings. That's a dummy used to return a list in StringMultiProperty. */ + ValueParser STRING_PARSER = new ValueParser() { + @Override + public String valueOf(String value) { + return value; + } + }; + // FUTURE Integer::valueOf /** Extracts integers. */ ValueParser INTEGER_PARSER = new ValueParser() { diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/properties/NonRuleWithAllPropertyTypes.java b/pmd-core/src/test/java/net/sourceforge/pmd/properties/NonRuleWithAllPropertyTypes.java index a8858d4b59..3fbd0a95a0 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/properties/NonRuleWithAllPropertyTypes.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/properties/NonRuleWithAllPropertyTypes.java @@ -5,6 +5,7 @@ package net.sourceforge.pmd.properties; import java.lang.reflect.Method; +import java.util.Arrays; import java.util.List; import net.sourceforge.pmd.RuleContext; @@ -71,7 +72,7 @@ public class NonRuleWithAllPropertyTypes extends AbstractRule { public static final TypeProperty SINGLE_TYPE = new TypeProperty("singleType", "Single type", String.class, new String[] {"java.lang"}, 5.0f); public static final TypeMultiProperty MULTI_TYPE = new TypeMultiProperty("multiType", "Multiple types", - new Class[] {Integer.class, Object.class}, new String[] {"java.lang"}, 6.0f); + Arrays.asList(Integer.class, Object.class), new String[] {"java.lang"}, 6.0f); public static final EnumeratedProperty ENUM_TYPE = new EnumeratedProperty<>("enumType", "Enumerated choices", new String[] {"String", "Object"}, new Class[] {String.class, Object.class}, 1, Class.class, 5.0f); diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/properties/TypePropertyTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/properties/TypePropertyTest.java index bf7fa53430..852011c584 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/properties/TypePropertyTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/properties/TypePropertyTest.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.properties; +import java.util.Arrays; +import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; @@ -28,46 +30,54 @@ import net.sourceforge.pmd.lang.rule.properties.TypeProperty; */ public class TypePropertyTest extends AbstractPropertyDescriptorTester { - private static final Class[] JAVA_LANG_CLASSES = {String.class, Integer.class, Thread.class, - Object.class, Runtime.class, }; - private static final Class[] JAVA_UTIL_CLASSES = {HashMap.class, Map.class, Comparator.class, Set.class, - Observer.class, }; + private static final List JAVA_LANG_CLASSES = Arrays.asList(String.class, Integer.class, Thread.class, + Object.class, Runtime.class); + private static final List JAVA_UTIL_CLASSES = Arrays.asList(HashMap.class, Map.class, + Comparator.class, Set.class, + Observer.class); + public TypePropertyTest() { super("Class"); } + @Override protected Class createValue() { - return randomChoice(JAVA_LANG_CLASSES); + return JAVA_LANG_CLASSES.get(randomInt(0, JAVA_LANG_CLASSES.size())); } + @Override protected Class createBadValue() { - return randomChoice(JAVA_UTIL_CLASSES); + return JAVA_UTIL_CLASSES.get(randomInt(0, JAVA_UTIL_CLASSES.size())); } + @Override protected PropertyDescriptor createProperty() { - return new TypeProperty("testType", "Test type property", JAVA_LANG_CLASSES[0], new String[] {"java.lang"}, + return new TypeProperty("testType", "Test type property", createValue(), new String[] {"java.lang"}, 1.0f); } + @Override protected PropertyDescriptor> createMultiProperty() { return new TypeMultiProperty("testType", "Test type property", JAVA_LANG_CLASSES, new String[] {"java.lang"}, 1.0f); } + @Override protected PropertyDescriptor createBadProperty() { - return new TypeProperty("testType", "Test type property", JAVA_LANG_CLASSES[0], new String[] {"java.util"}, + return new TypeProperty("testType", "Test type property", createValue(), new String[] {"java.util"}, 1.0f); } + @Override protected PropertyDescriptor> createBadMultiProperty() { - return new TypeMultiProperty("testType", "Test type property", new Class[] {Set.class}, + return new TypeMultiProperty("testType", "Test type property", Collections.singletonList(Set.class), new String[] {"java.lang"}, 1.0f); } }