@Override @Nullable public MultiValueMap<String, Object> getAllAnnotationAttributes(String annotationName, boolean classValuesAsString) { return AnnotatedElementUtils.getAllAnnotationAttributes(this.introspectedMethod, annotationName, classValuesAsString, this.nestedAnnotationsAsMap); }
/** * Get the annotation attributes of <strong>all</strong> annotations of the specified * {@code annotationName} in the annotation hierarchy above the supplied * {@link AnnotatedElement} and store the results in a {@link MultiValueMap}. * <p>Note: in contrast to {@link #getMergedAnnotationAttributes(AnnotatedElement, String)}, * this method does <em>not</em> support attribute overrides. * <p>This method follows <em>get semantics</em> as described in the * {@linkplain AnnotatedElementUtils class-level javadoc}. * @param element the annotated element * @param annotationName the fully qualified class name of the annotation type to find * @return a {@link MultiValueMap} keyed by attribute name, containing the annotation * attributes from all annotations found, or {@code null} if not found * @see #getAllAnnotationAttributes(AnnotatedElement, String, boolean, boolean) */ @Nullable public static MultiValueMap<String, Object> getAllAnnotationAttributes(AnnotatedElement element, String annotationName) { return getAllAnnotationAttributes(element, annotationName, false, false); }
@Override @Nullable public MultiValueMap<String, Object> getAllAnnotationAttributes(String annotationName, boolean classValuesAsString) { return AnnotatedElementUtils.getAllAnnotationAttributes(this.introspectedMethod, annotationName, classValuesAsString, this.nestedAnnotationsAsMap); }
@Override @Nullable public MultiValueMap<String, Object> getAllAnnotationAttributes(String annotationName, boolean classValuesAsString) { return (this.annotations.length > 0 ? AnnotatedElementUtils.getAllAnnotationAttributes( getIntrospectedClass(), annotationName, classValuesAsString, this.nestedAnnotationsAsMap) : null); }
/** * Get the annotation attributes of <strong>all</strong> annotations of the specified * {@code annotationName} in the annotation hierarchy above the supplied * {@link AnnotatedElement} and store the results in a {@link MultiValueMap}. * <p>Note: in contrast to {@link #getMergedAnnotationAttributes(AnnotatedElement, String)}, * this method does <em>not</em> support attribute overrides. * <p>This method follows <em>get semantics</em> as described in the * {@linkplain AnnotatedElementUtils class-level javadoc}. * @param element the annotated element * @param annotationName the fully qualified class name of the annotation type to find * @return a {@link MultiValueMap} keyed by attribute name, containing the annotation * attributes from all annotations found, or {@code null} if not found * @see #getAllAnnotationAttributes(AnnotatedElement, String, boolean, boolean) */ @Nullable public static MultiValueMap<String, Object> getAllAnnotationAttributes(AnnotatedElement element, String annotationName) { return getAllAnnotationAttributes(element, annotationName, false, false); }
@Override @Nullable public MultiValueMap<String, Object> getAllAnnotationAttributes(String annotationName, boolean classValuesAsString) { return (this.annotations.length > 0 ? AnnotatedElementUtils.getAllAnnotationAttributes( getIntrospectedClass(), annotationName, classValuesAsString, this.nestedAnnotationsAsMap) : null); }
@Test public void getAllAnnotationAttributesOnNonAnnotatedClass() { assertNull(getAllAnnotationAttributes(NonAnnotatedClass.class, TX_NAME)); }
@Test public void getAllAnnotationAttributesOnClassWithLocalAnnotation() { MultiValueMap<String, Object> attributes = getAllAnnotationAttributes(TxConfig.class, TX_NAME); assertNotNull("Annotation attributes map for @Transactional on TxConfig", attributes); assertEquals("value for TxConfig.", asList("TxConfig"), attributes.get("value")); }
/** * Note: this functionality is required by {@link org.springframework.context.annotation.ProfileCondition}. * @see org.springframework.core.env.EnvironmentSystemIntegrationTests */ @Test public void getAllAnnotationAttributesOnClassWithMultipleComposedAnnotations() { MultiValueMap<String, Object> attributes = getAllAnnotationAttributes(TxFromMultipleComposedAnnotations.class, TX_NAME); assertNotNull("Annotation attributes map for @Transactional on TxFromMultipleComposedAnnotations", attributes); assertEquals("value for TxFromMultipleComposedAnnotations.", asList("TxInheritedComposed", "TxComposed"), attributes.get("value")); }
@Test public void getAllAnnotationAttributesFavorsInheritedAnnotationsOverMoreLocallyDeclaredComposedAnnotations() { MultiValueMap<String, Object> attributes = getAllAnnotationAttributes(SubSubClassWithInheritedAnnotation.class, TX_NAME); assertNotNull("Annotation attributes map for @Transactional on SubSubClassWithInheritedAnnotation", attributes); assertEquals(asList("transactionManager"), attributes.get("qualifier")); }
@Test public void getAllAnnotationAttributesFavorsInheritedComposedAnnotationsOverMoreLocallyDeclaredComposedAnnotations() { MultiValueMap<String, Object> attributes = getAllAnnotationAttributes( SubSubClassWithInheritedComposedAnnotation.class, TX_NAME); assertNotNull("Annotation attributes map for @Transactional on SubSubClassWithInheritedComposedAnnotation", attributes); assertEquals(asList("composed1"), attributes.get("qualifier")); }
@Test public void getAllAnnotationAttributesOnClassWithLocalComposedAnnotationAndInheritedAnnotation() { MultiValueMap<String, Object> attributes = getAllAnnotationAttributes(SubClassWithInheritedAnnotation.class, TX_NAME); assertNotNull("Annotation attributes map for @Transactional on SubClassWithInheritedAnnotation", attributes); assertEquals(asList("composed2", "transactionManager"), attributes.get("qualifier")); }
/** * If the "value" entry contains both "DerivedTxConfig" AND "TxConfig", then * the algorithm is accidentally picking up shadowed annotations of the same * type within the class hierarchy. Such undesirable behavior would cause the * logic in {@link org.springframework.context.annotation.ProfileCondition} * to fail. * @see org.springframework.core.env.EnvironmentSystemIntegrationTests#mostSpecificDerivedClassDrivesEnvironment_withDevEnvAndDerivedDevConfigClass */ @Test public void getAllAnnotationAttributesOnClassWithLocalAnnotationThatShadowsAnnotationFromSuperclass() { MultiValueMap<String, Object> attributes = getAllAnnotationAttributes(DerivedTxConfig.class, TX_NAME); assertNotNull("Annotation attributes map for @Transactional on DerivedTxConfig", attributes); assertEquals("value for DerivedTxConfig.", asList("DerivedTxConfig"), attributes.get("value")); }
@Override @Nullable public MultiValueMap<String, Object> getAllAnnotationAttributes(String annotationName, boolean classValuesAsString) { return AnnotatedElementUtils.getAllAnnotationAttributes(this.introspectedMethod, annotationName, classValuesAsString, this.nestedAnnotationsAsMap); }
@Override @Nullable public MultiValueMap<String, Object> getAllAnnotationAttributes(String annotationName, boolean classValuesAsString) { return AnnotatedElementUtils.getAllAnnotationAttributes(this.introspectedMethod, annotationName, classValuesAsString, this.nestedAnnotationsAsMap); }
/** * Get the annotation attributes of <strong>all</strong> annotations of the specified * {@code annotationName} in the annotation hierarchy above the supplied * {@link AnnotatedElement} and store the results in a {@link MultiValueMap}. * <p>Note: in contrast to {@link #getMergedAnnotationAttributes(AnnotatedElement, String)}, * this method does <em>not</em> support attribute overrides. * <p>This method follows <em>get semantics</em> as described in the * {@linkplain AnnotatedElementUtils class-level javadoc}. * @param element the annotated element * @param annotationName the fully qualified class name of the annotation type to find * @return a {@link MultiValueMap} keyed by attribute name, containing the annotation * attributes from all annotations found, or {@code null} if not found * @see #getAllAnnotationAttributes(AnnotatedElement, String, boolean, boolean) */ @Nullable public static MultiValueMap<String, Object> getAllAnnotationAttributes(AnnotatedElement element, String annotationName) { return getAllAnnotationAttributes(element, annotationName, false, false); }
/** * Get the annotation attributes of <strong>all</strong> annotations of the specified * {@code annotationName} in the annotation hierarchy above the supplied * {@link AnnotatedElement} and store the results in a {@link MultiValueMap}. * <p>Note: in contrast to {@link #getMergedAnnotationAttributes(AnnotatedElement, String)}, * this method does <em>not</em> support attribute overrides. * <p>This method follows <em>get semantics</em> as described in the * {@linkplain AnnotatedElementUtils class-level javadoc}. * @param element the annotated element * @param annotationName the fully qualified class name of the annotation type to find * @return a {@link MultiValueMap} keyed by attribute name, containing the annotation * attributes from all annotations found, or {@code null} if not found * @see #getAllAnnotationAttributes(AnnotatedElement, String, boolean, boolean) */ @Nullable public static MultiValueMap<String, Object> getAllAnnotationAttributes(AnnotatedElement element, String annotationName) { return getAllAnnotationAttributes(element, annotationName, false, false); }
@Override @Nullable public MultiValueMap<String, Object> getAllAnnotationAttributes(String annotationName, boolean classValuesAsString) { return (this.annotations.length > 0 ? AnnotatedElementUtils.getAllAnnotationAttributes( getIntrospectedClass(), annotationName, classValuesAsString, this.nestedAnnotationsAsMap) : null); }
@Override @Nullable public MultiValueMap<String, Object> getAllAnnotationAttributes(String annotationName, boolean classValuesAsString) { return (this.annotations.length > 0 ? AnnotatedElementUtils.getAllAnnotationAttributes( getIntrospectedClass(), annotationName, classValuesAsString, this.nestedAnnotationsAsMap) : null); }
@SuppressWarnings("unchecked") private static <T> boolean test(Annotation annotation, String metaAnnotationName, String attribute, Predicate<T> filter) { if (annotation.annotationType().getName().equals(metaAnnotationName)) { Map<String, Object> attributes = AnnotationUtils.getAnnotationAttributes(annotation); return !attributes.isEmpty() && filter.test((T) attributes.get(attribute)); } MultiValueMap<String, Object> attributes = AnnotatedElementUtils .getAllAnnotationAttributes(annotation.annotationType(), metaAnnotationName); if (attributes == null || attributes.isEmpty()) { return false; } List<Object> elementTypes = attributes.get(attribute); for (Object value : elementTypes) { if (filter.test((T) value)) { return true; } } return false; }