-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathAnnotatedMember.java
More file actions
144 lines (126 loc) · 4.45 KB
/
AnnotatedMember.java
File metadata and controls
144 lines (126 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package tools.jackson.databind.introspect;
import java.lang.annotation.Annotation;
import java.lang.reflect.Member;
import java.util.stream.Stream;
import tools.jackson.databind.util.ClassUtil;
/**
* Intermediate base class for annotated entities that are members of
* a class; fields, methods and constructors. This is a superset
* of things that can represent logical properties as it contains
* constructors in addition to fields and methods.
*/
public abstract class AnnotatedMember
extends Annotated
{
/**
* Context object needed for resolving generic type associated with this
* member (method parameter or return value, or field type).
*/
protected final TypeResolutionContext _typeContext;
protected final AnnotationMap _annotations;
protected AnnotatedMember(TypeResolutionContext ctxt, AnnotationMap annotations) {
super();
_typeContext = ctxt;
_annotations = annotations;
}
/**
* Copy-constructor.
*/
protected AnnotatedMember(AnnotatedMember base) {
_typeContext = base._typeContext;
_annotations = base._annotations;
}
/**
* Fluent factory method that will construct a new instance that uses specified
* instance annotations instead of currently configured ones.
*/
public abstract Annotated withAnnotations(AnnotationMap fallback);
/**
* Actual physical class in which this member was declared.
*/
public abstract Class<?> getDeclaringClass();
public abstract Member getMember();
public String getFullName() {
return getDeclaringClass().getName() + "#" + getName();
}
@Override
public final <A extends Annotation> A getAnnotation(Class<A> acls) {
if (_annotations == null) {
return null;
}
return _annotations.get(acls);
}
@Override
public final boolean hasAnnotation(Class<? extends Annotation> acls) {
if (_annotations == null) {
return false;
}
return _annotations.has(acls);
}
@Override
public boolean hasOneOf(Class<? extends Annotation>[] annoClasses) {
if (_annotations == null) {
return false;
}
return _annotations.hasOneOf(annoClasses);
}
@Override
public Stream<Annotation> annotations() {
if (_annotations == null) {
return Stream.empty();
}
return _annotations.values();
}
/**
* Method that can be called to modify access rights, by calling
* {@link java.lang.reflect.AccessibleObject#trySetAccessible} on
* the underlying annotated element.
*<p>
* Note that caller should verify that
* {@link tools.jackson.databind.MapperFeature#CAN_OVERRIDE_ACCESS_MODIFIERS}
* is enabled before calling this method; as well as pass
* <code>force</code> flag appropriately.
*/
public final void fixAccess(boolean force) {
Member m = getMember();
if (m != null) { // may be null for virtual members
ClassUtil.checkAndFixAccess(m, force);
}
}
/**
* Optional method that can be used to assign value of
* this member on given object, if this is a supported
* operation for member type.
*<p>
* This is implemented for fields and single-argument
* member methods; but not for constructor parameters or
* other types of methods (like static methods)
*/
public abstract void setValue(Object pojo, Object value)
throws UnsupportedOperationException, IllegalArgumentException;
/**
* Optional method that can be used to access the value of
* this member on given object, if this is a supported
* operation for member type.
*<p>
* This is implemented for fields and no-argument
* member methods; but not for constructor parameters or
* other types of methods (like static methods)
*/
public abstract Object getValue(Object pojo)
throws UnsupportedOperationException, IllegalArgumentException;
/**
* Internal method used by {@code POJOProperiesCollector} to
* merge annotations from this member with those from another
* member.
*<p>
* NOTE: NOT to be used by code outside jackson-databind (but has to be
* public to be accessible from POJOPropertiesCollector).
*
* @deprecated Not to be used by code outside jackson-databind.
*/
@Deprecated
public AnnotationMap _annotationMap() {
return _annotations;
}
}