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