Merge branch 'pr-669'

This commit is contained in:
Juan Martín Sotuyo Dodero
2017-11-04 19:40:14 -03:00
80 changed files with 1785 additions and 1345 deletions

View File

@ -423,6 +423,7 @@ a warning will now be produced suggesting users to adopt it for better performan
* [#661](https://github.com/pmd/pmd/pull/661): \[apex] avoid hardcoding id's - [Jan Aertgeerts](https://github.com/JAertgeerts)
* [#666](https://github.com/pmd/pmd/pull/666): \[java] Add DoNotExtendJavaLangThrowable rule - [Robert Painsi](https://github.com/robertpainsi)
* [#668](https://github.com/pmd/pmd/pull/668): \[core] Fix javadoc warnings on pmd-core - [Clément Fournier](https://github.com/oowekyala)
* [#669](https://github.com/pmd/pmd/pull/669): \[core] Builder pattern for properties - [Clément Fournier](https://github.com/oowekyala)
* [#675](https://github.com/pmd/pmd/pull/675): \[java] Fix in Java grammar: Try with final resource node error - [Gonzalo Ibars Ingman](https://github.com/gibarsin)
* [#679](https://github.com/pmd/pmd/pull/679): \[core] Token scheme generalization - [Gonzalo Ibars Ingman](https://github.com/gibarsin)
* [#694](https://github.com/pmd/pmd/pull/694): \[core] Add minor fixes to root pom - [Matias Comercio](https://github.com/MatiasComercio)

View File

@ -14,8 +14,10 @@ public class AvoidDeeplyNestedIfStmtsRule extends AbstractApexRule {
private int depth;
private int depthLimit;
private static final IntegerProperty PROBLEM_DEPTH_DESCRIPTOR = new IntegerProperty("problemDepth",
"The if statement depth reporting threshold", 1, 25, 3, 1.0f);
private static final IntegerProperty PROBLEM_DEPTH_DESCRIPTOR
= IntegerProperty.named("problemDepth")
.desc("The if statement depth reporting threshold")
.range(1, 25).defaultValue(3).uiOrder(1.0f).build();
public AvoidDeeplyNestedIfStmtsRule() {
definePropertyDescriptor(PROBLEM_DEPTH_DESCRIPTOR);

View File

@ -37,8 +37,10 @@ import net.sourceforge.pmd.properties.IntegerProperty;
*/
public class StdCyclomaticComplexityRule extends AbstractApexRule {
public static final IntegerProperty REPORT_LEVEL_DESCRIPTOR = new IntegerProperty("reportLevel",
"Cyclomatic Complexity reporting threshold", 1, 30, 10, 1.0f);
public static final IntegerProperty REPORT_LEVEL_DESCRIPTOR
= IntegerProperty.named("reportLevel")
.desc("Cyclomatic Complexity reporting threshold")
.range(1, 30).defaultValue(10).uiOrder(1.0f).build();
public static final BooleanProperty SHOW_CLASSES_COMPLEXITY_DESCRIPTOR = new BooleanProperty(
"showClassesComplexity", "Add class average violations to the report", true, 2.0f);

View File

@ -26,8 +26,10 @@ import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.lang3.StringUtils;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
@ -40,11 +42,10 @@ import net.sourceforge.pmd.lang.LanguageVersion;
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.properties.AbstractPropertyDescriptorFactory;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyDescriptorFactory;
import net.sourceforge.pmd.properties.PropertyDescriptorField;
import net.sourceforge.pmd.properties.PropertyDescriptorUtil;
import net.sourceforge.pmd.properties.builders.PropertyDescriptorExternalBuilder;
import net.sourceforge.pmd.util.ResourceLoader;
/**
@ -872,20 +873,18 @@ public class RuleSetFactory {
return;
}
PropertyDescriptorFactory<?> pdFactory = PropertyDescriptorUtil.factoryFor(typeId);
PropertyDescriptorExternalBuilder<?> pdFactory = PropertyDescriptorUtil.factoryFor(typeId);
if (pdFactory == null) {
throw new RuntimeException("No property descriptor factory for type: " + typeId);
}
Set<PropertyDescriptorField> valueKeys = pdFactory.expectableFields();
Map<PropertyDescriptorField, String> values = new HashMap<>(valueKeys.size());
Map<PropertyDescriptorField, String> values = new HashMap<>();
NamedNodeMap atts = propertyElement.getAttributes();
// populate a map of values for an individual descriptor
for (PropertyDescriptorField field : valueKeys) {
String valueStr = propertyElement.getAttribute(field.attributeName());
if (valueStr != null) {
values.put(field, valueStr);
}
for (int i = 0; i < atts.getLength(); i++) {
Attr a = (Attr) atts.item(i);
values.put(PropertyDescriptorField.getConstant(a.getName()), a.getValue());
}
if (StringUtils.isBlank(values.get(DEFAULT_VALUE))) {
@ -898,7 +897,7 @@ public class RuleSetFactory {
}
// casting is not pretty but prevents the interface from having this method
PropertyDescriptor<?> desc = ((AbstractPropertyDescriptorFactory<?>) pdFactory).createExternalWith(values);
PropertyDescriptor<?> desc = pdFactory.build(values);
rule.definePropertyDescriptor(desc);
setValue(rule, desc, strValue);

View File

@ -9,7 +9,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;

View File

@ -23,7 +23,7 @@ public class MockRule extends AbstractRule {
public MockRule() {
super();
setLanguage(LanguageRegistry.getLanguage("Dummy"));
definePropertyDescriptor(new IntegerProperty("testIntProperty", "testIntProperty", 0, 100, 1, 0));
definePropertyDescriptor(IntegerProperty.named("testIntProperty").desc("testIntProperty").range(0, 100).defaultValue(1).uiOrder(0).build());
}
public MockRule(String name, String description, String message, String ruleSetName, RulePriority priority) {

View File

@ -9,16 +9,18 @@ import java.util.Map;
import net.sourceforge.pmd.properties.modules.NumericPropertyModule;
/**
* Base class for multi-valued numeric properties.
*
* @param <T> The type of number
*
* @author Brian Remedios
* @author Clément Fournier
* @version Refactored June 2017 (6.0.0)
*/
/* default */ abstract class AbstractMultiNumericProperty<T extends Number> extends AbstractMultiValueProperty<T>
implements NumericPropertyDescriptor<List<T>> {
implements NumericPropertyDescriptor<List<T>> {
private final NumericPropertyModule<T> module;

View File

@ -9,16 +9,18 @@ import java.util.Map;
import net.sourceforge.pmd.properties.modules.PackagedPropertyModule;
/**
* Multi-valued property restricting the type of its values to some packages.
*
* @param <T> The type of the values
*
* @author Brian Remedios
* @author Clément Fournier
* @version Refactored June 2017 (6.0.0)
*/
/* default */ abstract class AbstractMultiPackagedProperty<T> extends AbstractMultiValueProperty<T>
implements PackagedPropertyDescriptor<List<T>> {
implements PackagedPropertyDescriptor<List<T>> {
protected final PackagedPropertyModule<T> module;

View File

@ -14,6 +14,7 @@ import org.apache.commons.lang3.StringUtils;
import net.sourceforge.pmd.Rule;
/**
* Multi-valued property.
*
@ -23,7 +24,7 @@ import net.sourceforge.pmd.Rule;
* @version 6.0.0
*/
/* default */ abstract class AbstractMultiValueProperty<V> extends AbstractProperty<List<V>>
implements MultiValuePropertyDescriptor<V> {
implements MultiValuePropertyDescriptor<V> {
/** The default value. */

View File

@ -8,17 +8,18 @@ import java.util.Map;
import net.sourceforge.pmd.properties.modules.NumericPropertyModule;
/**
* Maintains a pair of boundary limit values between which all values managed by
* the subclasses must fit.
* Maintains a pair of boundary limit values between which all values managed by the subclasses must fit.
*
* @param <T> The type of value.
*
* @author Brian Remedios
* @author Clément Fournier
* @version Refactored June 2017 (6.0.0)
*/
/* default */ abstract class AbstractNumericProperty<T extends Number> extends AbstractSingleValueProperty<T>
implements NumericPropertyDescriptor<T> {
implements NumericPropertyDescriptor<T> {
private final NumericPropertyModule<T> module;

View File

@ -8,17 +8,19 @@ import java.util.Map;
import net.sourceforge.pmd.properties.modules.PackagedPropertyModule;
/**
* Property which restricts the type of its values to some packages. If
* the legalPackageNames value is set to null then no restrictions are made.
* Property which restricts the type of its values to some packages. If the legalPackageNames value is set to null then
* no restrictions are made.
*
* @param <T> The type of the values
*
* @author Brian Remedios
* @author Clément Fournier
* @version Refactored June 2017 (6.0.0)
*/
/* default */ abstract class AbstractPackagedProperty<T> extends AbstractSingleValueProperty<T>
implements PackagedPropertyDescriptor<T> {
implements PackagedPropertyDescriptor<T> {
protected final PackagedPropertyModule<T> module;

View File

@ -13,12 +13,14 @@ import java.util.Map;
import org.apache.commons.lang3.StringUtils;
/**
* Abstract class for properties.
*
* @param <T> The type of the property's value. This is a list type for multi-valued properties
*
* @author Brian Remedios
* @author Clément Fournier
* @version Refactored June 2017 (6.0.0)
*/
/* default */ abstract class AbstractProperty<T> implements PropertyDescriptor<T> {
@ -50,14 +52,6 @@ import org.apache.commons.lang3.StringUtils;
}
private static String checkNotEmpty(String arg, PropertyDescriptorField argId) throws IllegalArgumentException {
if (StringUtils.isBlank(arg)) {
throw new IllegalArgumentException("Property attribute '" + argId + "' cannot be null or blank");
}
return arg;
}
@Override
public String description() {
return description;
@ -107,8 +101,8 @@ import org.apache.commons.lang3.StringUtils;
@Override
public String toString() {
return "[PropertyDescriptor: name=" + name() + ","
+ " type=" + (isMultiValue() ? "List<" + type() + ">" : type()) + ","
+ " value=" + defaultValue() + "]";
+ " type=" + (isMultiValue() ? "List<" + type() + ">" : type()) + ","
+ " value=" + defaultValue() + "]";
}
@ -127,8 +121,8 @@ import org.apache.commons.lang3.StringUtils;
/**
* Adds this property's attributes to the map. Subclasses can override this to add more
* {@link PropertyDescriptorField}.
* Adds this property's attributes to the map. Subclasses can override this to add more {@link
* PropertyDescriptorField}.
*
* @param attributes The map to fill
*/
@ -153,4 +147,12 @@ import org.apache.commons.lang3.StringUtils;
}
private static String checkNotEmpty(String arg, PropertyDescriptorField argId) throws IllegalArgumentException {
if (StringUtils.isBlank(arg)) {
throw new IllegalArgumentException("Property attribute '" + argId + "' cannot be null or blank");
}
return arg;
}
}

View File

@ -15,9 +15,9 @@ import java.util.Set;
import net.sourceforge.pmd.util.CollectionUtil;
/**
* Base class for objects which can be configured through properties. Rules and
* Reports are such objects.
* Base class for objects which can be configured through properties. Rules and Reports are such objects.
*
* @author Brian Remedios
*/
@ -61,7 +61,7 @@ public abstract class AbstractPropertySource implements PropertySource {
for (PropertyDescriptor<?> descriptor : propertyDescriptors) {
if (descriptor.name().equals(propertyDescriptor.name())) {
throw new IllegalArgumentException("There is already a PropertyDescriptor with name '"
+ propertyDescriptor.name() + "' defined on Rule " + getName() + ".");
+ propertyDescriptor.name() + "' defined on Rule " + getName() + ".");
}
}
propertyDescriptors.add(propertyDescriptor);
@ -71,8 +71,7 @@ public abstract class AbstractPropertySource implements PropertySource {
/**
* Gets the name of the property source. This is e.g. the rule name or the
* report name.
* Gets the name of the property source. This is e.g. the rule name or the report name.
*
* @return the name
*/
@ -147,7 +146,7 @@ public abstract class AbstractPropertySource implements PropertySource {
private void checkValidPropertyDescriptor(PropertyDescriptor<?> propertyDescriptor) {
if (!propertyDescriptors.contains(propertyDescriptor)) {
throw new IllegalArgumentException(
"Property descriptor not defined for Rule " + getName() + ": " + propertyDescriptor);
"Property descriptor not defined for Rule " + getName() + ": " + propertyDescriptor);
}
}

View File

@ -6,6 +6,7 @@ package net.sourceforge.pmd.properties;
import net.sourceforge.pmd.Rule;
/**
* Single value property.
*
@ -14,7 +15,7 @@ import net.sourceforge.pmd.Rule;
* @author Clément Fournier
*/
/* default */ abstract class AbstractSingleValueProperty<T> extends AbstractProperty<T>
implements SingleValuePropertyDescriptor<T> {
implements SingleValuePropertyDescriptor<T> {
/** Default value. */
private T defaultValue;
@ -85,12 +86,10 @@ import net.sourceforge.pmd.Rule;
}
private String typeErrorFor(T value) { // TODO:cf consider subtypes?
private String typeErrorFor(T value) {
if (value != null && !type().isAssignableFrom(value.getClass())) {
return value + " is not an instance of " + type();
}
return null;
}

View File

@ -8,7 +8,10 @@ import static net.sourceforge.pmd.properties.ValueParserConstants.BOOLEAN_PARSER
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import net.sourceforge.pmd.properties.builders.MultiValuePropertyBuilder;
import net.sourceforge.pmd.properties.builders.PropertyDescriptorBuilderConversionWrapper;
/**
* Defines a property type that supports multiple Boolean values.
@ -17,20 +20,6 @@ import java.util.Map;
*/
public final class BooleanMultiProperty extends AbstractMultiValueProperty<Boolean> {
/** Factory. */
public static final PropertyDescriptorFactory<List<Boolean>> FACTORY // @formatter:off
= new MultiValuePropertyDescriptorFactory<Boolean>(Boolean.class) {
@Override
public BooleanMultiProperty createWith(Map<PropertyDescriptorField, String> valuesById, boolean isDefinedExternally) {
char delimiter = delimiterIn(valuesById);
return new BooleanMultiProperty(nameIn(valuesById),
descriptionIn(valuesById),
ValueParserConstants.parsePrimitives(defaultValueIn(valuesById), delimiter, BOOLEAN_PARSER),
0f,
isDefinedExternally);
}
}; // @formatter:on
/**
* Constructor using an array of defaults.
@ -76,4 +65,32 @@ public final class BooleanMultiProperty extends AbstractMultiValueProperty<Boole
return Boolean.class;
}
static PropertyDescriptorBuilderConversionWrapper.MultiValue<Boolean, BooleanMultiPBuilder> extractor() {
return new PropertyDescriptorBuilderConversionWrapper.MultiValue<Boolean, BooleanMultiPBuilder>(Boolean.class, ValueParserConstants.BOOLEAN_PARSER) {
@Override
protected BooleanMultiPBuilder newBuilder(String name) {
return new BooleanMultiPBuilder(name);
}
};
}
public static BooleanMultiPBuilder named(String name) {
return new BooleanMultiPBuilder(name);
}
public static final class BooleanMultiPBuilder extends MultiValuePropertyBuilder<Boolean, BooleanMultiPBuilder> {
private BooleanMultiPBuilder(String name) {
super(name);
}
@Override
public BooleanMultiProperty build() {
return new BooleanMultiProperty(this.name, this.description, this.defaultValues, this.uiOrder, isDefinedInXML);
}
}
}

View File

@ -6,7 +6,9 @@ package net.sourceforge.pmd.properties;
import static net.sourceforge.pmd.properties.ValueParserConstants.BOOLEAN_PARSER;
import java.util.Map;
import net.sourceforge.pmd.properties.builders.PropertyDescriptorBuilderConversionWrapper;
import net.sourceforge.pmd.properties.builders.SingleValuePropertyBuilder;
/**
* Defines a property type that supports single Boolean values.
@ -16,23 +18,8 @@ import java.util.Map;
*/
public final class BooleanProperty extends AbstractSingleValueProperty<Boolean> {
/** Factory. */
public static final PropertyDescriptorFactory<Boolean> FACTORY // @formatter:off
= new SingleValuePropertyDescriptorFactory<Boolean>(Boolean.class) {
@Override
public BooleanProperty createWith(Map<PropertyDescriptorField, String> valuesById, boolean isDefinedExternally) {
return new BooleanProperty(nameIn(valuesById),
descriptionIn(valuesById),
BOOLEAN_PARSER.valueOf(defaultValueIn(valuesById)),
0f,
isDefinedExternally);
}
}; // @formatter:on
/**
* Constructor for BooleanProperty limited to a single value. Converts
* default argument string into a boolean.
* Constructor for BooleanProperty limited to a single value. Converts default argument string into a boolean.
*
* @param theName Name
* @param theDescription Description
@ -75,4 +62,33 @@ public final class BooleanProperty extends AbstractSingleValueProperty<Boolean>
public Boolean createFrom(String propertyString) throws IllegalArgumentException {
return BOOLEAN_PARSER.valueOf(propertyString);
}
static PropertyDescriptorBuilderConversionWrapper.SingleValue<Boolean, BooleanPBuilder> extractor() {
return new PropertyDescriptorBuilderConversionWrapper.SingleValue<Boolean, BooleanPBuilder>(Boolean.class, ValueParserConstants.BOOLEAN_PARSER) {
@Override
protected BooleanPBuilder newBuilder(String name) {
return new BooleanPBuilder(name);
}
};
}
public static BooleanPBuilder named(String name) {
return new BooleanPBuilder(name);
}
public static final class BooleanPBuilder extends SingleValuePropertyBuilder<Boolean, BooleanPBuilder> {
private BooleanPBuilder(String name) {
super(name);
}
@Override
public BooleanProperty build() {
return new BooleanProperty(this.name, this.description, this.defaultValue, this.uiOrder, this.isDefinedInXML);
}
}
}

View File

@ -7,10 +7,13 @@ package net.sourceforge.pmd.properties;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import net.sourceforge.pmd.properties.builders.MultiValuePropertyBuilder;
import net.sourceforge.pmd.properties.builders.PropertyDescriptorBuilderConversionWrapper;
/**
* Multi-valued character property.
*
@ -19,27 +22,6 @@ import org.apache.commons.lang3.StringUtils;
*/
public final class CharacterMultiProperty extends AbstractMultiValueProperty<Character> {
/** Factory. */
public static final PropertyDescriptorFactory<List<Character>> FACTORY // @formatter:off
= new MultiValuePropertyDescriptorFactory<Character>(Character.class) {
@Override
protected boolean isValueMissing(String value) {
return StringUtils.isEmpty(value);
}
@Override
public CharacterMultiProperty createWith(Map<PropertyDescriptorField, String> valuesById, boolean isDefinedExternally) {
char delimiter = delimiterIn(valuesById);
return new CharacterMultiProperty(nameIn(valuesById),
descriptionIn(valuesById),
ValueParserConstants.parsePrimitives(defaultValueIn(valuesById), delimiter, ValueParserConstants.CHARACTER_PARSER),
0.0f,
delimiter,
isDefinedExternally);
}
}; // @formatter:on
/**
* Constructor using an array of defaults.
@ -111,4 +93,33 @@ public final class CharacterMultiProperty extends AbstractMultiValueProperty<Cha
return chars;
}
static PropertyDescriptorBuilderConversionWrapper.MultiValue<Character, CharacterMultiPBuilder> extractor() {
return new PropertyDescriptorBuilderConversionWrapper.MultiValue<Character, CharacterMultiPBuilder>(Character.class, ValueParserConstants.CHARACTER_PARSER) {
@Override
protected CharacterMultiPBuilder newBuilder(String name) {
return new CharacterMultiPBuilder(name);
}
};
}
public static CharacterMultiPBuilder named(String name) {
return new CharacterMultiPBuilder(name);
}
public static final class CharacterMultiPBuilder extends MultiValuePropertyBuilder<Character, CharacterMultiPBuilder> {
private CharacterMultiPBuilder(String name) {
super(name);
}
@Override
public CharacterMultiProperty build() {
return new CharacterMultiProperty(this.name, this.description, this.defaultValues, this.uiOrder, multiValueDelimiter, isDefinedInXML);
}
}
}

View File

@ -6,9 +6,9 @@ package net.sourceforge.pmd.properties;
import static net.sourceforge.pmd.properties.ValueParserConstants.CHARACTER_PARSER;
import java.util.Map;
import net.sourceforge.pmd.properties.builders.PropertyDescriptorBuilderConversionWrapper;
import net.sourceforge.pmd.properties.builders.SingleValuePropertyBuilder;
import org.apache.commons.lang3.StringUtils;
/**
* Defines a property type that supports single Character values.
@ -18,26 +18,6 @@ import org.apache.commons.lang3.StringUtils;
*/
public final class CharacterProperty extends AbstractSingleValueProperty<Character> {
public static final PropertyDescriptorFactory<Character> FACTORY // @formatter:off
= new SingleValuePropertyDescriptorFactory<Character>(Character.class) {
@Override
protected boolean isValueMissing(String value) {
return StringUtils.isEmpty(value);
}
@Override
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,
isDefinedExternally);
}
}; // @formatter:on
/**
* Constructor for CharacterProperty.
*
@ -60,20 +40,6 @@ public final class CharacterProperty extends AbstractSingleValueProperty<Charact
}
/**
* Parses a String into a Character.
*
* @param charStr String to parse
*
* @return Parsed Character
*
* @throws IllegalArgumentException if the String doesn't have length 1
*/
public static Character charFrom(String charStr) {
return CHARACTER_PARSER.valueOf(charStr);
}
/**
* Constructor.
*
@ -98,4 +64,45 @@ public final class CharacterProperty extends AbstractSingleValueProperty<Charact
return charFrom(valueString);
}
/**
* Parses a String into a Character.
*
* @param charStr String to parse
*
* @return Parsed Character
* @throws IllegalArgumentException if the String doesn't have length 1
*/
public static Character charFrom(String charStr) {
return CHARACTER_PARSER.valueOf(charStr);
}
static PropertyDescriptorBuilderConversionWrapper.SingleValue<Character, CharacterPBuilder> extractor() {
return new PropertyDescriptorBuilderConversionWrapper.SingleValue<Character, CharacterPBuilder>(Character.class, ValueParserConstants.CHARACTER_PARSER) {
@Override
protected CharacterPBuilder newBuilder(String name) {
return new CharacterPBuilder(name);
}
};
}
public static CharacterPBuilder named(String name) {
return new CharacterPBuilder(name);
}
public static final class CharacterPBuilder extends SingleValuePropertyBuilder<Character, CharacterPBuilder> {
private CharacterPBuilder(String name) {
super(name);
}
@Override
public CharacterProperty build() {
return new CharacterProperty(this.name, this.description, this.defaultValue, this.uiOrder, isDefinedInXML);
}
}
}

View File

@ -4,11 +4,12 @@
package net.sourceforge.pmd.properties;
import static net.sourceforge.pmd.properties.ValueParserConstants.DOUBLE_PARSER;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import net.sourceforge.pmd.properties.builders.MultiNumericPropertyBuilder;
import net.sourceforge.pmd.properties.builders.PropertyDescriptorBuilderConversionWrapper;
/**
* Multi-valued double property.
@ -18,27 +19,6 @@ import java.util.Map;
*/
public final class DoubleMultiProperty extends AbstractMultiNumericProperty<Double> {
/** Factory. */
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, boolean isDefinedExternally) {
String[] minMax = minMaxFrom(valuesById);
char delimiter = delimiterIn(valuesById, DEFAULT_NUMERIC_DELIMITER);
List<Double> defaultValues
= ValueParserConstants.parsePrimitives(defaultValueIn(valuesById), delimiter, DOUBLE_PARSER);
return new DoubleMultiProperty(nameIn(valuesById),
descriptionIn(valuesById),
DOUBLE_PARSER.valueOf(minMax[0]),
DOUBLE_PARSER.valueOf(minMax[1]),
defaultValues,
0f,
isDefinedExternally);
}
}; // @formatter:on
/**
* Constructor using an array of defaults.
*
@ -93,4 +73,32 @@ public final class DoubleMultiProperty extends AbstractMultiNumericProperty<Doub
return Double.valueOf(value);
}
static PropertyDescriptorBuilderConversionWrapper.MultiValue.Numeric<Double, DoubleMultiPBuilder> extractor() {
return new PropertyDescriptorBuilderConversionWrapper.MultiValue.Numeric<Double, DoubleMultiPBuilder>(Double.class, ValueParserConstants.DOUBLE_PARSER) {
@Override
protected DoubleMultiPBuilder newBuilder(String name) {
return new DoubleMultiPBuilder(name);
}
};
}
public static DoubleMultiPBuilder named(String name) {
return new DoubleMultiPBuilder(name);
}
public static final class DoubleMultiPBuilder extends MultiNumericPropertyBuilder<Double, DoubleMultiPBuilder> {
private DoubleMultiPBuilder(String name) {
super(name);
}
@Override
public DoubleMultiProperty build() {
return new DoubleMultiProperty(name, description, lowerLimit, upperLimit, defaultValues, uiOrder, isDefinedInXML);
}
}
}

View File

@ -6,34 +6,18 @@ package net.sourceforge.pmd.properties;
import static net.sourceforge.pmd.properties.ValueParserConstants.DOUBLE_PARSER;
import java.util.Map;
import net.sourceforge.pmd.properties.builders.PropertyDescriptorBuilderConversionWrapper;
import net.sourceforge.pmd.properties.builders.SingleNumericPropertyBuilder;
/**
* Defines a property type that support single double-type property values
* within an upper and lower boundary.
* Defines a property type that support single double-type property values within an upper and lower boundary.
*
* @author Brian Remedios
* @version Refactored June 2017 (6.0.0)
*/
public final class DoubleProperty extends AbstractNumericProperty<Double> {
/** Factory. */
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,
boolean isDefinedExternally) {
final String[] minMax = minMaxFrom(valuesById);
return new DoubleProperty(nameIn(valuesById),
descriptionIn(valuesById),
doubleFrom(minMax[0]),
doubleFrom(minMax[1]),
doubleFrom(defaultValueIn(valuesById)),
0f,
isDefinedExternally);
}
}; // @formatter:on
/**
* Constructor for DoubleProperty that limits itself to a single value within the specified limits. Converts string
@ -62,18 +46,6 @@ public final class DoubleProperty extends AbstractNumericProperty<Double> {
}
/**
* Parses a String into a Double.
*
* @param numberString String to parse
*
* @return Parsed Double
*/
private static Double doubleFrom(String numberString) {
return DOUBLE_PARSER.valueOf(numberString);
}
/**
* Constructor that limits itself to a single value within the specified limits.
*
@ -102,4 +74,45 @@ public final class DoubleProperty extends AbstractNumericProperty<Double> {
protected Double createFrom(String value) {
return doubleFrom(value);
}
/**
* Parses a String into a Double.
*
* @param numberString String to parse
*
* @return Parsed Double
*/
private static Double doubleFrom(String numberString) {
return DOUBLE_PARSER.valueOf(numberString);
}
static PropertyDescriptorBuilderConversionWrapper.SingleValue.Numeric<Double, DoublePBuilder> extractor() {
return new PropertyDescriptorBuilderConversionWrapper.SingleValue.Numeric<Double, DoublePBuilder>(Double.class, ValueParserConstants.DOUBLE_PARSER) {
@Override
protected DoublePBuilder newBuilder(String name) {
return new DoublePBuilder(name);
}
};
}
public static DoublePBuilder named(String name) {
return new DoublePBuilder(name);
}
public static final class DoublePBuilder extends SingleNumericPropertyBuilder<Double, DoublePBuilder> {
private DoublePBuilder(String name) {
super(name);
}
@Override
public DoubleProperty build() {
return new DoubleProperty(name, description, lowerLimit, upperLimit, defaultValue, uiOrder, isDefinedInXML);
}
}
}

View File

@ -8,9 +8,11 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.sourceforge.pmd.properties.builders.MultiValuePropertyBuilder;
import net.sourceforge.pmd.properties.modules.EnumeratedPropertyModule;
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
* mappings method returns the set of mappings between the labels and their values.
@ -24,21 +26,6 @@ import net.sourceforge.pmd.util.CollectionUtil;
public final class EnumeratedMultiProperty<E> extends AbstractMultiValueProperty<E>
implements EnumeratedPropertyDescriptor<E, List<E>> {
/** Factory. */
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, boolean isDefinedExternally) {
Object[] choices = choicesIn(valuesById);
return new EnumeratedMultiProperty<>(nameIn(valuesById),
descriptionIn(valuesById),
CollectionUtil.mapFrom(labelsIn(valuesById), choices),
selection(indicesIn(valuesById), choices),
classIn(valuesById),
0f,
isDefinedExternally);
}
}; // @formatter:on
private final EnumeratedPropertyModule<E> module;
@ -56,13 +43,13 @@ public final class EnumeratedMultiProperty<E> extends AbstractMultiValueProperty
* @param theUIOrder UI order
*
* @deprecated Use {@link #EnumeratedMultiProperty(String, String, Map, List, Class, float)}. Will be removed in
* 7.0.0
* 7.0.0
*/
@Deprecated
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, false);
selection(choiceIndices, theChoices), valueType, theUIOrder, false);
}
@ -78,13 +65,13 @@ public final class EnumeratedMultiProperty<E> extends AbstractMultiValueProperty
* @param theUIOrder UI order
*
* @deprecated Use {@link #EnumeratedMultiProperty(String, String, Map, List, Class, float)}. Will be removed in
* 7.0.0
* 7.0.0
*/
@Deprecated
public EnumeratedMultiProperty(String theName, String theDescription, String[] theLabels, E[] theChoices,
int[] choiceIndices, float theUIOrder) {
this(theName, theDescription, CollectionUtil.mapFrom(theLabels, theChoices),
selection(choiceIndices, theChoices), null, theUIOrder, false);
selection(choiceIndices, theChoices), null, theUIOrder, false);
}
@ -168,4 +155,44 @@ public final class EnumeratedMultiProperty<E> extends AbstractMultiValueProperty
return selected;
}
public static <E> EnumMultiPBuilder<E> named(String name) {
return new EnumMultiPBuilder<>(name);
}
public static final class EnumMultiPBuilder<E> extends MultiValuePropertyBuilder<E, EnumMultiPBuilder<E>> {
private Class<E> valueType;
private Map<String, E> mappings;
private EnumMultiPBuilder(String name) {
super(name);
}
public EnumMultiPBuilder<E> type(Class<E> type) {
this.valueType = type;
return this;
}
/**
* Sets the key-value mappings.
*
* @param map A map of label to value
*
* @return The same builder
*/
public EnumMultiPBuilder<E> mappings(Map<String, E> map) {
this.mappings = map;
return this;
}
@Override
public EnumeratedMultiProperty<E> build() {
return new EnumeratedMultiProperty<>(this.name, this.description, mappings, this.defaultValues, valueType, this.uiOrder, isDefinedInXML);
}
}
}

View File

@ -4,12 +4,13 @@
package net.sourceforge.pmd.properties;
import java.util.Enumeration;
import java.util.Map;
import net.sourceforge.pmd.properties.builders.SingleValuePropertyBuilder;
import net.sourceforge.pmd.properties.modules.EnumeratedPropertyModule;
import net.sourceforge.pmd.util.CollectionUtil;
/**
* 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.
@ -23,26 +24,7 @@ import net.sourceforge.pmd.util.CollectionUtil;
* @version Refactored June 2017 (6.0.0)
*/
public final class EnumeratedProperty<E> extends AbstractSingleValueProperty<E>
implements EnumeratedPropertyDescriptor<E, E> {
/** Factory. */
public static final PropertyDescriptorFactory<? extends Enumeration> FACTORY // @formatter:off
= new SingleValuePropertyDescriptorFactory<Enumeration>(Enumeration.class) { // TODO:cf Enumeration? Object?
@Override
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),
labelsToChoices,
choicesIn(valuesById)[indexIn(valuesById)],
classIn(valuesById),
0f,
isDefinedExternally);
}
}; // @formatter:on
implements EnumeratedPropertyDescriptor<E, E> {
private final EnumeratedPropertyModule<E> module;
@ -65,7 +47,7 @@ public final class EnumeratedProperty<E> extends AbstractSingleValueProperty<E>
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, false);
theChoices[defaultIndex], valueType, theUIOrder, false);
}
@ -86,7 +68,7 @@ public final class EnumeratedProperty<E> extends AbstractSingleValueProperty<E>
public EnumeratedProperty(String theName, String theDescription, String[] theLabels, E[] theChoices,
int defaultIndex, float theUIOrder) {
this(theName, theDescription, CollectionUtil.mapFrom(theLabels, theChoices),
theChoices[defaultIndex], null, theUIOrder, false);
theChoices[defaultIndex], null, theUIOrder, false);
}
@ -146,4 +128,35 @@ public final class EnumeratedProperty<E> extends AbstractSingleValueProperty<E>
}
public static <E> EnumPBuilder<E> named(String name) {
return new EnumPBuilder<>(name);
}
public static final class EnumPBuilder<E> extends SingleValuePropertyBuilder<E, EnumPBuilder<E>> {
private Class<E> valueType;
private Map<String, E> mappings;
private EnumPBuilder(String name) {
super(name);
}
public EnumPBuilder<E> type(Class<E> type) {
this.valueType = type;
return this;
}
public EnumPBuilder<E> mappings(Map<String, E> map) {
this.mappings = map;
return this;
}
@Override
public EnumeratedProperty<E> build() {
return new EnumeratedProperty<>(this.name, this.description, mappings, this.defaultValue, valueType, this.uiOrder, isDefinedInXML);
}
}
}

View File

@ -6,6 +6,7 @@ package net.sourceforge.pmd.properties;
import java.util.Map;
/**
* Interface defining an enumerated property descriptor.
*

View File

@ -1,57 +0,0 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.properties;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/** Builder for an expected fields map. */
public final class ExpectedFieldsBuilder {
private final Map<PropertyDescriptorField, Boolean> requiredFields = new HashMap<>();
private ExpectedFieldsBuilder() {
}
/**
* Adds a mapping of field/ required to the map.
*
* @param field The field to expect
* @param isRequired Whether it's required or not
*
* @return This instance, so that we have a fluent interface
*/
public ExpectedFieldsBuilder put(PropertyDescriptorField field, boolean isRequired) {
requiredFields.put(field, isRequired);
return this;
}
/**
* Gets an immutable map containing the fields we've put here.
*
* @return The map of field/ isRequired mappings
*/
public Map<PropertyDescriptorField, Boolean> build() {
return Collections.unmodifiableMap(requiredFields);
}
/**
* Gets a builder for a required fields map.
*
* @return A builder
*
* @see ExpectedFieldsBuilder
*/
public static ExpectedFieldsBuilder instance() {
return new ExpectedFieldsBuilder();
}
}

View File

@ -5,10 +5,13 @@
package net.sourceforge.pmd.properties;
import java.io.File;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import net.sourceforge.pmd.properties.builders.PropertyDescriptorBuilderConversionWrapper;
import net.sourceforge.pmd.properties.builders.SinglePackagedPropertyBuilder;
/**
* Property taking a File object as its value.
*
@ -17,19 +20,6 @@ import org.apache.commons.lang3.StringUtils;
*/
public final class FileProperty extends AbstractSingleValueProperty<File> {
/** Factory. */
public static final PropertyDescriptorFactory<File> FACTORY // @formatter:off
= new SingleValuePropertyDescriptorFactory<File>(File.class) {
@Override
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.
@ -60,4 +50,34 @@ public final class FileProperty extends AbstractSingleValueProperty<File> {
public File createFrom(String propertyString) {
return StringUtils.isBlank(propertyString) ? null : new File(propertyString);
}
static PropertyDescriptorBuilderConversionWrapper.SingleValue<File, FilePBuilder> extractor() {
return new PropertyDescriptorBuilderConversionWrapper.SingleValue<File, FilePBuilder>(File.class, ValueParserConstants.FILE_PARSER) {
@Override
protected FilePBuilder newBuilder(String name) {
return new FilePBuilder(name);
}
};
}
public static FilePBuilder named(String name) {
return new FilePBuilder(name);
}
public static final class FilePBuilder extends SinglePackagedPropertyBuilder<File, FilePBuilder> {
private FilePBuilder(String name) {
super(name);
}
@Override
public FileProperty build() {
return new FileProperty(name, description, defaultValue, uiOrder, isDefinedInXML);
}
}
}

View File

@ -4,11 +4,12 @@
package net.sourceforge.pmd.properties;
import static net.sourceforge.pmd.properties.ValueParserConstants.FLOAT_PARSER;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import net.sourceforge.pmd.properties.builders.MultiNumericPropertyBuilder;
import net.sourceforge.pmd.properties.builders.PropertyDescriptorBuilderConversionWrapper;
/**
* Multi-valued float property.
@ -18,25 +19,6 @@ import java.util.Map;
*/
public final class FloatMultiProperty extends AbstractMultiNumericProperty<Float> {
/** Factory. */
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,
boolean isDefinedExternally) {
String[] minMax = minMaxFrom(valuesById);
char delimiter = delimiterIn(valuesById, DEFAULT_NUMERIC_DELIMITER);
List<Float> defaultValues = ValueParserConstants.parsePrimitives(defaultValueIn(valuesById), delimiter, FLOAT_PARSER);
return new FloatMultiProperty(nameIn(valuesById),
descriptionIn(valuesById),
FLOAT_PARSER.valueOf(minMax[0]),
FLOAT_PARSER.valueOf(minMax[1]),
defaultValues,
0f,
isDefinedExternally);
}
}; // @formatter:on
/**
* Constructor using an array of defaults.
@ -91,4 +73,34 @@ public final class FloatMultiProperty extends AbstractMultiNumericProperty<Float
protected Float createFrom(String value) {
return Float.valueOf(value);
}
static PropertyDescriptorBuilderConversionWrapper.MultiValue.Numeric<Float, FloatMultiPBuilder> extractor() {
return new PropertyDescriptorBuilderConversionWrapper.MultiValue.Numeric<Float, FloatMultiPBuilder>(Float.class, ValueParserConstants.FLOAT_PARSER) {
@Override
protected FloatMultiPBuilder newBuilder(String name) {
return new FloatMultiPBuilder(name);
}
};
}
public static FloatMultiPBuilder named(String name) {
return new FloatMultiPBuilder(name);
}
public static final class FloatMultiPBuilder extends MultiNumericPropertyBuilder<Float, FloatMultiPBuilder> {
private FloatMultiPBuilder(String name) {
super(name);
}
@Override
public FloatMultiProperty build() {
return new FloatMultiProperty(name, description, lowerLimit, upperLimit, defaultValues, uiOrder, isDefinedInXML);
}
}
}

View File

@ -6,32 +6,17 @@ package net.sourceforge.pmd.properties;
import static net.sourceforge.pmd.properties.ValueParserConstants.FLOAT_PARSER;
import java.util.Map;
import net.sourceforge.pmd.properties.builders.PropertyDescriptorBuilderConversionWrapper;
import net.sourceforge.pmd.properties.builders.SingleNumericPropertyBuilder;
/**
* Defines a property type that supports single float property values within an
* upper and lower boundary.
* Defines a property type that supports single float property values within an upper and lower boundary.
*
* @author Brian Remedios
*/
public final class FloatProperty extends AbstractNumericProperty<Float> {
/** Factory. */
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, 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(defaultValueIn(valuesById)),
0f,
isDefinedExternally);
}
}; // @formatter:on
/**
* Constructor for FloatProperty that limits itself to a single value within the specified limits. Converts string
@ -50,7 +35,7 @@ public final class FloatProperty extends AbstractNumericProperty<Float> {
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, false);
FLOAT_PARSER.valueOf(maxStr), FLOAT_PARSER.valueOf(defaultStr), theUIOrder, false);
}
@ -91,4 +76,32 @@ public final class FloatProperty extends AbstractNumericProperty<Float> {
}
static PropertyDescriptorBuilderConversionWrapper.SingleValue.Numeric<Float, FloatPBuilder> extractor() {
return new PropertyDescriptorBuilderConversionWrapper.SingleValue.Numeric<Float, FloatPBuilder>(Float.class, ValueParserConstants.FLOAT_PARSER) {
@Override
protected FloatPBuilder newBuilder(String name) {
return new FloatPBuilder(name);
}
};
}
public static FloatPBuilder named(String name) {
return new FloatPBuilder(name);
}
public static final class FloatPBuilder extends SingleNumericPropertyBuilder<Float, FloatPBuilder> {
private FloatPBuilder(String name) {
super(name);
}
@Override
public FloatProperty build() {
return new FloatProperty(name, description, lowerLimit, upperLimit, defaultValue, uiOrder, isDefinedInXML);
}
}
}

View File

@ -4,11 +4,12 @@
package net.sourceforge.pmd.properties;
import static net.sourceforge.pmd.properties.ValueParserConstants.INTEGER_PARSER;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import net.sourceforge.pmd.properties.builders.MultiNumericPropertyBuilder;
import net.sourceforge.pmd.properties.builders.PropertyDescriptorBuilderConversionWrapper;
/**
* Multi-valued integer property.
@ -18,25 +19,6 @@ import java.util.Map;
*/
public final class IntegerMultiProperty extends AbstractMultiNumericProperty<Integer> {
/** Factory. */
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, boolean
isDefinedExternally) {
String[] minMax = minMaxFrom(valuesById);
char delimiter = delimiterIn(valuesById, DEFAULT_NUMERIC_DELIMITER);
List<Integer> defaultValues = ValueParserConstants.parsePrimitives(defaultValueIn(valuesById), delimiter, INTEGER_PARSER);
return new IntegerMultiProperty(nameIn(valuesById),
descriptionIn(valuesById),
INTEGER_PARSER.valueOf(minMax[0]),
INTEGER_PARSER.valueOf(minMax[1]),
defaultValues,
0f,
isDefinedExternally);
}
}; // @formatter:on
/**
* Constructor using an array of defaults.
@ -93,4 +75,32 @@ public final class IntegerMultiProperty extends AbstractMultiNumericProperty<Int
protected Integer createFrom(String toParse) {
return Integer.valueOf(toParse);
}
static PropertyDescriptorBuilderConversionWrapper.MultiValue.Numeric<Integer, IntegerMultiPBuilder> extractor() {
return new PropertyDescriptorBuilderConversionWrapper.MultiValue.Numeric<Integer, IntegerMultiPBuilder>(Integer.class, ValueParserConstants.INTEGER_PARSER) {
@Override
protected IntegerMultiPBuilder newBuilder(String name) {
return new IntegerMultiPBuilder(name);
}
};
}
public static IntegerMultiPBuilder named(String name) {
return new IntegerMultiPBuilder(name);
}
public static final class IntegerMultiPBuilder extends MultiNumericPropertyBuilder<Integer, IntegerMultiPBuilder> {
private IntegerMultiPBuilder(String name) {
super(name);
}
@Override
public IntegerMultiProperty build() {
return new IntegerMultiProperty(name, description, lowerLimit, upperLimit, defaultValues, uiOrder, isDefinedInXML);
}
}
}

View File

@ -6,33 +6,17 @@ package net.sourceforge.pmd.properties;
import static net.sourceforge.pmd.properties.ValueParserConstants.INTEGER_PARSER;
import java.util.Map;
import net.sourceforge.pmd.properties.builders.PropertyDescriptorBuilderConversionWrapper;
import net.sourceforge.pmd.properties.builders.SingleNumericPropertyBuilder;
/**
* Defines a datatype that supports single Integer property values within an
* upper and lower boundary.
* Defines a datatype that supports single Integer property values within an upper and lower boundary.
*
* @author Brian Remedios
*/
public final class IntegerProperty extends AbstractNumericProperty<Integer> {
/** Factory. */
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, 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(defaultValueIn(valuesById)),
0f,
isDefinedExternally);
}
}; // @formatter:on
/**
* Constructor that limits itself to a single value within the specified limits.
@ -71,4 +55,31 @@ public final class IntegerProperty extends AbstractNumericProperty<Integer> {
}
static PropertyDescriptorBuilderConversionWrapper.SingleValue.Numeric<Integer, IntegerPBuilder> extractor() {
return new PropertyDescriptorBuilderConversionWrapper.SingleValue.Numeric<Integer, IntegerPBuilder>(Integer.class, ValueParserConstants.INTEGER_PARSER) {
@Override
protected IntegerPBuilder newBuilder(String name) {
return new IntegerPBuilder(name);
}
};
}
public static IntegerPBuilder named(String name) {
return new IntegerPBuilder(name);
}
public static final class IntegerPBuilder extends SingleNumericPropertyBuilder<Integer, IntegerPBuilder> {
private IntegerPBuilder(String name) {
super(name);
}
@Override
public IntegerProperty build() {
return new IntegerProperty(name, description, lowerLimit, upperLimit, defaultValue, uiOrder, isDefinedInXML);
}
}
}

Some files were not shown because too many files have changed in this diff Show More