1
2
3
4 package net.sourceforge.pmd.lang.rule.properties;
5
6 import java.util.Map;
7
8 import net.sourceforge.pmd.PropertyDescriptorFactory;
9 import net.sourceforge.pmd.lang.rule.properties.factories.BasicPropertyDescriptorFactory;
10 import net.sourceforge.pmd.util.StringUtil;
11
12
13
14
15
16
17
18
19
20 public class TypeMultiProperty extends AbstractMultiPackagedProperty<Class[]> {
21
22 public static final PropertyDescriptorFactory FACTORY = new BasicPropertyDescriptorFactory<TypeMultiProperty>(
23 Class[].class, PACKAGED_FIELD_TYPES_BY_KEY) {
24
25 public TypeMultiProperty createWith(Map<String, String> valuesById) {
26 char delimiter = delimiterIn(valuesById);
27 return new TypeMultiProperty(nameIn(valuesById), descriptionIn(valuesById), defaultValueIn(valuesById),
28 legalPackageNamesIn(valuesById, delimiter), 0f);
29 }
30 };
31
32
33
34
35
36
37
38
39
40
41
42 public TypeMultiProperty(String theName, String theDescription, Class<?>[] theDefaults, String[] legalPackageNames,
43 float theUIOrder) {
44 super(theName, theDescription, theDefaults, legalPackageNames, theUIOrder);
45
46 }
47
48
49
50
51
52
53
54
55
56
57
58 public TypeMultiProperty(String theName, String theDescription, String theTypeDefaults, String[] legalPackageNames,
59 float theUIOrder) {
60 this(theName, theDescription, typesFrom(theTypeDefaults), legalPackageNames, theUIOrder);
61
62 }
63
64
65
66
67
68
69
70
71
72
73
74 public TypeMultiProperty(String theName, String theDescription, String theTypeDefaults,
75 Map<String, String> otherParams, float theUIOrder) {
76 this(theName, theDescription, typesFrom(theTypeDefaults), packageNamesIn(otherParams), theUIOrder);
77 }
78
79
80
81
82
83 public static Class<?>[] typesFrom(String classesStr) {
84 String[] values = StringUtil.substringsOf(classesStr, DELIMITER);
85
86 Class<?>[] classes = new Class<?>[values.length];
87 for (int i = 0; i < values.length; i++) {
88 classes[i] = TypeProperty.classFrom(values[i]);
89 }
90 return classes;
91 }
92
93
94
95
96
97 @Override
98 protected String packageNameOf(Object item) {
99 return ((Class<?>) item).getName();
100 }
101
102
103
104
105
106 public Class<Class[]> type() {
107 return Class[].class;
108 }
109
110
111
112
113 @Override
114 protected String itemTypeName() {
115 return "type";
116 }
117
118
119
120
121
122 @Override
123 protected String asString(Object value) {
124 return value == null ? "" : ((Class<?>) value).getName();
125 }
126
127
128
129
130
131
132 public Class<?>[] valueFrom(String valueString) {
133 return typesFrom(valueString);
134 }
135 }