1 package net.sourceforge.pmd;
2
3 import java.util.List;
4 import java.util.Map;
5 import java.util.Set;
6
7 /**
8 *
9 * @author Brian Remedios
10 */
11 public interface PropertySource {
12
13 /**
14 * Define a new property via a PropertyDescriptor.
15 *
16 * @param propertyDescriptor The property descriptor.
17 * @throws IllegalArgumentException If there is already a property defined the same name.
18 */
19 void definePropertyDescriptor(PropertyDescriptor<?> propertyDescriptor) throws IllegalArgumentException;
20
21 /**
22 * Get the PropertyDescriptor for the given property name.
23 *
24 * @param name The name of the property.
25 * @return The PropertyDescriptor for the named property, <code>null</code> if there is no such property defined.
26 */
27 PropertyDescriptor<?> getPropertyDescriptor(String name);
28
29 /**
30 * Get the PropertyDescriptors for all defined properties. The properties
31 * are returned sorted by UI order.
32 *
33 * @return The PropertyDescriptors in UI order.
34 */
35 List<PropertyDescriptor<?>> getPropertyDescriptors();
36
37 /**
38 * Get the typed value for the given property.
39 *
40 * @param <T> The underlying type of the property descriptor.
41 * @param propertyDescriptor The property descriptor.
42 * @return The property value.
43 */
44 <T> T getProperty(PropertyDescriptor<T> propertyDescriptor);
45
46 /**
47 * Set the property value specified (will be type-checked)
48 *
49 * @param <T> The underlying type of the property descriptor.
50 * @param propertyDescriptor The property descriptor.
51 * @param value The value to set.
52 */
53 <T> void setProperty(PropertyDescriptor<T> propertyDescriptor, T value);
54
55 /**
56 * Returns all the current property values for the receiver or an
57 * immutable empty map if none are specified.
58 */
59 Map<PropertyDescriptor<?>, Object> getPropertiesByPropertyDescriptor();
60
61 /**
62 * Returns whether this Rule has the specified PropertyDescriptor.
63 *
64 * @param descriptor The PropertyDescriptor for which to check.
65 * @return boolean <code>true</code> if the descriptor is present, <code>false</code> otherwise.
66 */
67 boolean hasDescriptor(PropertyDescriptor<?> descriptor);
68
69 /**
70 * Returns whether this Rule uses default values for properties.
71 * @return boolean <code>true</code> if the properties all have default values, <code>false</code> otherwise.
72 */
73 boolean usesDefaultValues();
74
75 /**
76 * Clears out any user-specified value for the property allowing it to use the default
77 * value in the descriptor.
78 *
79 * @param desc
80 */
81 void useDefaultValueFor(PropertyDescriptor<?> desc);
82
83 /**
84 * Return the properties that are effectively ignored due to the configuration
85 * of the rule and values held by other properties. This can be used to disable
86 * corresponding widgets in a UI.
87 *
88 */
89 Set<PropertyDescriptor<?>> ignoredProperties();
90
91 /**
92 * Returns a description of why the receiver may be dysfunctional. Usually due to missing property
93 * values or some kind of conflict between values. Returns null if the receiver is ok.
94 *
95 * @return String
96 */
97 String dysfunctionReason();
98 }