Class AnnotationUtils

java.lang.Object
org.apache.dubbo.config.spring.util.AnnotationUtils

public abstract class AnnotationUtils extends Object
Annotation Utilities
Since:
2017.01.13
Author:
Mercy
See Also:
  • Field Details

    • ANNOTATED_ELEMENT_UTILS_CLASS_NAME

      public static final String ANNOTATED_ELEMENT_UTILS_CLASS_NAME
      The class name of AnnotatedElementUtils that is introduced since Spring Framework 4
      See Also:
  • Constructor Details

    • AnnotationUtils

      public AnnotationUtils()
  • Method Details

    • isPresent

      public static <A extends Annotation> boolean isPresent(Method method, Class<A> annotationClass)
      Is specified Annotation present on Method's declaring class or parameters or itself.
      Type Parameters:
      A - Annotation type
      Parameters:
      method - Method
      annotationClass - Annotation type
      Returns:
      If present , return true , or false
    • findAnnotations

      public static <A extends Annotation> Map<ElementType,List<A>> findAnnotations(Method method, Class<A> annotationClass)
      Find specified Annotation type maps from Method
      Type Parameters:
      A - Annotation type
      Parameters:
      method - Method
      annotationClass - Annotation type
      Returns:
      Annotation type maps , the ElementType as key , the list of Annotation as value. If Annotation was annotated on Method's parametersElementType.PARAMETER , the associated Annotation list may contain multiple elements.
    • getAttributes

      public static Map<String,Object> getAttributes(Annotation annotation, boolean ignoreDefaultValue, String... ignoreAttributeNames)
      Get the Annotation attributes
      Parameters:
      annotation - specified Annotation
      ignoreDefaultValue - whether ignore default value or not
      ignoreAttributeNames - the attribute names of annotation should be ignored
      Returns:
      non-null
      Since:
      1.0.2
    • getAttributes

      public static Map<String,Object> getAttributes(Annotation annotation, org.springframework.core.env.PropertyResolver propertyResolver, boolean ignoreDefaultValue, String... ignoreAttributeNames)
      Get the Annotation attributes
      Parameters:
      annotation - specified Annotation
      propertyResolver - PropertyResolver instance, e.g Environment
      ignoreDefaultValue - whether ignore default value or not
      ignoreAttributeNames - the attribute names of annotation should be ignored
      Returns:
      non-null
      Since:
      1.0.2
    • getAttributes

      public static Map<String,Object> getAttributes(Map<String,Object> annotationAttributes, org.springframework.core.env.PropertyResolver propertyResolver, String... ignoreAttributeNames)
      Get the Annotation attributes
      Parameters:
      annotationAttributes - the attributes of specified Annotation
      propertyResolver - PropertyResolver instance, e.g Environment
      ignoreAttributeNames - the attribute names of annotation should be ignored
      Returns:
      non-null
      Since:
      1.0.4
    • getAttributes

      public static Map<String,Object> getAttributes(Annotation annotation, org.springframework.core.env.PropertyResolver propertyResolver, boolean classValuesAsString, boolean nestedAnnotationsAsMap, boolean ignoreDefaultValue, String... ignoreAttributeNames)
      Parameters:
      annotation - specified Annotation
      propertyResolver - PropertyResolver instance, e.g Environment
      classValuesAsString - whether to turn Class references into Strings (for compatibility with AnnotationMetadata or to preserve them as Class references
      nestedAnnotationsAsMap - whether to turn nested Annotation instances into AnnotationAttributes maps (for compatibility with AnnotationMetadata or to preserve them as Annotation instances
      ignoreDefaultValue - whether ignore default value or not
      ignoreAttributeNames - the attribute names of annotation should be ignored
      Returns:
      Since:
      1.0.11
    • getAttribute

      public static <T> T getAttribute(Annotation annotation, String attributeName)
      Get the attribute value
      Type Parameters:
      T - the type of attribute value
      Parameters:
      annotation - annotation
      attributeName - the name of attribute
      Returns:
      the attribute value if found
      Since:
      1.0.3
    • getAttribute

      public static <T> T getAttribute(Map<String,Object> attributes, String attributeName)
      Get the attribute value
      Type Parameters:
      T - the type of attribute value
      Parameters:
      attributes - the annotation attributes or AnnotationAttributes
      attributeName - the name of attribute
      Returns:
      the attribute value if found
      Since:
      1.0.3
    • getAttribute

      public static <T> T getAttribute(Map<String,Object> attributes, String attributeName, boolean required)
      Get the attribute value the will
      Type Parameters:
      T - the type of attribute value
      Parameters:
      attributes - the annotation attributes or AnnotationAttributes
      attributeName - the name of attribute
      required - the required attribute or not
      Returns:
      the attribute value if found
      Throws:
      IllegalStateException - if attribute value can't be found
      Since:
      1.0.6
    • getAttribute

      public static <T> T getAttribute(Map<String,Object> attributes, String attributeName, T defaultValue)
      Get the attribute value with default value
      Type Parameters:
      T - the type of attribute value
      Parameters:
      attributes - the annotation attributes or AnnotationAttributes
      attributeName - the name of attribute
      defaultValue - the default value of attribute
      Returns:
      the attribute value if found
      Since:
      1.0.6
    • getRequiredAttribute

      public static <T> T getRequiredAttribute(Map<String,Object> attributes, String attributeName)
      Get the required attribute value
      Type Parameters:
      T - the type of attribute value
      Parameters:
      attributes - the annotation attributes or AnnotationAttributes
      attributeName - the name of attribute
      Returns:
      the attribute value if found
      Throws:
      IllegalStateException - if attribute value can't be found
      Since:
      1.0.6
    • getAnnotationAttributes

      public static org.springframework.core.annotation.AnnotationAttributes getAnnotationAttributes(Annotation annotation, boolean ignoreDefaultValue, String... ignoreAttributeNames)
      Get the AnnotationAttributes
      Parameters:
      annotation - specified Annotation
      ignoreDefaultValue - whether ignore default value or not
      ignoreAttributeNames - the attribute names of annotation should be ignored
      Returns:
      non-null
      Since:
      1.0.3
      See Also:
    • getAnnotationAttributes

      public static org.springframework.core.annotation.AnnotationAttributes getAnnotationAttributes(Annotation annotation, org.springframework.core.env.PropertyResolver propertyResolver, boolean classValuesAsString, boolean nestedAnnotationsAsMap, boolean ignoreDefaultValue, String... ignoreAttributeNames)
      Get the AnnotationAttributes
      Parameters:
      annotation - specified Annotation
      propertyResolver - PropertyResolver instance, e.g Environment
      classValuesAsString - whether to turn Class references into Strings (for compatibility with AnnotationMetadata or to preserve them as Class references
      nestedAnnotationsAsMap - whether to turn nested Annotation instances into AnnotationAttributes maps (for compatibility with AnnotationMetadata or to preserve them as Annotation instances
      ignoreDefaultValue - whether ignore default value or not
      ignoreAttributeNames - the attribute names of annotation should be ignored
      Returns:
      non-null
      Since:
      1.0.11
      See Also:
    • getAnnotationAttributes

      public static org.springframework.core.annotation.AnnotationAttributes getAnnotationAttributes(Annotation annotation, org.springframework.core.env.PropertyResolver propertyResolver, boolean ignoreDefaultValue, String... ignoreAttributeNames)
      Get the AnnotationAttributes
      Parameters:
      annotation - specified Annotation
      propertyResolver - PropertyResolver instance, e.g Environment
      ignoreDefaultValue - whether ignore default value or not
      ignoreAttributeNames - the attribute names of annotation should be ignored
      Returns:
      non-null
      Since:
      1.0.3
      See Also:
    • getAnnotationAttributes

      public static org.springframework.core.annotation.AnnotationAttributes getAnnotationAttributes(AnnotatedElement annotatedElement, Class<? extends Annotation> annotationType, org.springframework.core.env.PropertyResolver propertyResolver, boolean ignoreDefaultValue, String... ignoreAttributeNames)
      Get the AnnotationAttributes
      Parameters:
      annotatedElement - the annotated element
      annotationType - the tyoe pf annotation
      propertyResolver - PropertyResolver instance, e.g Environment
      ignoreDefaultValue - whether ignore default value or not
      ignoreAttributeNames - the attribute names of annotation should be ignored
      Returns:
      if annotatedElement can't be found in annotatedElement, return null
      Since:
      1.0.3
    • getAnnotationAttributes

      public static org.springframework.core.annotation.AnnotationAttributes getAnnotationAttributes(AnnotatedElement annotatedElement, Class<? extends Annotation> annotationType, org.springframework.core.env.PropertyResolver propertyResolver, boolean classValuesAsString, boolean nestedAnnotationsAsMap, boolean ignoreDefaultValue, String... ignoreAttributeNames)
      Get the AnnotationAttributes
      Parameters:
      annotatedElement - the annotated element
      annotationType - the tyoe pf annotation
      propertyResolver - PropertyResolver instance, e.g Environment
      ignoreDefaultValue - whether ignore default value or not
      ignoreAttributeNames - the attribute names of annotation should be ignored
      Returns:
      if annotatedElement can't be found in annotatedElement, return null
      Since:
      1.0.11
    • getAnnotationAttributes

      public static org.springframework.core.annotation.AnnotationAttributes getAnnotationAttributes(AnnotatedElement annotatedElement, Class<? extends Annotation> annotationType, org.springframework.core.env.PropertyResolver propertyResolver, boolean ignoreDefaultValue, boolean tryMergedAnnotation, String... ignoreAttributeNames)
      Get the AnnotationAttributes, if the argument tryMergedAnnotation is true, the AnnotationAttributes will be got from merged annotation first, if failed, and then to get from normal one
      Parameters:
      annotatedElement - the annotated element
      annotationType - the tyoe pf annotation
      propertyResolver - PropertyResolver instance, e.g Environment
      ignoreDefaultValue - whether ignore default value or not
      tryMergedAnnotation - whether try merged annotation or not
      ignoreAttributeNames - the attribute names of annotation should be ignored
      Returns:
      if annotatedElement can't be found in annotatedElement, return null
      Since:
      1.0.3
    • getAnnotationAttributes

      public static org.springframework.core.annotation.AnnotationAttributes getAnnotationAttributes(AnnotatedElement annotatedElement, Class<? extends Annotation> annotationType, org.springframework.core.env.PropertyResolver propertyResolver, boolean classValuesAsString, boolean nestedAnnotationsAsMap, boolean ignoreDefaultValue, boolean tryMergedAnnotation, String... ignoreAttributeNames)
      Get the AnnotationAttributes, if the argument tryMergedAnnotation is true, the AnnotationAttributes will be got from merged annotation first, if failed, and then to get from normal one
      Parameters:
      annotatedElement - the annotated element
      annotationType - the tyoe pf annotation
      propertyResolver - PropertyResolver instance, e.g Environment
      classValuesAsString - whether to turn Class references into Strings (for compatibility with AnnotationMetadata or to preserve them as Class references
      nestedAnnotationsAsMap - whether to turn nested Annotation instances into AnnotationAttributes maps (for compatibility with AnnotationMetadata or to preserve them as Annotation instances
      ignoreDefaultValue - whether ignore default value or not
      tryMergedAnnotation - whether try merged annotation or not
      ignoreAttributeNames - the attribute names of annotation should be ignored
      Returns:
      if annotatedElement can't be found in annotatedElement, return null
      Since:
      1.0.11
    • tryGetMergedAnnotation

      public static Annotation tryGetMergedAnnotation(AnnotatedElement annotatedElement, Class<? extends Annotation> annotationType)
      Try to get the merged annotation
      Parameters:
      annotatedElement - the annotated element
      annotationType - the tyoe pf annotation
      Returns:
      If current version of Spring Framework is below 4.2, return null
      Since:
      1.0.3
    • tryGetMergedAnnotation

      public static Annotation tryGetMergedAnnotation(AnnotatedElement annotatedElement, Class<? extends Annotation> annotationType, boolean classValuesAsString, boolean nestedAnnotationsAsMap)
      Try to get the merged annotation
      Parameters:
      annotatedElement - the annotated element
      annotationType - the tyoe pf annotation
      classValuesAsString - whether to turn Class references into Strings (for compatibility with AnnotationMetadata or to preserve them as Class references
      nestedAnnotationsAsMap - whether to turn nested Annotation instances into AnnotationAttributes maps (for compatibility with AnnotationMetadata or to preserve them as Annotation instances
      Returns:
      If current version of Spring Framework is below 4.2, return null
      Since:
      1.0.11
    • tryGetMergedAnnotationAttributes

      public static org.springframework.core.annotation.AnnotationAttributes tryGetMergedAnnotationAttributes(AnnotatedElement annotatedElement, Class<? extends Annotation> annotationType, org.springframework.core.env.PropertyResolver propertyResolver, boolean ignoreDefaultValue, String... ignoreAttributeNames)
      Try to get the annotation attributes after merging and resolving the placeholders
      Parameters:
      annotatedElement - the annotated element
      annotationType - the tyoe pf annotation
      propertyResolver - PropertyResolver instance, e.g Environment
      ignoreDefaultValue - whether ignore default value or not
      ignoreAttributeNames - the attribute names of annotation should be ignored
      Returns:
      If the specified annotation type is not found, return null
      Since:
      1.0.3
    • tryGetMergedAnnotationAttributes

      public static org.springframework.core.annotation.AnnotationAttributes tryGetMergedAnnotationAttributes(AnnotatedElement annotatedElement, Class<? extends Annotation> annotationType, org.springframework.core.env.PropertyResolver propertyResolver, boolean classValuesAsString, boolean nestedAnnotationsAsMap, boolean ignoreDefaultValue, String... ignoreAttributeNames)
      Try to get the annotation attributes after merging and resolving the placeholders
      Parameters:
      annotatedElement - the annotated element
      annotationType - the tyoe pf annotation
      propertyResolver - PropertyResolver instance, e.g Environment
      classValuesAsString - whether to turn Class references into Strings (for compatibility with AnnotationMetadata or to preserve them as Class references
      nestedAnnotationsAsMap - whether to turn nested Annotation instances into AnnotationAttributes maps (for compatibility with AnnotationMetadata or to preserve them as Annotation instances
      ignoreDefaultValue - whether ignore default value or not
      ignoreAttributeNames - the attribute names of annotation should be ignored
      Returns:
      If the specified annotation type is not found, return null
      Since:
      1.0.11