1 |
| package net.sourceforge.pmd.properties; |
2 |
| |
3 |
| import java.lang.reflect.Method; |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| public class MethodProperty extends AbstractPMDProperty { |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
0
| public MethodProperty(String theName, String theDescription, Object theDefault, float theUIOrder) {
|
18 |
0
| super(theName, theDescription, theDefault, theUIOrder);
|
19 |
| } |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
0
| public Class type() {
|
27 |
0
| return Method.class;
|
28 |
| } |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
37 |
0
| public Object valueFrom(String propertyString) throws IllegalArgumentException {
|
38 |
| |
39 |
0
| Class cls = classIn(propertyString);
|
40 |
0
| String methodName = methodNameIn(propertyString);
|
41 |
0
| Class[] parameterTypes = parameterTypesIn(propertyString);
|
42 |
| |
43 |
0
| try {
|
44 |
0
| return cls.getMethod(methodName, parameterTypes);
|
45 |
| } catch (Exception e) { |
46 |
0
| throw new IllegalArgumentException("invalid method: " + propertyString);
|
47 |
| } |
48 |
| } |
49 |
| |
50 |
0
| private Class classIn(String propertyString) throws IllegalArgumentException {
|
51 |
| |
52 |
0
| int dotPos = propertyString.lastIndexOf('.');
|
53 |
0
| String className = propertyString.substring(0, dotPos);
|
54 |
| |
55 |
0
| try {
|
56 |
0
| return Class.forName(className);
|
57 |
| } catch (Exception ex) { |
58 |
0
| throw new IllegalArgumentException("class not found: " + className);
|
59 |
| } |
60 |
| } |
61 |
| |
62 |
0
| private String methodNameIn(String propertyString) throws IllegalArgumentException {
|
63 |
| |
64 |
0
| int dotPos = propertyString.lastIndexOf('.');
|
65 |
0
| return propertyString.substring(dotPos);
|
66 |
| } |
67 |
| |
68 |
0
| private Class[] parameterTypesIn(String propertyString) {
|
69 |
0
| return null;
|
70 |
| } |
71 |
| } |