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