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 public class MethodMultiProperty extends AbstractMultiPackagedProperty<Method[]> {
23
24 public static final PropertyDescriptorFactory FACTORY = new BasicPropertyDescriptorFactory<MethodMultiProperty>(Method[].class, packagedFieldTypesByKey) {
25
26 public MethodMultiProperty createWith(Map<String, String> valuesById) {
27 return new MethodMultiProperty(
28 nameIn(valuesById),
29 descriptionIn(valuesById),
30 defaultValueIn(valuesById),
31 legalPackageNamesIn(valuesById),
32 0f);
33 }
34 };
35
36
37
38
39
40
41
42
43
44
45
46 public MethodMultiProperty(String theName, String theDescription, Method[] theDefaults, String[] legalPackageNames, 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, String[] legalPackageNames, float theUIOrder) {
61 super(theName, theDescription, methodsFrom(methodDefaults), legalPackageNames, theUIOrder);
62 }
63
64
65
66
67
68
69
70
71
72
73
74 public MethodMultiProperty(String theName, String theDescription, String methodDefaults, Map<String, String> otherParams, float theUIOrder) {
75 this(theName, theDescription, methodsFrom(methodDefaults), packageNamesIn(otherParams), theUIOrder);
76 }
77
78
79
80
81
82 public static Method[] methodsFrom(String methodsStr) {
83
84 String[] values = StringUtil.substringsOf(methodsStr, DELIMITER);
85
86 Method[] methods = new Method[values.length];
87 for (int i = 0; i < methods.length; i++) {
88 methods[i] = MethodProperty.methodFrom(values[i], MethodProperty.CLASS_METHOD_DELIMITER, MethodProperty.METHOD_ARG_DELIMITER);
89 }
90 return methods;
91 }
92
93
94
95
96
97
98
99
100 @Override
101 protected String asString(Object value) {
102 return value == null ? "" : MethodProperty.asStringFor((Method) value);
103 }
104
105
106
107
108
109 @Override
110 protected String packageNameOf(Object item) {
111
112 final Method method = (Method) item;
113 return method.getDeclaringClass().getName() + '.' + method.getName();
114 }
115
116
117
118
119 @Override
120 protected String itemTypeName() {
121 return "method";
122 }
123
124
125
126
127
128
129 public Class<Method[]> type() {
130 return Method[].class;
131 }
132
133
134
135
136
137
138
139 public Method[] valueFrom(String valueString) throws IllegalArgumentException {
140 return methodsFrom(valueString);
141 }
142 }