226 public boolean isSynthetic() { 227 return Modifier.isSynthetic(getModifiers()); 228 } 229 230 /** 231 * Returns a {@code Class} object that identifies the 232 * declared type for the field represented by this 233 * {@code Field} object. 234 * 235 * @return a {@code Class} object identifying the declared 236 * type of the field represented by this object 237 */ 238 public Class<?> getType() { 239 return type; 240 } 241 242 /** 243 * Returns a {@code Type} object that represents the declared type for 244 * the field represented by this {@code Field} object. 245 * 246 * <p>If the {@code Type} is a parameterized type, the 247 * {@code Type} object returned must accurately reflect the 248 * actual type parameters used in the source code. 249 * 250 * <p>If the type of the underlying field is a type variable or a 251 * parameterized type, it is created. Otherwise, it is resolved. 252 * 253 * @return a {@code Type} object that represents the declared type for 254 * the field represented by this {@code Field} object 255 * @throws GenericSignatureFormatError if the generic field 256 * signature does not conform to the format specified in 257 * <cite>The Java™ Virtual Machine Specification</cite> 258 * @throws TypeNotPresentException if the generic type 259 * signature of the underlying field refers to a non-existent 260 * type declaration 261 * @throws MalformedParameterizedTypeException if the generic 262 * signature of the underlying field refers to a parameterized type 263 * that cannot be instantiated for any reason 264 * @since 1.5 265 */ 266 public Type getGenericType() { 267 if (getGenericSignature() != null) 268 return getGenericInfo().getGenericType(); 1117 1118 // Sets the FieldAccessor for this Field object and 1119 // (recursively) its root 1120 private void setFieldAccessor(FieldAccessor accessor, boolean overrideFinalCheck) { 1121 if (overrideFinalCheck) 1122 overrideFieldAccessor = accessor; 1123 else 1124 fieldAccessor = accessor; 1125 // Propagate up 1126 if (root != null) { 1127 root.setFieldAccessor(accessor, overrideFinalCheck); 1128 } 1129 } 1130 1131 @Override 1132 Field getRoot() { 1133 return root; 1134 } 1135 1136 /** 1137 * @throws NullPointerException {@inheritDoc} 1138 * @since 1.5 1139 */ 1140 public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { 1141 Objects.requireNonNull(annotationClass); 1142 return annotationClass.cast(declaredAnnotations().get(annotationClass)); 1143 } 1144 1145 /** 1146 * {@inheritDoc} 1147 * @throws NullPointerException {@inheritDoc} 1148 * @since 1.8 1149 */ 1150 @Override 1151 public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) { 1152 Objects.requireNonNull(annotationClass); 1153 1154 return AnnotationSupport.getDirectlyAndIndirectlyPresent(declaredAnnotations(), annotationClass); 1155 } 1156 1157 /** 1158 * {@inheritDoc} 1159 */ 1160 public Annotation[] getDeclaredAnnotations() { 1161 return AnnotationParser.toArray(declaredAnnotations()); 1162 } 1163 1164 private transient volatile Map<Class<? extends Annotation>, Annotation> declaredAnnotations; 1165 1166 private Map<Class<? extends Annotation>, Annotation> declaredAnnotations() { 1167 Map<Class<? extends Annotation>, Annotation> declAnnos; 1168 if ((declAnnos = declaredAnnotations) == null) { 1169 synchronized (this) { 1170 if ((declAnnos = declaredAnnotations) == null) { 1171 Field root = this.root; 1172 if (root != null) { 1173 declAnnos = root.declaredAnnotations(); 1174 } else { 1175 declAnnos = AnnotationParser.parseAnnotations( 1176 annotations, 1177 SharedSecrets.getJavaLangAccess() 1178 .getConstantPool(getDeclaringClass()), 1179 getDeclaringClass()); | 226 public boolean isSynthetic() { 227 return Modifier.isSynthetic(getModifiers()); 228 } 229 230 /** 231 * Returns a {@code Class} object that identifies the 232 * declared type for the field represented by this 233 * {@code Field} object. 234 * 235 * @return a {@code Class} object identifying the declared 236 * type of the field represented by this object 237 */ 238 public Class<?> getType() { 239 return type; 240 } 241 242 /** 243 * Returns a {@code Type} object that represents the declared type for 244 * the field represented by this {@code Field} object. 245 * 246 * <p>If the declared type of the field is a parameterized type, 247 * the {@code Type} object returned must accurately reflect the 248 * type arguments used in the source code. 249 * 250 * <p>If the type of the underlying field is a type variable or a 251 * parameterized type, it is created. Otherwise, it is resolved. 252 * 253 * @return a {@code Type} object that represents the declared type for 254 * the field represented by this {@code Field} object 255 * @throws GenericSignatureFormatError if the generic field 256 * signature does not conform to the format specified in 257 * <cite>The Java™ Virtual Machine Specification</cite> 258 * @throws TypeNotPresentException if the generic type 259 * signature of the underlying field refers to a non-existent 260 * type declaration 261 * @throws MalformedParameterizedTypeException if the generic 262 * signature of the underlying field refers to a parameterized type 263 * that cannot be instantiated for any reason 264 * @since 1.5 265 */ 266 public Type getGenericType() { 267 if (getGenericSignature() != null) 268 return getGenericInfo().getGenericType(); 1117 1118 // Sets the FieldAccessor for this Field object and 1119 // (recursively) its root 1120 private void setFieldAccessor(FieldAccessor accessor, boolean overrideFinalCheck) { 1121 if (overrideFinalCheck) 1122 overrideFieldAccessor = accessor; 1123 else 1124 fieldAccessor = accessor; 1125 // Propagate up 1126 if (root != null) { 1127 root.setFieldAccessor(accessor, overrideFinalCheck); 1128 } 1129 } 1130 1131 @Override 1132 Field getRoot() { 1133 return root; 1134 } 1135 1136 /** 1137 * {@inheritDoc} 1138 * @throws NullPointerException {@inheritDoc} 1139 * @since 1.5 1140 */ 1141 @Override 1142 public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { 1143 Objects.requireNonNull(annotationClass); 1144 return annotationClass.cast(declaredAnnotations().get(annotationClass)); 1145 } 1146 1147 /** 1148 * {@inheritDoc} 1149 * @throws NullPointerException {@inheritDoc} 1150 * @since 1.8 1151 */ 1152 @Override 1153 public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) { 1154 Objects.requireNonNull(annotationClass); 1155 1156 return AnnotationSupport.getDirectlyAndIndirectlyPresent(declaredAnnotations(), annotationClass); 1157 } 1158 1159 /** 1160 * {@inheritDoc} 1161 */ 1162 @Override 1163 public Annotation[] getDeclaredAnnotations() { 1164 return AnnotationParser.toArray(declaredAnnotations()); 1165 } 1166 1167 private transient volatile Map<Class<? extends Annotation>, Annotation> declaredAnnotations; 1168 1169 private Map<Class<? extends Annotation>, Annotation> declaredAnnotations() { 1170 Map<Class<? extends Annotation>, Annotation> declAnnos; 1171 if ((declAnnos = declaredAnnotations) == null) { 1172 synchronized (this) { 1173 if ((declAnnos = declaredAnnotations) == null) { 1174 Field root = this.root; 1175 if (root != null) { 1176 declAnnos = root.declaredAnnotations(); 1177 } else { 1178 declAnnos = AnnotationParser.parseAnnotations( 1179 annotations, 1180 SharedSecrets.getJavaLangAccess() 1181 .getConstantPool(getDeclaringClass()), 1182 getDeclaringClass()); |