1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.apache.commons.clazz.reflect.common; |
17 | |
|
18 | |
import java.lang.reflect.Method; |
19 | |
|
20 | |
import org.apache.commons.clazz.Clazz; |
21 | |
import org.apache.commons.clazz.ClazzFeature; |
22 | |
import org.apache.commons.clazz.ClazzLoader; |
23 | |
import org.apache.commons.clazz.common.ClazzFeatureSupport; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
public class ReflectedMethodFeatureSupport extends ClazzFeatureSupport |
32 | |
implements ClazzFeature |
33 | |
{ |
34 | |
private Method method; |
35 | |
private String signature; |
36 | 0 | private static final Clazz[] EMPTY_CLAZZ_ARRAY = new Clazz[0]; |
37 | |
private Clazz[] parameterClazzes; |
38 | 0 | private boolean returnClazzCached = false; |
39 | |
private Clazz returnClazz; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
public ReflectedMethodFeatureSupport(Clazz declaringClazz, Method method) { |
45 | 0 | super(declaringClazz); |
46 | 0 | this.method = method; |
47 | 0 | } |
48 | |
|
49 | |
public Method getMethod() { |
50 | 0 | return method; |
51 | |
} |
52 | |
|
53 | |
public String getName() { |
54 | 0 | return method.getName(); |
55 | |
} |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
public String getSignature() { |
61 | 0 | if (signature == null) { |
62 | 0 | signature = |
63 | |
Clazz.constructSignature( |
64 | |
method.getName(), |
65 | |
method.getParameterTypes()); |
66 | |
} |
67 | 0 | return signature; |
68 | |
} |
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
public Clazz[] getParameterClazzes() { |
74 | 0 | if (parameterClazzes == null) { |
75 | 0 | Class paramClasses[] = method.getParameterTypes(); |
76 | 0 | if (paramClasses == null) { |
77 | 0 | parameterClazzes = EMPTY_CLAZZ_ARRAY; |
78 | |
} |
79 | |
else { |
80 | 0 | parameterClazzes = new Clazz[paramClasses.length]; |
81 | 0 | ClazzLoader loader = getDeclaringClazz().getClazzLoader(); |
82 | 0 | for (int i = 0; i < paramClasses.length; i++) { |
83 | 0 | String name = Clazz.getCanonicalClassName(paramClasses[i]); |
84 | 0 | parameterClazzes[i] = loader.getClazzForName(name); |
85 | |
} |
86 | |
} |
87 | |
} |
88 | 0 | return parameterClazzes; |
89 | |
} |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
public Clazz getReturnClazz() { |
95 | 0 | if (!returnClazzCached) { |
96 | 0 | returnClazzCached = true; |
97 | 0 | Class returnType = method.getReturnType(); |
98 | 0 | if (returnType == null || returnType.equals(Void.TYPE)) { |
99 | 0 | returnClazz = null; |
100 | |
} |
101 | |
else { |
102 | 0 | ClazzLoader loader = getDeclaringClazz().getClazzLoader(); |
103 | 0 | returnClazz = loader.getClazzForName(returnType.getName()); |
104 | |
} |
105 | |
} |
106 | 0 | return returnClazz; |
107 | |
} |
108 | |
|
109 | |
public String toString() { |
110 | 0 | return getSignature(); |
111 | |
} |
112 | |
} |