Class Qualifiers

java.lang.Object
io.micronaut.inject.qualifiers.Qualifiers

public class Qualifiers extends Object
Factory for Bean qualifiers.
Since:
1.0
Author:
Graeme Rocher
  • Constructor Details

    • Qualifiers

      public Qualifiers()
  • Method Details

    • any

      public static <T> Qualifier<T> any()
      Allows looking up the first matching instance.

      This qualifier results on NonUniqueBeanException never being thrown as the first matching instance will be returned.

      Type Parameters:
      T - The generic type
      Returns:
      The any qualifier.
      Since:
      3.0.0
      See Also:
    • none

      public static <T> Qualifier<T> none()
      Allows looking up for beans without any qualifier.
      Type Parameters:
      T - The generic type
      Returns:
      The none qualifier.
      Since:
      3.8.0
    • forArgument

      @Nullable public static <T> @Nullable Qualifier<T> forArgument(@NonNull @NonNull Argument<?> argument)
      Build a qualifier for the given argument.
      Type Parameters:
      T - The type
      Parameters:
      argument - The argument
      Returns:
      The resolved qualifier
    • byQualifiers

      public static <T> Qualifier<T> byQualifiers(Qualifier<T>... qualifiers)
      Build a qualifier from other qualifiers.
      Type Parameters:
      T - The component type
      Parameters:
      qualifiers - The qualifiers
      Returns:
      The qualifier
    • byName

      public static <T> Qualifier<T> byName(String name)
      Build a qualifier for the given name.
      Type Parameters:
      T - The component type
      Parameters:
      name - The name
      Returns:
      The qualifier
    • findName

      @Nullable public static @Nullable String findName(@NonNull @NonNull Qualifier<?> qualifier)
      Finds a name in the provided qualifier.
      Returns:
      The qualifier
      Since:
      4.0.0
    • byNamePrefix

      public static <T> Qualifier<T> byNamePrefix(String prefix)
      Qualify by a prefix. Applies starting with logic to the name of the bean..
      Type Parameters:
      T - The component type
      Parameters:
      prefix - The name
      Returns:
      The qualifier
      Since:
      4.0.0
    • byAnnotation

      public static <T> Qualifier<T> byAnnotation(Annotation annotation)
      Build a qualifier for the given annotation.
      Type Parameters:
      T - The component type
      Parameters:
      annotation - The annotation
      Returns:
      The qualifier
    • byAnnotation

      public static <T> Qualifier<T> byAnnotation(AnnotationMetadata metadata, Class<? extends Annotation> type)
      Build a qualifier for the given annotation.
      Type Parameters:
      T - The component type
      Parameters:
      metadata - The metadata
      type - The annotation type
      Returns:
      The qualifier
    • byAnnotation

      public static <T> Qualifier<T> byAnnotation(AnnotationMetadata metadata, String type)

      Build a qualifier for the given annotation. This qualifier will match a candidate under the following circumstances:

      • If the type parameter is Named then the value of the Named annotation within the metadata is used to match the candidate by name
      • If the type parameter is Type then the value of the Type annotation is used to match the candidate by type
      Type Parameters:
      T - The component type
      Parameters:
      metadata - The metadata
      type - The annotation type
      Returns:
      The qualifier
    • byAnnotation

      public static <T extends Annotation> Qualifier<T> byAnnotation(AnnotationMetadata metadata, AnnotationValue<T> annotationValue)

      Build a qualifier for the given annotation value.

      Type Parameters:
      T - The component type
      Parameters:
      metadata - The metadata
      annotationValue - The annotation value
      Returns:
      The qualifier
    • byRepeatableAnnotation

      public static <T> Qualifier<T> byRepeatableAnnotation(AnnotationMetadata metadata, String repeatableType)

      Builds a qualifier that uses the given repeatable annotation.

      Type Parameters:
      T - The component type
      Parameters:
      metadata - The metadata
      repeatableType - The annotation repeatable type. That is the annotation specified to Repeatable.value()
      Returns:
      The qualifier
    • byAnnotationSimple

      @Internal public static <T> Qualifier<T> byAnnotationSimple(AnnotationMetadata metadata, String type)

      Build a qualifier for the given annotation.

      Unlike byAnnotation(io.micronaut.core.annotation.AnnotationMetadata, String) this method will not attempt to pick the qualifier strategy to use at runtime based on the passed annotation name.

      Type Parameters:
      T - The component type
      Parameters:
      metadata - The metadata
      type - The annotation type
      Returns:
      The qualifier
      Since:
      3.1.0
    • byStereotype

      public static <T> Qualifier<T> byStereotype(Class<? extends Annotation> stereotype)
      Build a qualifier for the given annotation.
      Type Parameters:
      T - The component type
      Parameters:
      stereotype - The stereotype
      Returns:
      The qualifier
    • byStereotype

      public static <T> Qualifier<T> byStereotype(String stereotype)
      Build a qualifier for the given annotation.
      Type Parameters:
      T - The component type
      Parameters:
      stereotype - The stereotype
      Returns:
      The qualifier
      Since:
      3.0.0
    • byTypeArguments

      public static <T> Qualifier<T> byTypeArguments(Class<?>... typeArguments)
      Build a qualifier for the given generic type arguments.
      Type Parameters:
      T - The component type
      Parameters:
      typeArguments - The generic type arguments
      Returns:
      The qualifier
    • byExactTypeArgumentName

      @NonNull public static <T> @NonNull Qualifier<T> byExactTypeArgumentName(@NonNull @NonNull String typeName)
      Build a qualifier for the given generic type argument name.
      Type Parameters:
      T - The component type
      Parameters:
      typeName - The name of the generic type argument
      Returns:
      The qualifier
      Since:
      3.0.0
    • byTypeArgumentsClosest

      public static <T> Qualifier<T> byTypeArgumentsClosest(Class<?>... typeArguments)
      Build a qualifier for the given generic type arguments. Only the closest matches will be returned.
      Type Parameters:
      T - The component type
      Parameters:
      typeArguments - The generic type arguments
      Returns:
      The qualifier
    • byType

      public static <T> Qualifier<T> byType(Class<?>... typeArguments)
      Build a qualifier for the given generic type arguments.
      Type Parameters:
      T - The component type
      Parameters:
      typeArguments - The generic type arguments
      Returns:
      The qualifier
    • byInterceptorBinding

      @NonNull public static <T> @NonNull Qualifier<T> byInterceptorBinding(@NonNull @NonNull AnnotationMetadata annotationMetadata)
      Reduces bean definitions by the given interceptor binding.
      Type Parameters:
      T - The bean type
      Parameters:
      annotationMetadata - The annotation metadata
      Returns:
      The qualifier
    • byInterceptorBindingValues

      @NonNull public static <T> @NonNull Qualifier<T> byInterceptorBindingValues(@NonNull @NonNull Collection<AnnotationValue<?>> binding)
      Reduces bean definitions by the given interceptor binding.
      Type Parameters:
      T - The bean type
      Parameters:
      binding - The binding values to use
      Returns:
      The qualifier
      Since:
      3.3.0