| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -442,9 +442,9 @@ public void doWith(Method method) throws IllegalArgumentException, IllegalAccess | |||
| 442 | 442 | ||
| 443 | 443 | private AnnotationAttributes findAutowiredAnnotation(AccessibleObject ao) { | |
| 444 | 444 | for (Class<? extends Annotation> type : this.autowiredAnnotationTypes) { | |
| 445 | - AnnotationAttributes ann = AnnotatedElementUtils.getAnnotationAttributes(ao, type.getName()); | ||
| 446 | - if (ann != null) { | ||
| 447 | - return ann; | ||
| 445 | + AnnotationAttributes attributes = AnnotatedElementUtils.getAnnotationAttributes(ao, type); | ||
| 446 | + if (attributes != null) { | ||
| 447 | + return attributes; | ||
| 448 | 448 | } | |
| 449 | 449 | } | |
| 450 | 450 | return null; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -218,6 +218,31 @@ public Boolean process(AnnotatedElement annotatedElement, Annotation annotation, | |||
| 218 | 218 | })); | |
| 219 | 219 | } | |
| 220 | 220 | ||
| 221 | + /** | ||
| 222 | + * Get the first annotation of the specified {@code annotationType} within | ||
| 223 | + * the annotation hierarchy <em>above</em> the supplied {@code element} and | ||
| 224 | + * merge that annotation's attributes with <em>matching</em> attributes from | ||
| 225 | + * annotations in lower levels of the annotation hierarchy. | ||
| 226 | + * | ||
| 227 | + * <p>{@link AliasFor @AliasFor} semantics are fully supported, both | ||
| 228 | + * within a single annotation and within the annotation hierarchy. | ||
| 229 | + * | ||
| 230 | + * <p>This method delegates to {@link #getAnnotationAttributes(AnnotatedElement, String)}. | ||
| 231 | + * | ||
| 232 | + * @param element the annotated element; never {@code null} | ||
| 233 | + * @param annotationType the annotation type to find; never {@code null} | ||
| 234 | + * @return the merged {@code AnnotationAttributes}, or {@code null} if not found | ||
| 235 | + * @see #getAnnotationAttributes(AnnotatedElement, String, boolean, boolean) | ||
| 236 | + * @see #getAllAnnotationAttributes(AnnotatedElement, String) | ||
| 237 | + * @see #findAnnotationAttributes(AnnotatedElement, String, boolean, boolean) | ||
| 238 | + * @see #findAnnotation(AnnotatedElement, Class) | ||
| 239 | + */ | ||
| 240 | + public static AnnotationAttributes getAnnotationAttributes(AnnotatedElement element, | ||
| 241 | + Class<? extends Annotation> annotationType) { | ||
| 242 | + Assert.notNull(annotationType, "annotationType must not be null"); | ||
| 243 | + return getAnnotationAttributes(element, annotationType.getName()); | ||
| 244 | + } | ||
| 245 | + | ||
| 221 | 246 | /** | |
| 222 | 247 | * Get the first annotation of the specified {@code annotationType} within | |
| 223 | 248 | * the annotation hierarchy <em>above</em> the supplied {@code element} and | |
@@ -298,17 +323,15 @@ public static AnnotationAttributes getAnnotationAttributes(AnnotatedElement elem | |||
| 298 | 323 | * <p>{@link AliasFor @AliasFor} semantics are fully supported, both | |
| 299 | 324 | * within a single annotation and within the annotation hierarchy. | |
| 300 | 325 | * | |
| 301 | - * <p>This method delegates to {@link #findAnnotationAttributes(AnnotatedElement, String, boolean, boolean)} | ||
| 302 | - * (supplying {@code false} for {@code classValuesAsString} and {@code nestedAnnotationsAsMap}) | ||
| 303 | - * and {@link AnnotationUtils#synthesizeAnnotation(Map, Class, AnnotatedElement)}. | ||
| 326 | + * <p>This method delegates to {@link #findAnnotation(AnnotatedElement, String)}. | ||
| 304 | 327 | * | |
| 305 | 328 | * @param element the annotated element; never {@code null} | |
| 306 | 329 | * @param annotationType the annotation type to find; never {@code null} | |
| 307 | 330 | * @return the merged, synthesized {@code Annotation}, or {@code null} if not found | |
| 308 | 331 | * @since 4.2 | |
| 309 | 332 | * @see #findAnnotation(AnnotatedElement, String) | |
| 310 | 333 | * @see #findAnnotationAttributes(AnnotatedElement, String, boolean, boolean) | |
| 311 | - * @see AnnotationUtils#synthesizeAnnotation(Map, Class, AnnotatedElement) | ||
| 334 | + * @see #getAnnotationAttributes(AnnotatedElement, Class) | ||
| 312 | 335 | */ | |
| 313 | 336 | public static <A extends Annotation> A findAnnotation(AnnotatedElement element, Class<A> annotationType) { | |
| 314 | 337 | Assert.notNull(annotationType, "annotationType must not be null"); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -325,30 +325,26 @@ public void getAnnotationAttributesWithAliasedValueComposedAnnotation() { | |||
| 325 | 325 | @Test | |
| 326 | 326 | public void getAnnotationAttributesWithInvalidConventionBasedComposedAnnotation() { | |
| 327 | 327 | Class<?> element = InvalidConventionBasedComposedContextConfigClass.class; | |
| 328 | - String name = ContextConfig.class.getName(); | ||
| 329 | - | ||
| 330 | 328 | exception.expect(AnnotationConfigurationException.class); | |
| 331 | 329 | exception.expectMessage(either(containsString("attribute [value] and its alias [locations]")).or( | |
| 332 | 330 | containsString("attribute [locations] and its alias [value]"))); | |
| 333 | 331 | exception.expectMessage(either( | |
| 334 | 332 | containsString("values of [{duplicateDeclaration}] and [{requiredLocationsDeclaration}]")).or( | |
| 335 | 333 | containsString("values of [{requiredLocationsDeclaration}] and [{duplicateDeclaration}]"))); | |
| 336 | 334 | exception.expectMessage(containsString("but only one declaration is permitted")); | |
| 337 | - getAnnotationAttributes(element, name); | ||
| 335 | + getAnnotationAttributes(element, ContextConfig.class); | ||
| 338 | 336 | } | |
| 339 | 337 | ||
| 340 | 338 | @Test | |
| 341 | 339 | public void getAnnotationAttributesWithInvalidAliasedComposedAnnotation() { | |
| 342 | 340 | Class<?> element = InvalidAliasedComposedContextConfigClass.class; | |
| 343 | - String name = ContextConfig.class.getName(); | ||
| 344 | - | ||
| 345 | 341 | exception.expect(AnnotationConfigurationException.class); | |
| 346 | 342 | exception.expectMessage(either(containsString("attribute [value] and its alias [locations]")).or( | |
| 347 | 343 | containsString("attribute [locations] and its alias [value]"))); | |
| 348 | 344 | exception.expectMessage(either(containsString("values of [{duplicateDeclaration}] and [{test.xml}]")).or( | |
| 349 | 345 | containsString("values of [{test.xml}] and [{duplicateDeclaration}]"))); | |
| 350 | 346 | exception.expectMessage(containsString("but only one declaration is permitted")); | |
| 351 | - getAnnotationAttributes(element, name); | ||
| 347 | + getAnnotationAttributes(element, ContextConfig.class); | ||
| 352 | 348 | } | |
| 353 | 349 | ||
| 354 | 350 | @Test | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,9 +39,9 @@ public class JtaTransactionAnnotationParser implements TransactionAnnotationPars | |||
| 39 | 39 | ||
| 40 | 40 | @Override | |
| 41 | 41 | public TransactionAttribute parseTransactionAnnotation(AnnotatedElement ae) { | |
| 42 | - AnnotationAttributes ann = AnnotatedElementUtils.getAnnotationAttributes(ae, javax.transaction.Transactional.class.getName()); | ||
| 43 | - if (ann != null) { | ||
| 44 | - return parseTransactionAnnotation(ann); | ||
| 42 | + AnnotationAttributes attributes = AnnotatedElementUtils.getAnnotationAttributes(ae, javax.transaction.Transactional.class); | ||
| 43 | + if (attributes != null) { | ||
| 44 | + return parseTransactionAnnotation(attributes); | ||
| 45 | 45 | } | |
| 46 | 46 | else { | |
| 47 | 47 | return null; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,9 +39,9 @@ public class SpringTransactionAnnotationParser implements TransactionAnnotationP | |||
| 39 | 39 | ||
| 40 | 40 | @Override | |
| 41 | 41 | public TransactionAttribute parseTransactionAnnotation(AnnotatedElement ae) { | |
| 42 | - AnnotationAttributes ann = AnnotatedElementUtils.getAnnotationAttributes(ae, Transactional.class.getName()); | ||
| 43 | - if (ann != null) { | ||
| 44 | - return parseTransactionAnnotation(ann); | ||
| 42 | + AnnotationAttributes attributes = AnnotatedElementUtils.getAnnotationAttributes(ae, Transactional.class); | ||
| 43 | + if (attributes != null) { | ||
| 44 | + return parseTransactionAnnotation(attributes); | ||
| 45 | 45 | } | |
| 46 | 46 | else { | |
| 47 | 47 | return null; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments