Class AnnotationMetadata

java.lang.Object
be.imgn.inject.context.AnnotationMetadata

public final class AnnotationMetadata extends Object
The framework-related annotations captured at an injection point or provision definition: every annotation whose type carries InjectingAnnotation, QualifyingAnnotation, or ScopingAnnotation.

Annotations are held as AnnotationValue data computed at compile time, so inspection needs no reflection:

metadata.get(Named.class).flatMap(AnnotationValue::stringValue);      // by type
metadata.byStereotype(QualifyingAnnotation.class);                    // every qualifier at this site

At most one annotation per annotation type is held, matching the language rule for non-repeatable annotations.

  • Method Details

    • empty

      public static AnnotationMetadata empty()
      Returns the shared empty metadata instance.
      Returns:
      the shared empty metadata instance
    • of

      public static AnnotationMetadata of(AnnotationValue... annotations)
      Returns metadata holding annotations, keyed by annotation type.
      Parameters:
      annotations - the framework-related annotations present at the site; later entries win for a repeated type
      Returns:
      metadata holding annotations, keyed by annotation type
    • get

      public Optional<AnnotationValue> get(Class<? extends Annotation> type)
      Returns the annotation of type present at the site, if any.
      Parameters:
      type - the annotation type to look up
      Returns:
      the annotation of type present at the site, if any
    • isPresent

      public boolean isPresent(Class<? extends Annotation> type)
      Returns whether an annotation of type is present at the site.
      Parameters:
      type - the annotation type to test
      Returns:
      whether an annotation of type is present at the site
    • byStereotype

      public List<AnnotationValue> byStereotype(Class<? extends Annotation> stereotype)
      Returns every annotation at the site whose type carries stereotype.
      Parameters:
      stereotype - the meta-annotation to filter by, such as QualifyingAnnotation.class
      Returns:
      every annotation at the site whose type carries stereotype
    • hasStereotype

      public boolean hasStereotype(Class<? extends Annotation> stereotype)
      Returns whether any annotation at the site carries stereotype.
      Parameters:
      stereotype - the meta-annotation to test
      Returns:
      whether any annotation at the site carries stereotype
    • types

      public Set<Class<? extends Annotation>> types()
      Returns the annotation types present at the site.
      Returns:
      the annotation types present at the site
    • isEmpty

      public boolean isEmpty()
      Returns whether no framework-related annotation was present at the site.
      Returns:
      whether no framework-related annotation was present at the site
    • toString

      public String toString()
      Overrides:
      toString in class Object