Removed need for wrappers
This commit is contained in:
@ -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 <T>
|
||||
* @param <T> The type of values property descriptor returned by this factory. This can be a list.
|
||||
*
|
||||
* @author Brian Remedios
|
||||
*/
|
||||
public abstract class BasicPropertyDescriptorFactory<T> implements PropertyDescriptorFactory<T> {
|
||||
public abstract class AbstractPropertyDescriptorFactory<T> implements PropertyDescriptorFactory<T> {
|
||||
|
||||
protected static final Map<PropertyDescriptorField, Boolean> CORE_FIELD_TYPES_BY_KEY
|
||||
= CollectionUtil.mapFrom(new PropertyDescriptorField[] {NAME, DESCRIPTION, DEFAULT_VALUE, DELIMITER},
|
||||
@ -41,13 +40,13 @@ public abstract class BasicPropertyDescriptorFactory<T> implements PropertyDescr
|
||||
private final Map<PropertyDescriptorField, Boolean> fieldTypesByKey;
|
||||
|
||||
|
||||
public BasicPropertyDescriptorFactory(Class<?> theValueType) {
|
||||
public AbstractPropertyDescriptorFactory(Class<?> theValueType) {
|
||||
valueType = theValueType;
|
||||
fieldTypesByKey = Collections.unmodifiableMap(CORE_FIELD_TYPES_BY_KEY);
|
||||
}
|
||||
|
||||
|
||||
public BasicPropertyDescriptorFactory(Class<?> theValueType, Map<PropertyDescriptorField, Boolean> additionalFieldTypesByKey) {
|
||||
public AbstractPropertyDescriptorFactory(Class<?> theValueType, Map<PropertyDescriptorField, Boolean> additionalFieldTypesByKey) {
|
||||
|
||||
valueType = theValueType;
|
||||
Map<PropertyDescriptorField, Boolean> temp
|
||||
@ -114,7 +113,7 @@ public abstract class BasicPropertyDescriptorFactory<T> implements PropertyDescr
|
||||
|
||||
protected static String[] labelsIn(Map<PropertyDescriptorField, String> valuesById) {
|
||||
return StringUtil.substringsOf(valuesById.get(PropertyDescriptorField.LABELS),
|
||||
AbstractMultiValueProperty.DEFAULT_DELIMITER);
|
||||
MultiValuePropertyDescriptor.DEFAULT_DELIMITER);
|
||||
}
|
||||
|
||||
|
||||
@ -140,7 +139,7 @@ public abstract class BasicPropertyDescriptorFactory<T> implements PropertyDescr
|
||||
|
||||
|
||||
protected static char delimiterIn(Map<PropertyDescriptorField, String> valuesById) {
|
||||
return delimiterIn(valuesById, AbstractMultiValueProperty.DEFAULT_DELIMITER);
|
||||
return delimiterIn(valuesById, MultiValuePropertyDescriptor.DEFAULT_DELIMITER);
|
||||
}
|
||||
|
||||
|
||||
@ -185,8 +184,8 @@ public abstract class BasicPropertyDescriptorFactory<T> implements PropertyDescr
|
||||
}
|
||||
|
||||
|
||||
public static Map<PropertyDescriptorField, Boolean> expectedFieldTypesWith(PropertyDescriptorField[] otherKeys, Boolean[]
|
||||
otherValues) {
|
||||
public static Map<PropertyDescriptorField, Boolean> expectedFieldTypesWith(PropertyDescriptorField[] otherKeys,
|
||||
Boolean[] otherValues) {
|
||||
Map<PropertyDescriptorField, Boolean> 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<T> implements PropertyDescr
|
||||
return largerMap;
|
||||
}
|
||||
|
||||
// protected static Map<String, PropertyDescriptorFactory>
|
||||
// factoriesByTypeIdFrom(PropertyDescriptorFactory[] factories) {
|
||||
// Map<String, PropertyDescriptorFactory> factoryMap = new HashMap<String,
|
||||
// PropertyDescriptorFactory>(factories.length);
|
||||
// for (PropertyDescriptorFactory factory : factories)
|
||||
// factoryMap.put(factory.typeId(), factory);
|
||||
// return factoryMap;
|
||||
// }
|
||||
//
|
||||
|
||||
@Override
|
||||
public final PropertyDescriptor<T> createWith(Map<PropertyDescriptorField, String> 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<T> createExternalWith(Map<PropertyDescriptorField, String> 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<T> createWith(Map<PropertyDescriptorField, String> valuesById, boolean isExternallyDefined);
|
||||
|
||||
|
||||
}
|
@ -17,6 +17,13 @@ import java.util.List;
|
||||
*/
|
||||
public interface MultiValuePropertyDescriptor<V> extends PropertyDescriptor<List<V>> {
|
||||
|
||||
/** 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.
|
||||
|
@ -156,4 +156,16 @@ public interface PropertyDescriptor<T> extends Comparable<PropertyDescriptor<?>>
|
||||
* @return map
|
||||
*/
|
||||
Map<PropertyDescriptorField, String> 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();
|
||||
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import java.util.Map;
|
||||
/**
|
||||
* A factory to create {@link PropertyDescriptor}s based on a map of values.
|
||||
*
|
||||
* @param <T> the type of values property descriptor returned by this factory. This can be a list.
|
||||
* @param <T> The type of values property descriptor returned by this factory. This can be a list.
|
||||
*
|
||||
* @author Brian Remedios
|
||||
*/
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -42,8 +42,8 @@ import net.sourceforge.pmd.PropertyDescriptorField;
|
||||
* the bounds
|
||||
*/
|
||||
AbstractMultiNumericProperty(String theName, String theDescription, T lower, T upper, List<T> theDefault,
|
||||
float theUIOrder) {
|
||||
super(theName, theDescription, theDefault, theUIOrder);
|
||||
float theUIOrder, boolean isDefinedExternally) {
|
||||
super(theName, theDescription, theDefault, theUIOrder, isDefinedExternally);
|
||||
|
||||
lowerLimit = lower;
|
||||
upperLimit = upper;
|
||||
|
@ -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<PropertyDescriptorField, Boolean> 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<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);
|
||||
|
||||
|
@ -26,11 +26,7 @@ import net.sourceforge.pmd.util.StringUtil;
|
||||
/* default */ abstract class AbstractMultiValueProperty<V> extends AbstractProperty<List<V>>
|
||||
implements MultiValuePropertyDescriptor<V> {
|
||||
|
||||
/** 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<V> 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<V> theDefault, float theUIOrder) {
|
||||
this(theName, theDescription, theDefault, theUIOrder, DEFAULT_DELIMITER);
|
||||
AbstractMultiValueProperty(String theName, String theDescription, List<V> 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<V> 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;
|
||||
}
|
||||
|
@ -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<T> {
|
||||
|
||||
public static final Map<PropertyDescriptorField, Boolean> 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;
|
||||
|
@ -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<PropertyDescriptorField, Boolean> 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);
|
||||
|
||||
|
@ -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<T> getWrapper();
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isDefinedExternally() {
|
||||
return isDefinedExternally;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -24,12 +24,13 @@ public final class BooleanMultiProperty extends AbstractMultiValueProperty<Boole
|
||||
public static final PropertyDescriptorFactory<List<Boolean>> FACTORY // @formatter:off
|
||||
= new MultiValuePropertyDescriptorFactory<Boolean>(Boolean.class) {
|
||||
@Override
|
||||
public BooleanMultiProperty createWith(Map<PropertyDescriptorField, String> valuesById) {
|
||||
public BooleanMultiProperty createWith(Map<PropertyDescriptorField, String> 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<Boole
|
||||
* @param theUIOrder UI order
|
||||
*/
|
||||
public BooleanMultiProperty(String theName, String theDescription, Boolean[] defaultValues, float theUIOrder) {
|
||||
this(theName, theDescription, Arrays.asList(defaultValues), theUIOrder);
|
||||
this(theName, theDescription, Arrays.asList(defaultValues), theUIOrder, false);
|
||||
}
|
||||
|
||||
|
||||
@ -56,7 +57,13 @@ public final class BooleanMultiProperty extends AbstractMultiValueProperty<Boole
|
||||
* @param theUIOrder UI order
|
||||
*/
|
||||
public BooleanMultiProperty(String theName, String theDescription, List<Boolean> defaultValues, float theUIOrder) {
|
||||
super(theName, theDescription, defaultValues, theUIOrder);
|
||||
this(theName, theDescription, defaultValues, theUIOrder, false);
|
||||
}
|
||||
|
||||
|
||||
private BooleanMultiProperty(String theName, String theDescription, List<Boolean> defaultValues,
|
||||
float theUIOrder, boolean isDefinedExternally) {
|
||||
super(theName, theDescription, defaultValues, theUIOrder, isDefinedExternally);
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,11 +23,12 @@ public final class BooleanProperty extends AbstractSingleValueProperty<Boolean>
|
||||
public static final PropertyDescriptorFactory<Boolean> FACTORY // @formatter:off
|
||||
= new SingleValuePropertyDescriptorFactory<Boolean>(Boolean.class) {
|
||||
@Override
|
||||
public BooleanProperty createWith(Map<PropertyDescriptorField, String> valuesById) {
|
||||
public BooleanProperty createWith(Map<PropertyDescriptorField, String> 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<Boolean>
|
||||
* @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<Boolean>
|
||||
* @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<Boolean> type() {
|
||||
return Boolean.class;
|
||||
|
@ -25,13 +25,14 @@ public final class CharacterMultiProperty extends AbstractMultiValueProperty<Cha
|
||||
public static final PropertyDescriptorFactory<List<Character>> FACTORY // @formatter:off
|
||||
= new MultiValuePropertyDescriptorFactory<Character>(Character.class) {
|
||||
@Override
|
||||
public CharacterMultiProperty createWith(Map<PropertyDescriptorField, String> valuesById) {
|
||||
public CharacterMultiProperty createWith(Map<PropertyDescriptorField, String> 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<Cha
|
||||
*
|
||||
* @throws IllegalArgumentException if the delimiter is in the default values
|
||||
*/
|
||||
public CharacterMultiProperty(String theName, String theDescription, Character[] defaultValues, float theUIOrder,
|
||||
char delimiter) {
|
||||
this(theName, theDescription, Arrays.asList(defaultValues), theUIOrder, delimiter);
|
||||
public CharacterMultiProperty(String theName, String theDescription, Character[] defaultValues, float theUIOrder, char delimiter) {
|
||||
this(theName, theDescription, Arrays.asList(defaultValues), theUIOrder, delimiter, false);
|
||||
}
|
||||
|
||||
|
||||
private CharacterMultiProperty(String theName, String theDescription, List<Character> 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<Cha
|
||||
*
|
||||
* @throws IllegalArgumentException if the delimiter is in the default values
|
||||
*/
|
||||
public CharacterMultiProperty(String theName, String theDescription, List<Character> 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<Character> defaultValues, float theUIOrder, char delimiter) {
|
||||
this(theName, theDescription, defaultValues, theUIOrder, delimiter, false);
|
||||
}
|
||||
|
||||
|
||||
|
@ -22,12 +22,13 @@ public final class CharacterProperty extends AbstractSingleValueProperty<Charact
|
||||
public static final PropertyDescriptorFactory<Character> FACTORY // @formatter:off
|
||||
= new SingleValuePropertyDescriptorFactory<Character>(Character.class) {
|
||||
@Override
|
||||
public CharacterProperty createWith(Map<PropertyDescriptorField, String> valuesById) {
|
||||
public CharacterProperty createWith(Map<PropertyDescriptorField, String> 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<Charact
|
||||
* @param theUIOrder float
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* @deprecated will be removed in 7.0.0
|
||||
*/
|
||||
public CharacterProperty(String theName, String theDescription, String defaultStr, float theUIOrder) {
|
||||
this(theName, theDescription, charFrom(defaultStr), theUIOrder);
|
||||
this(theName, theDescription, charFrom(defaultStr), theUIOrder, false);
|
||||
}
|
||||
|
||||
|
||||
@ -56,7 +58,12 @@ public final class CharacterProperty extends AbstractSingleValueProperty<Charact
|
||||
* @param theUIOrder UI order
|
||||
*/
|
||||
public CharacterProperty(String theName, String theDescription, Character theDefault, float theUIOrder) {
|
||||
super(theName, theDescription, theDefault, theUIOrder);
|
||||
this(theName, theDescription, theDefault, theUIOrder, false);
|
||||
}
|
||||
|
||||
|
||||
private CharacterProperty(String theName, String theDescription, Character theDefault, float theUIOrder, boolean isDefinedExternally) {
|
||||
super(theName, theDescription, theDefault, theUIOrder, isDefinedExternally);
|
||||
}
|
||||
|
||||
|
||||
|
@ -26,7 +26,7 @@ public final class DoubleMultiProperty extends AbstractMultiNumericProperty<Doub
|
||||
public static final PropertyDescriptorFactory<List<Double>> FACTORY // @formatter:off
|
||||
= new MultiValuePropertyDescriptorFactory<Double>(Double.class, NUMBER_FIELD_TYPES_BY_KEY) {
|
||||
@Override
|
||||
public DoubleMultiProperty createWith(Map<PropertyDescriptorField, String> valuesById) {
|
||||
public DoubleMultiProperty createWith(Map<PropertyDescriptorField, String> valuesById, boolean isDefinedExternally) {
|
||||
String[] minMax = minMaxFrom(valuesById);
|
||||
char delimiter = delimiterIn(valuesById, DEFAULT_NUMERIC_DELIMITER);
|
||||
List<Double> defaultValues = parsePrimitives(numericDefaultValueIn(valuesById), delimiter, DOUBLE_PARSER);
|
||||
@ -35,7 +35,8 @@ public final class DoubleMultiProperty extends AbstractMultiNumericProperty<Doub
|
||||
DOUBLE_PARSER.valueOf(minMax[0]),
|
||||
DOUBLE_PARSER.valueOf(minMax[1]),
|
||||
defaultValues,
|
||||
0f);
|
||||
0f,
|
||||
isDefinedExternally);
|
||||
}
|
||||
}; // @formatter:on
|
||||
|
||||
@ -54,7 +55,7 @@ public final class DoubleMultiProperty extends AbstractMultiNumericProperty<Doub
|
||||
*/
|
||||
public DoubleMultiProperty(String theName, String theDescription, Double min, Double max,
|
||||
Double[] defaultValues, float theUIOrder) {
|
||||
this(theName, theDescription, min, max, Arrays.asList(defaultValues), theUIOrder);
|
||||
this(theName, theDescription, min, max, Arrays.asList(defaultValues), theUIOrder, false);
|
||||
}
|
||||
|
||||
|
||||
@ -72,7 +73,12 @@ public final class DoubleMultiProperty extends AbstractMultiNumericProperty<Doub
|
||||
*/
|
||||
public DoubleMultiProperty(String theName, String theDescription, Double min, Double max,
|
||||
List<Double> 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<Double> defaultValues, float theUIOrder, boolean isDefinedExternally) {
|
||||
super(theName, theDescription, min, max, defaultValues, theUIOrder, isDefinedExternally);
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,14 +23,16 @@ public final class DoubleProperty extends AbstractNumericProperty<Double> {
|
||||
public static final PropertyDescriptorFactory<Double> FACTORY // @formatter:off
|
||||
= new SingleValuePropertyDescriptorFactory<Double>(Double.class, NUMBER_FIELD_TYPES_BY_KEY) {
|
||||
@Override
|
||||
public DoubleProperty createWith(Map<PropertyDescriptorField, String> valuesById) {
|
||||
public DoubleProperty createWith(Map<PropertyDescriptorField, String> 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<Double> {
|
||||
* @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<Double> {
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 <E> The type of the values
|
||||
*
|
||||
@ -30,14 +30,15 @@ public final class EnumeratedMultiProperty<E> extends AbstractMultiValueProperty
|
||||
public static final PropertyDescriptorFactory<List<Object>> FACTORY // @formatter:off
|
||||
= new MultiValuePropertyDescriptorFactory<Object>(Object.class) { // TODO:cf is Object the right type?
|
||||
@Override
|
||||
public EnumeratedMultiProperty createWith(Map<PropertyDescriptorField, String> valuesById) {
|
||||
public EnumeratedMultiProperty createWith(Map<PropertyDescriptorField, String> 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<E> extends AbstractMultiValueProperty
|
||||
public EnumeratedMultiProperty(String theName, String theDescription, String[] theLabels, E[] theChoices,
|
||||
int[] choiceIndices, Class<E> 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<E> extends AbstractMultiValueProperty
|
||||
*/
|
||||
public EnumeratedMultiProperty(String theName, String theDescription, Map<String, E> choices,
|
||||
List<E> defaultValues, Class<E> valueType, float theUIOrder) {
|
||||
super(theName, theDescription, defaultValues, theUIOrder);
|
||||
this(theName, theDescription, choices, defaultValues, valueType, theUIOrder, false);
|
||||
}
|
||||
|
||||
|
||||
private EnumeratedMultiProperty(String theName, String theDescription, Map<String, E> choices,
|
||||
List<E> defaultValues, Class<E> valueType, float theUIOrder,
|
||||
boolean isDefinedExternally) {
|
||||
super(theName, theDescription, defaultValues, theUIOrder, isDefinedExternally);
|
||||
|
||||
checkDefaults(defaultValues, choices);
|
||||
|
||||
|
@ -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 <E> Type of the choices
|
||||
* <p>This property currently doesn't support serialization and cannot be defined in a ruleset file.z
|
||||
*
|
||||
* @param <E> Type of the values
|
||||
*
|
||||
* @author Brian Remedios
|
||||
* @version Refactored June 2017 (6.0.0)
|
||||
@ -32,14 +32,16 @@ public final class EnumeratedProperty<E> extends AbstractSingleValueProperty<E>
|
||||
= new SingleValuePropertyDescriptorFactory<Enumeration>(Enumeration.class) { // TODO:cf Enumeration? Object?
|
||||
|
||||
@Override
|
||||
public EnumeratedProperty createWith(Map<PropertyDescriptorField, String> valuesById) {
|
||||
public EnumeratedProperty createWith(Map<PropertyDescriptorField, String> valuesById, boolean isDefinedExternally) {
|
||||
Map<String, Object> 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<E> extends AbstractSingleValueProperty<E>
|
||||
private final Class<E> 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<E> 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<String, E> labelsToChoices,
|
||||
E defaultValue, Class<E> valueType, float theUIOrder) {
|
||||
super(theName, theDescription, defaultValue, theUIOrder);
|
||||
this(theName, theDescription, labelsToChoices, defaultValue, valueType, theUIOrder, false);
|
||||
}
|
||||
|
||||
|
||||
private EnumeratedProperty(String theName, String theDescription, Map<String, E> labelsToChoices,
|
||||
E defaultValue, Class<E> valueType, float theUIOrder, boolean isDefinedExternally) {
|
||||
super(theName, theDescription, defaultValue, theUIOrder, isDefinedExternally);
|
||||
|
||||
this.valueType = valueType;
|
||||
choicesByLabel = Collections.unmodifiableMap(labelsToChoices);
|
||||
|
@ -23,17 +23,33 @@ public final class FileProperty extends AbstractSingleValueProperty<File> {
|
||||
public static final PropertyDescriptorFactory<File> FACTORY // @formatter:off
|
||||
= new SingleValuePropertyDescriptorFactory<File>(File.class) {
|
||||
@Override
|
||||
public FileProperty createWith(Map<PropertyDescriptorField, String> valuesById) {
|
||||
return new FileProperty(nameIn(valuesById), descriptionIn(valuesById), null, 0f);
|
||||
public FileProperty createWith(Map<PropertyDescriptorField, String> 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<File> type() {
|
||||
return File.class;
|
||||
|
@ -26,7 +26,8 @@ public final class FloatMultiProperty extends AbstractMultiNumericProperty<Float
|
||||
public static final PropertyDescriptorFactory<List<Float>> FACTORY // @formatter:off
|
||||
= new MultiValuePropertyDescriptorFactory<Float>(Float.class, NUMBER_FIELD_TYPES_BY_KEY) {
|
||||
@Override
|
||||
public FloatMultiProperty createWith(Map<PropertyDescriptorField, String> valuesById) {
|
||||
public FloatMultiProperty createWith(Map<PropertyDescriptorField, String> valuesById,
|
||||
boolean isDefinedExternally) {
|
||||
String[] minMax = minMaxFrom(valuesById);
|
||||
char delimiter = delimiterIn(valuesById, DEFAULT_NUMERIC_DELIMITER);
|
||||
List<Float> defaultValues = parsePrimitives(numericDefaultValueIn(valuesById), delimiter, FLOAT_PARSER);
|
||||
@ -34,7 +35,9 @@ public final class FloatMultiProperty extends AbstractMultiNumericProperty<Float
|
||||
descriptionIn(valuesById),
|
||||
FLOAT_PARSER.valueOf(minMax[0]),
|
||||
FLOAT_PARSER.valueOf(minMax[1]),
|
||||
defaultValues, 0f);
|
||||
defaultValues,
|
||||
0f,
|
||||
isDefinedExternally);
|
||||
}
|
||||
}; // @formatter:on
|
||||
|
||||
@ -53,7 +56,7 @@ public final class FloatMultiProperty extends AbstractMultiNumericProperty<Float
|
||||
*/
|
||||
public FloatMultiProperty(String theName, String theDescription, Float min, Float max,
|
||||
Float[] defaultValues, float theUIOrder) {
|
||||
this(theName, theDescription, min, max, Arrays.asList(defaultValues), theUIOrder);
|
||||
this(theName, theDescription, min, max, Arrays.asList(defaultValues), theUIOrder, false);
|
||||
}
|
||||
|
||||
|
||||
@ -71,7 +74,13 @@ public final class FloatMultiProperty extends AbstractMultiNumericProperty<Float
|
||||
*/
|
||||
public FloatMultiProperty(String theName, String theDescription, Float min, Float max,
|
||||
List<Float> 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<Float> defaultValues, float theUIOrder, boolean isDefinedExternally) {
|
||||
super(theName, theDescription, min, max, defaultValues, theUIOrder, isDefinedExternally);
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,13 +23,15 @@ public final class FloatProperty extends AbstractNumericProperty<Float> {
|
||||
public static final PropertyDescriptorFactory<Float> FACTORY // @formatter:off
|
||||
= new SingleValuePropertyDescriptorFactory<Float>(Float.class, NUMBER_FIELD_TYPES_BY_KEY) {
|
||||
@Override
|
||||
public FloatProperty createWith(Map<PropertyDescriptorField, String> valuesById) {
|
||||
public FloatProperty createWith(Map<PropertyDescriptorField, String> 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<Float> {
|
||||
* @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<Float> {
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -26,7 +26,8 @@ public final class IntegerMultiProperty extends AbstractMultiNumericProperty<Int
|
||||
public static final PropertyDescriptorFactory<List<Integer>> FACTORY // @formatter:off
|
||||
= new MultiValuePropertyDescriptorFactory<Integer>(Integer.class, NUMBER_FIELD_TYPES_BY_KEY) {
|
||||
@Override
|
||||
public IntegerMultiProperty createWith(Map<PropertyDescriptorField, String> valuesById) {
|
||||
public IntegerMultiProperty createWith(Map<PropertyDescriptorField, String> valuesById, boolean
|
||||
isDefinedExternally) {
|
||||
String[] minMax = minMaxFrom(valuesById);
|
||||
char delimiter = delimiterIn(valuesById, DEFAULT_NUMERIC_DELIMITER);
|
||||
List<Integer> defaultValues = parsePrimitives(numericDefaultValueIn(valuesById), delimiter, INTEGER_PARSER);
|
||||
@ -35,7 +36,8 @@ public final class IntegerMultiProperty extends AbstractMultiNumericProperty<Int
|
||||
INTEGER_PARSER.valueOf(minMax[0]),
|
||||
INTEGER_PARSER.valueOf(minMax[1]),
|
||||
defaultValues,
|
||||
0f);
|
||||
0f,
|
||||
isDefinedExternally);
|
||||
}
|
||||
}; // @formatter:on
|
||||
|
||||
@ -54,7 +56,7 @@ public final class IntegerMultiProperty extends AbstractMultiNumericProperty<Int
|
||||
*/
|
||||
public IntegerMultiProperty(String theName, String theDescription, Integer min, Integer max,
|
||||
Integer[] defaultValues, float theUIOrder) {
|
||||
this(theName, theDescription, min, max, Arrays.asList(defaultValues), theUIOrder);
|
||||
this(theName, theDescription, min, max, Arrays.asList(defaultValues), theUIOrder, false);
|
||||
}
|
||||
|
||||
|
||||
@ -73,7 +75,14 @@ public final class IntegerMultiProperty extends AbstractMultiNumericProperty<Int
|
||||
public IntegerMultiProperty(String theName, String theDescription, Integer min, Integer max,
|
||||
List<Integer> 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<Integer> defaultValues, float theUIOrder, boolean isDefinedExternally) {
|
||||
|
||||
super(theName, theDescription, min, max, defaultValues, theUIOrder, isDefinedExternally);
|
||||
}
|
||||
|
||||
|
||||
|
@ -22,14 +22,15 @@ public final class IntegerProperty extends AbstractNumericProperty<Integer> {
|
||||
public static final PropertyDescriptorFactory<Integer> FACTORY // @formatter:off
|
||||
= new SingleValuePropertyDescriptorFactory<Integer>(Integer.class, NUMBER_FIELD_TYPES_BY_KEY) {
|
||||
@Override
|
||||
public IntegerProperty createWith(Map<PropertyDescriptorField, String> valuesById) {
|
||||
public IntegerProperty createWith(Map<PropertyDescriptorField, String> 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<Integer> {
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -26,7 +26,7 @@ public final class LongMultiProperty extends AbstractMultiNumericProperty<Long>
|
||||
public static final PropertyDescriptorFactory<List<Long>> FACTORY // @formatter:off
|
||||
= new MultiValuePropertyDescriptorFactory<Long>(Long.class, NUMBER_FIELD_TYPES_BY_KEY) {
|
||||
@Override
|
||||
public LongMultiProperty createWith(Map<PropertyDescriptorField, String> valuesById) {
|
||||
public LongMultiProperty createWith(Map<PropertyDescriptorField, String> valuesById, boolean isDefinedExternally) {
|
||||
String[] minMax = minMaxFrom(valuesById);
|
||||
char delimiter = delimiterIn(valuesById, DEFAULT_NUMERIC_DELIMITER);
|
||||
List<Long> defaultValues = parsePrimitives(defaultValueIn(valuesById), delimiter, LONG_PARSER);
|
||||
@ -34,7 +34,9 @@ public final class LongMultiProperty extends AbstractMultiNumericProperty<Long>
|
||||
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<Long>
|
||||
*/
|
||||
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<Long>
|
||||
*/
|
||||
public LongMultiProperty(String theName, String theDescription, Long min, Long max,
|
||||
List<Long> 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<Long> defaultValues, float theUIOrder, boolean isDefinedExternally) {
|
||||
super(theName, theDescription, min, max, defaultValues, theUIOrder, isDefinedExternally);
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,13 +23,15 @@ public final class LongProperty extends AbstractNumericProperty<Long> {
|
||||
public static final PropertyDescriptorFactory<Long> FACTORY // @formatter:off
|
||||
= new SingleValuePropertyDescriptorFactory<Long>(Long.class, NUMBER_FIELD_TYPES_BY_KEY) {
|
||||
@Override
|
||||
public LongProperty createWith(Map<PropertyDescriptorField, String> valuesById) {
|
||||
public LongProperty createWith(Map<PropertyDescriptorField, String> 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<Long> {
|
||||
* @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<Long> {
|
||||
* @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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -31,10 +31,14 @@ public final class MethodMultiProperty extends AbstractMultiPackagedProperty<Met
|
||||
public static final PropertyDescriptorFactory<List<Method>> FACTORY // @formatter:off
|
||||
= new MultiValuePropertyDescriptorFactory<Method>(Method.class, PACKAGED_FIELD_TYPES_BY_KEY) {
|
||||
@Override
|
||||
public MethodMultiProperty createWith(Map<PropertyDescriptorField, String> valuesById) {
|
||||
public MethodMultiProperty createWith(Map<PropertyDescriptorField, String> 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<Met
|
||||
*/
|
||||
public MethodMultiProperty(String theName, String theDescription, List<Method> 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<Method> theDefaults,
|
||||
String[] legalPackageNames, float theUIOrder, boolean isDefinedExternally) {
|
||||
super(theName, theDescription, theDefaults, legalPackageNames, theUIOrder, isDefinedExternally);
|
||||
}
|
||||
|
||||
|
||||
@ -75,7 +85,7 @@ public final class MethodMultiProperty extends AbstractMultiPackagedProperty<Met
|
||||
*/
|
||||
public MethodMultiProperty(String theName, String theDescription, String methodDefaults,
|
||||
String[] legalPackageNames, float theUIOrder) {
|
||||
super(theName, theDescription, methodsFrom(methodDefaults), legalPackageNames, theUIOrder);
|
||||
this(theName, theDescription, methodsFrom(methodDefaults), legalPackageNames, theUIOrder, false);
|
||||
}
|
||||
|
||||
|
||||
@ -91,13 +101,6 @@ public final class MethodMultiProperty extends AbstractMultiPackagedProperty<Met
|
||||
}
|
||||
|
||||
|
||||
// TODO:cf deprecate this
|
||||
public MethodMultiProperty(String theName, String theDescription, String methodDefaults,
|
||||
Map<PropertyDescriptorField, String> 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<Met
|
||||
|
||||
@Override
|
||||
protected String packageNameOf(Method item) {
|
||||
final Method method = item;
|
||||
return method.getDeclaringClass().getName() + '.' + method.getName();
|
||||
return item.getDeclaringClass().getName() + '.' + item.getName();
|
||||
}
|
||||
|
||||
|
||||
|
@ -33,13 +33,14 @@ public final class MethodProperty extends AbstractPackagedProperty<Method> {
|
||||
public static final PropertyDescriptorFactory<Method> FACTORY // @formatter:off
|
||||
= new SingleValuePropertyDescriptorFactory<Method>(Method.class, PACKAGED_FIELD_TYPES_BY_KEY) {
|
||||
@Override
|
||||
public MethodProperty createWith(Map<PropertyDescriptorField, String> valuesById) {
|
||||
public MethodProperty createWith(Map<PropertyDescriptorField, String> 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<Method> {
|
||||
|
||||
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) {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user