Package net.sourceforge.pmd.properties
Class AbstractPropertySource
- java.lang.Object
-
- net.sourceforge.pmd.properties.AbstractPropertySource
-
- All Implemented Interfaces:
PropertySource
- Direct Known Subclasses:
AbstractRenderer,AbstractRule
public abstract class AbstractPropertySource extends java.lang.Object implements PropertySource
Base class for objects which can be configured through properties. Rules and Reports are such objects.- Author:
- Brian Remedios
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<PropertyDescriptor<?>>propertyDescriptorsThe list of known properties that can be configured.protected java.util.Map<PropertyDescriptor<?>,java.lang.Object>propertyValuesByDescriptorThe values for each property.
-
Constructor Summary
Constructors Constructor Description AbstractPropertySource()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected java.util.List<PropertyDescriptor<?>>copyPropertyDescriptors()Creates a copied list of the property descriptors and returns it.protected java.util.Map<PropertyDescriptor<?>,java.lang.Object>copyPropertyValues()Creates a copied map of the values of the properties and returns it.voiddefinePropertyDescriptor(PropertyDescriptor<?> propertyDescriptor)Define a new property via a PropertyDescriptor.java.lang.StringdysfunctionReason()Returns a description of why the receiver may be dysfunctional.abstract java.lang.StringgetName()Gets the name of the property source.java.util.Map<PropertyDescriptor<?>,java.lang.Object>getPropertiesByPropertyDescriptor()Returns all the current property values for the receiver or an immutable empty map if none are specified.<T> TgetProperty(PropertyDescriptor<T> propertyDescriptor)Get the typed value for the given property.PropertyDescriptor<?>getPropertyDescriptor(java.lang.String name)Get the PropertyDescriptor for the given property name.java.util.List<PropertyDescriptor<?>>getPropertyDescriptors()Get the PropertyDescriptors for all defined properties.booleanhasDescriptor(PropertyDescriptor<?> descriptor)Returns whether this Rule has the specified PropertyDescriptor.java.util.Set<PropertyDescriptor<?>>ignoredProperties()Return the properties that are effectively ignored due to the configuration of the rule and values held by other properties.<V> voidsetProperty(MultiValuePropertyDescriptor<V> propertyDescriptor, V... values)Sets the value of a multi value property descriptor with a variable number of arguments.<T> voidsetProperty(PropertyDescriptor<T> propertyDescriptor, T value)Set the property value specified (will be type-checked)voiduseDefaultValueFor(PropertyDescriptor<?> desc)Clears out any user-specified value for the property allowing it to use the default value in the descriptor.booleanusesDefaultValues()Returns whether this Rule uses default values for properties.
-
-
-
Field Detail
-
propertyDescriptors
protected java.util.List<PropertyDescriptor<?>> propertyDescriptors
The list of known properties that can be configured.
-
propertyValuesByDescriptor
protected java.util.Map<PropertyDescriptor<?>,java.lang.Object> propertyValuesByDescriptor
The values for each property.
-
-
Method Detail
-
copyPropertyDescriptors
protected java.util.List<PropertyDescriptor<?>> copyPropertyDescriptors()
Creates a copied list of the property descriptors and returns it.- Returns:
- a copy of the property descriptors.
-
copyPropertyValues
protected java.util.Map<PropertyDescriptor<?>,java.lang.Object> copyPropertyValues()
Creates a copied map of the values of the properties and returns it.- Returns:
- a copy of the values
-
ignoredProperties
public java.util.Set<PropertyDescriptor<?>> ignoredProperties()
Description copied from interface:PropertySourceReturn the properties that are effectively ignored due to the configuration of the rule and values held by other properties. This can be used to disable corresponding widgets in a UI.- Specified by:
ignoredPropertiesin interfacePropertySource- Returns:
- the properties that are ignored
-
definePropertyDescriptor
public void definePropertyDescriptor(PropertyDescriptor<?> propertyDescriptor)
Description copied from interface:PropertySourceDefine a new property via a PropertyDescriptor.- Specified by:
definePropertyDescriptorin interfacePropertySource- Parameters:
propertyDescriptor- The property descriptor.
-
getName
public abstract java.lang.String getName()
Gets the name of the property source. This is e.g. the rule name or the report name.- Returns:
- the name
-
getPropertyDescriptor
public PropertyDescriptor<?> getPropertyDescriptor(java.lang.String name)
Description copied from interface:PropertySourceGet the PropertyDescriptor for the given property name.- Specified by:
getPropertyDescriptorin interfacePropertySource- Parameters:
name- The name of the property.- Returns:
- The PropertyDescriptor for the named property,
nullif there is no such property defined.
-
hasDescriptor
public boolean hasDescriptor(PropertyDescriptor<?> descriptor)
Description copied from interface:PropertySourceReturns whether this Rule has the specified PropertyDescriptor.- Specified by:
hasDescriptorin interfacePropertySource- Parameters:
descriptor- The PropertyDescriptor for which to check.- Returns:
- boolean
trueif the descriptor is present,falseotherwise.
-
getPropertyDescriptors
public java.util.List<PropertyDescriptor<?>> getPropertyDescriptors()
Description copied from interface:PropertySourceGet the PropertyDescriptors for all defined properties. The properties are returned sorted by UI order.- Specified by:
getPropertyDescriptorsin interfacePropertySource- Returns:
- The PropertyDescriptors in UI order.
-
getProperty
public <T> T getProperty(PropertyDescriptor<T> propertyDescriptor)
Description copied from interface:PropertySourceGet the typed value for the given property. Multi valued properties return immutable lists.- Specified by:
getPropertyin interfacePropertySource- Type Parameters:
T- The underlying type of the property descriptor.- Parameters:
propertyDescriptor- The property descriptor.- Returns:
- The property value.
-
setProperty
public <T> void setProperty(PropertyDescriptor<T> propertyDescriptor, T value)
Description copied from interface:PropertySourceSet the property value specified (will be type-checked)- Specified by:
setPropertyin interfacePropertySource- Type Parameters:
T- The underlying type of the property descriptor.- Parameters:
propertyDescriptor- The property descriptor.value- The value to set.
-
setProperty
public <V> void setProperty(MultiValuePropertyDescriptor<V> propertyDescriptor, V... values)
Description copied from interface:PropertySourceSets the value of a multi value property descriptor with a variable number of arguments.- Specified by:
setPropertyin interfacePropertySource- Type Parameters:
V- The type of the values- Parameters:
propertyDescriptor- The property descriptor for which to add a valuevalues- Values
-
getPropertiesByPropertyDescriptor
public java.util.Map<PropertyDescriptor<?>,java.lang.Object> getPropertiesByPropertyDescriptor()
Description copied from interface:PropertySourceReturns all the current property values for the receiver or an immutable empty map if none are specified.- Specified by:
getPropertiesByPropertyDescriptorin interfacePropertySource- Returns:
- all current property values or a empty map.
-
usesDefaultValues
public boolean usesDefaultValues()
Description copied from interface:PropertySourceReturns whether this Rule uses default values for properties.- Specified by:
usesDefaultValuesin interfacePropertySource- Returns:
- boolean
trueif the properties all have default values,falseotherwise.
-
useDefaultValueFor
public void useDefaultValueFor(PropertyDescriptor<?> desc)
Description copied from interface:PropertySourceClears out any user-specified value for the property allowing it to use the default value in the descriptor.- Specified by:
useDefaultValueForin interfacePropertySource- Parameters:
desc- the property to clear out
-
dysfunctionReason
public java.lang.String dysfunctionReason()
Description copied from interface:PropertySourceReturns a description of why the receiver may be dysfunctional. Usually due to missing property values or some kind of conflict between values. Returns null if the receiver is ok.- Specified by:
dysfunctionReasonin interfacePropertySource- Returns:
- String
-
-