1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package jp.liq.container.reflect;
17
18 import java.lang.annotation.Annotation;
19 import java.lang.reflect.Method;
20
21
22
23
24
25
26 public class MethodWrapper extends ParameterizedMember {
27 private final Method method;
28
29 public MethodWrapper(Method method) {
30 this.method = method;
31 }
32
33
34
35
36 public String name() {
37 return method.getName();
38 }
39
40
41
42 public java.lang.reflect.Method getMethod() {
43 return method;
44 }
45
46
47
48
49
50
51
52 public <T> ObjectFactory<T> createObjectFactory(final Object target, final Class<T> type) {
53 final MethodWrapper m = this;
54
55
56 return new ObjectFactory<T>() {
57
58 public T createObject(Object[] args) throws ReflectException {
59 return type.cast(m.invoke(target, args));
60 }
61 };
62 }
63
64
65
66
67 public Object invoke(Object target, Object[] args) throws ReflectException {
68 try {
69 return method.invoke(target, args);
70 } catch (Exception e) {
71 throw new ReflectException(e, this,
72 ReflectException.Reason.FAILED_TO_INVOKE_METHOD);
73 }
74 }
75
76
77
78
79 public boolean isAnnotationPresent(Class<? extends Annotation> ann) {
80 return method.getAnnotation(ann) != null;
81 }
82
83
84
85 public boolean equals(Object o) {
86 return method.equals(o);
87 }
88
89
90
91 public int hashCode() {
92 return method.hashCode();
93 }
94
95
96
97
98 public String toString() {
99 return method.toString();
100 }
101
102
103
104
105 public Annotation[][] getParameterAnnotations() {
106 return method.getParameterAnnotations();
107 }
108
109
110
111
112 public Class<?>[] getParameterTypes() {
113 return method.getParameterTypes();
114 }
115
116
117
118
119 @Override
120 public int getModifiers() {
121 return method.getModifiers();
122 }
123 }