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.Field;
20
21 import jp.liq.container.reflect.ReflectException.Reason;
22
23
24
25
26
27 public class FieldWrapper extends Member {
28 private final Field field;
29
30
31
32
33
34 public FieldWrapper(Field field) {
35 this.field = field;
36 }
37
38
39
40
41 public Field getField() {
42 return this.field;
43 }
44
45
46
47
48
49
50
51 public void set(Object target, Object value) throws ReflectException {
52 try {
53 field.set(target, value);
54 } catch (Exception e) {
55 throw new ReflectException(e, this, Reason.FAILED_TO_SET_FIELD);
56 }
57 }
58
59
60
61
62
63
64 public Object get(Object target) throws ReflectException {
65 try {
66 return field.get(target);
67 } catch (Exception e) {
68 throw new ReflectException(e, this, Reason.FAILED_TO_GET_FIELD);
69 }
70 }
71
72
73
74
75 public String name() {
76 return field.getName();
77 }
78
79
80
81
82 public boolean isAnnotationPresent(Class<? extends Annotation> ann) {
83 return field.getAnnotation(ann) != null;
84 }
85
86
87
88
89 public String toString() {
90 return field.toString();
91 }
92
93
94
95
96 @Override
97 protected int getModifiers() {
98 return field.getModifiers();
99 }
100
101 }