Package net.sourceforge.pmd.properties
Class PropertyBuilder.RegexPropertyBuilder
- java.lang.Object
-
- net.sourceforge.pmd.properties.PropertyBuilder<B,T>
-
- net.sourceforge.pmd.properties.PropertyBuilder.RegexPropertyBuilder
-
- Enclosing class:
- PropertyBuilder<B extends PropertyBuilder<B,T>,T>
public static final class PropertyBuilder.RegexPropertyBuilder extends PropertyBuilder<B,T>
Specialized builder for regex properties. Allows specifying the pattern as a string, withdefaultValue(String)
.- Author:
- Clément Fournier
- Since:
- 6.10.0
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class net.sourceforge.pmd.properties.PropertyBuilder
PropertyBuilder.GenericCollectionPropertyBuilder<V,C extends Iterable<V>>, PropertyBuilder.GenericPropertyBuilder<T>, PropertyBuilder.RegexPropertyBuilder
-
-
Field Summary
-
Fields inherited from class net.sourceforge.pmd.properties.PropertyBuilder
isXPathAvailable, typeId
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PropertyDescriptor<T>
build()
Builds the descriptor and returns it.PropertyBuilder.RegexPropertyBuilder
defaultValue(String pattern)
Specify a default value using a string pattern.PropertyBuilder.RegexPropertyBuilder
defaultValue(String pattern, int flags)
Specify a default value using a string pattern.protected PropertySerializer<T>
getParser()
<C extends Iterable<T>>
PropertyBuilder.GenericCollectionPropertyBuilder<T,C>map(Collector<? super T,?,? extends C> collector)
Returns a new builder that can be used to build a property with value type<C>
.B
require(PropertyConstraint<? super T> constraint)
Add a constraint on the values that this property may take.PropertyBuilder.GenericCollectionPropertyBuilder<T,List<T>>
toList()
Returns a new builder that can be used to build a property handling lists of Ts.PropertyBuilder.GenericPropertyBuilder<Optional<T>>
toOptional(String missingValue)
Returns a new builder that can be used to build a property handlingOptional<T>
.-
Methods inherited from class net.sourceforge.pmd.properties.PropertyBuilder
availableInXPath, defaultValue, desc, getName
-
-
-
-
Method Detail
-
defaultValue
public PropertyBuilder.RegexPropertyBuilder defaultValue(String pattern)
Specify a default value using a string pattern. The argument is compiled to a pattern usingPattern.compile(String)
.- Parameters:
pattern
- String pattern- Returns:
- The same builder
- Throws:
PatternSyntaxException
- If the argument is not a valid pattern
-
defaultValue
public PropertyBuilder.RegexPropertyBuilder defaultValue(String pattern, int flags)
Specify a default value using a string pattern. The argument is compiled to a pattern usingPattern.compile(String, int)
.- Parameters:
pattern
- String patternflags
- Regex compilation flags, the same as forPattern.compile(String, int)
- Returns:
- The same builder
- Throws:
PatternSyntaxException
- If the argument is not a valid patternIllegalArgumentException
- If bit values other than those corresponding to the defined match flags are set inflags
-
getParser
protected PropertySerializer<T> getParser()
-
require
public B require(PropertyConstraint<? super T> constraint)
Description copied from class:PropertyBuilder
Add a constraint on the values that this property may take. The validity of values will be checked when parsing the XML, and invalid values will be reported. A rule will never be run if some of its properties violate some constraints.Constraints should be independent from each other, and should perform no side effects. PMD doesn't specify how many times a constraint predicate will be executed, or in what order.
- Specified by:
require
in classPropertyBuilder<B extends PropertyBuilder<B,T>,T>
- Parameters:
constraint
- The constraint- Returns:
- The same builder
- See Also:
NumericConstraints
-
toList
public PropertyBuilder.GenericCollectionPropertyBuilder<T,List<T>> toList()
Returns a new builder that can be used to build a property handling lists of Ts. The validators already added are converted to list validators. The default value cannot have previously been set.- Returns:
- A new list property builder
- Throws:
IllegalStateException
- if the default value has already been set- See Also:
map(Collector)
-
map
public <C extends Iterable<T>> PropertyBuilder.GenericCollectionPropertyBuilder<T,C> map(Collector<? super T,?,? extends C> collector)
Returns a new builder that can be used to build a property with value type<C>
. The validators already added are converted to collection validators. The default value cannot have previously been set. The returned builder will support conversion to and from a delimited string.Example usage:
// this can be set with // <value>a,b,c</value> PropertyDescriptor<Set<String>> whitelistSet = PropertyFactory.stringProperty("whitelist") .desc(...) .map(Collectors.toSet()) .emptyDefaultValue() .build();
- Returns:
- A new list property builder
- Throws:
IllegalStateException
- if the default value has already been set
-
toOptional
public PropertyBuilder.GenericPropertyBuilder<Optional<T>> toOptional(String missingValue)
Returns a new builder that can be used to build a property handlingOptional<T>
. The validators already added are used on the validator property. If the default value was previously set, it is converted to an optional withOptional.of(Object)
.- Parameters:
missingValue
- The string representation of the empty optional.- Returns:
- A new property builder for an optional.
-
build
public PropertyDescriptor<T> build()
Description copied from class:PropertyBuilder
Builds the descriptor and returns it.- Specified by:
build
in classPropertyBuilder<B extends PropertyBuilder<B,T>,T>
- Returns:
- The built descriptor
-
-