From c745ae1503832a17847b2db97a5626cebcb425a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Thu, 6 Dec 2018 15:02:09 +0100 Subject: [PATCH] Add long properties --- .../pmd/properties/PropertyFactory.java | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyFactory.java index 108f1b017f..0458252d14 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyFactory.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyFactory.java @@ -83,7 +83,10 @@ public final class PropertyFactory { * Returns a builder for an integer property. The property descriptor * will by default accept any value conforming to the format specified * by {@link Integer#parseInt(String)}, e.g. {@code 1234} or {@code -123}. - * Acceptable values may be further refined by {@linkplain PropertyBuilder#require(PropertyConstraint) adding constraints}. + * + *

Note that that parser only supports decimal representations. + * + *

Acceptable values may be further refined by {@linkplain PropertyBuilder#require(PropertyConstraint) adding constraints}. * The class {@link NumericConstraints} provides some useful ready-made constraints * for that purpose. * @@ -111,6 +114,43 @@ public final class PropertyFactory { } + /** + * Returns a builder for a long integer property. The property descriptor + * will by default accept any value conforming to the format specified + * by {@link Long#parseLong(String)}, e.g. {@code 1234455678854}. + * + *

Note that that parser only supports decimal representations, and that neither + * the character L nor l is permitted to appear at the end of the string as a type + * indicator, as would be permitted in Java source. + * + *

Acceptable values may be further refined by {@linkplain PropertyBuilder#require(PropertyConstraint) adding constraints}. + * The class {@link NumericConstraints} provides some useful ready-made constraints + * for that purpose. + * + * @param name Name of the property to build + * + * @return A new builder + * + * @see NumericConstraints + */ + public static GenericPropertyBuilder longIntProperty(String name) { + return new GenericPropertyBuilder<>(name, ValueParserConstants.LONG_PARSER, Long.class); + } + + + /** + * Returns a builder for a property having as value a list of long integers. The + * format of the individual items is the same as for {@linkplain #longIntProperty(String)} longIntProperty}. + * + * @param name Name of the property to build + * + * @return A new builder + */ + public static GenericCollectionPropertyBuilder> longIntListProperty(String name) { + return longIntProperty(name).toList().delim(MultiValuePropertyDescriptor.DEFAULT_NUMERIC_DELIMITER); + } + + /** * Returns a builder for a double property. The property descriptor * will by default accept any value conforming to the format specified @@ -190,7 +230,7 @@ public final class PropertyFactory { return stringProperty(name).toList(); } - + /** * Returns a builder for a character property. The property descriptor * will accept any single character string. No unescaping is performed