64 private Class<?> clazz;
65 private int slot;
66 // This is guaranteed to be interned by the VM in the 1.4
67 // reflection implementation
68 private String name;
69 private Class<?> type;
70 private int modifiers;
71 // Generics and annotations support
72 private transient String signature;
73 // generic info repository; lazily initialized
74 private transient FieldRepository genericInfo;
75 private byte[] annotations;
76 // Cached field accessor created without override
77 private FieldAccessor fieldAccessor;
78 // Cached field accessor created with override
79 private FieldAccessor overrideFieldAccessor;
80 // For sharing of FieldAccessors. This branching structure is
81 // currently only two levels deep (i.e., one root Field and
82 // potentially many Field objects pointing to it.)
83 private Field root;
84 // This is set by the vm at Field creation
85 private byte[] typeAnnotations;
86
87 // Generics infrastructure
88
89 private String getGenericSignature() {return signature;}
90
91 // Accessor for factory
92 private GenericsFactory getFactory() {
93 Class<?> c = getDeclaringClass();
94 // create scope and factory
95 return CoreReflectionFactory.make(c, ClassScope.make(c));
96 }
97
98 // Accessor for generic info repository
99 private FieldRepository getGenericInfo() {
100 // lazily initialize repository if necessary
101 if (genericInfo == null) {
102 // create and cache generic info repository
103 genericInfo = FieldRepository.make(getGenericSignature(),
104 getFactory());
105 }
131
132 /**
133 * Package-private routine (exposed to java.lang.Class via
134 * ReflectAccess) which returns a copy of this Field. The copy's
135 * "root" field points to this Field.
136 */
137 Field copy() {
138 // This routine enables sharing of FieldAccessor objects
139 // among Field objects which refer to the same underlying
140 // method in the VM. (All of this contortion is only necessary
141 // because of the "accessibility" bit in AccessibleObject,
142 // which implicitly requires that new java.lang.reflect
143 // objects be fabricated for each reflective call on Class
144 // objects.)
145 Field res = new Field(clazz, name, type, modifiers, slot, signature, annotations);
146 res.root = this;
147 // Might as well eagerly propagate this if already present
148 res.fieldAccessor = fieldAccessor;
149 res.overrideFieldAccessor = overrideFieldAccessor;
150
151 res.typeAnnotations = typeAnnotations;
152 return res;
153 }
154
155 /**
156 * Returns the {@code Class} object representing the class or interface
157 * that declares the field represented by this {@code Field} object.
158 */
159 public Class<?> getDeclaringClass() {
160 return clazz;
161 }
162
163 /**
164 * Returns the name of the field represented by this {@code Field} object.
165 */
166 public String getName() {
167 return name;
168 }
169
170 /**
171 * Returns the Java language modifiers for the field represented
1038
1039 /**
1040 * {@inheritDoc}
1041 */
1042 public Annotation[] getDeclaredAnnotations() {
1043 return AnnotationParser.toArray(declaredAnnotations());
1044 }
1045
1046 private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
1047
1048 private synchronized Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
1049 if (declaredAnnotations == null) {
1050 declaredAnnotations = AnnotationParser.parseAnnotations(
1051 annotations, sun.misc.SharedSecrets.getJavaLangAccess().
1052 getConstantPool(getDeclaringClass()),
1053 getDeclaringClass());
1054 }
1055 return declaredAnnotations;
1056 }
1057
1058 /**
1059 * Returns an AnnotatedType object that represents the use of a type to specify
1060 * the declared type of the field represented by this Field.
1061 *
1062 * @since 1.8
1063 */
1064 public AnnotatedType getAnnotatedType() {
1065 return TypeAnnotationParser.buildAnnotatedType(typeAnnotations,
1066 sun.misc.SharedSecrets.getJavaLangAccess().
1067 getConstantPool(getDeclaringClass()),
1068 this,
1069 getDeclaringClass(),
1070 getGenericType(),
1071 TypeAnnotation.TypeAnnotationTarget.FIELD_TYPE);
1072 }
1073 }
|
64 private Class<?> clazz;
65 private int slot;
66 // This is guaranteed to be interned by the VM in the 1.4
67 // reflection implementation
68 private String name;
69 private Class<?> type;
70 private int modifiers;
71 // Generics and annotations support
72 private transient String signature;
73 // generic info repository; lazily initialized
74 private transient FieldRepository genericInfo;
75 private byte[] annotations;
76 // Cached field accessor created without override
77 private FieldAccessor fieldAccessor;
78 // Cached field accessor created with override
79 private FieldAccessor overrideFieldAccessor;
80 // For sharing of FieldAccessors. This branching structure is
81 // currently only two levels deep (i.e., one root Field and
82 // potentially many Field objects pointing to it.)
83 private Field root;
84
85 // Generics infrastructure
86
87 private String getGenericSignature() {return signature;}
88
89 // Accessor for factory
90 private GenericsFactory getFactory() {
91 Class<?> c = getDeclaringClass();
92 // create scope and factory
93 return CoreReflectionFactory.make(c, ClassScope.make(c));
94 }
95
96 // Accessor for generic info repository
97 private FieldRepository getGenericInfo() {
98 // lazily initialize repository if necessary
99 if (genericInfo == null) {
100 // create and cache generic info repository
101 genericInfo = FieldRepository.make(getGenericSignature(),
102 getFactory());
103 }
129
130 /**
131 * Package-private routine (exposed to java.lang.Class via
132 * ReflectAccess) which returns a copy of this Field. The copy's
133 * "root" field points to this Field.
134 */
135 Field copy() {
136 // This routine enables sharing of FieldAccessor objects
137 // among Field objects which refer to the same underlying
138 // method in the VM. (All of this contortion is only necessary
139 // because of the "accessibility" bit in AccessibleObject,
140 // which implicitly requires that new java.lang.reflect
141 // objects be fabricated for each reflective call on Class
142 // objects.)
143 Field res = new Field(clazz, name, type, modifiers, slot, signature, annotations);
144 res.root = this;
145 // Might as well eagerly propagate this if already present
146 res.fieldAccessor = fieldAccessor;
147 res.overrideFieldAccessor = overrideFieldAccessor;
148
149 return res;
150 }
151
152 /**
153 * Returns the {@code Class} object representing the class or interface
154 * that declares the field represented by this {@code Field} object.
155 */
156 public Class<?> getDeclaringClass() {
157 return clazz;
158 }
159
160 /**
161 * Returns the name of the field represented by this {@code Field} object.
162 */
163 public String getName() {
164 return name;
165 }
166
167 /**
168 * Returns the Java language modifiers for the field represented
1035
1036 /**
1037 * {@inheritDoc}
1038 */
1039 public Annotation[] getDeclaredAnnotations() {
1040 return AnnotationParser.toArray(declaredAnnotations());
1041 }
1042
1043 private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
1044
1045 private synchronized Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
1046 if (declaredAnnotations == null) {
1047 declaredAnnotations = AnnotationParser.parseAnnotations(
1048 annotations, sun.misc.SharedSecrets.getJavaLangAccess().
1049 getConstantPool(getDeclaringClass()),
1050 getDeclaringClass());
1051 }
1052 return declaredAnnotations;
1053 }
1054
1055 private native byte[] getTypeAnnotationBytes0();
1056
1057 /**
1058 * Returns an AnnotatedType object that represents the use of a type to specify
1059 * the declared type of the field represented by this Field.
1060 *
1061 * @since 1.8
1062 */
1063 public AnnotatedType getAnnotatedType() {
1064 return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes0(),
1065 sun.misc.SharedSecrets.getJavaLangAccess().
1066 getConstantPool(getDeclaringClass()),
1067 this,
1068 getDeclaringClass(),
1069 getGenericType(),
1070 TypeAnnotation.TypeAnnotationTarget.FIELD_TYPE);
1071 }
1072 }
|