Package io.micronaut.inject.qualifiers
Class Qualifiers
- java.lang.Object
-
- io.micronaut.inject.qualifiers.Qualifiers
-
public class Qualifiers extends java.lang.Object
Factory forBean
qualifiers.- Since:
- 1.0
-
-
Constructor Summary
Constructors Constructor Description Qualifiers()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <T> Qualifier<T>
any()
Allows looking up the first matching instance.static <T extends java.lang.annotation.Annotation>
Qualifier<T>byAnnotation(io.micronaut.core.annotation.AnnotationMetadata metadata, io.micronaut.core.annotation.AnnotationValue<T> annotationValue)
Build a qualifier for the given annotation value.static <T> Qualifier<T>
byAnnotation(io.micronaut.core.annotation.AnnotationMetadata metadata, java.lang.Class<? extends java.lang.annotation.Annotation> type)
Build a qualifier for the given annotation.static <T> Qualifier<T>
byAnnotation(io.micronaut.core.annotation.AnnotationMetadata metadata, java.lang.String type)
Build a qualifier for the given annotation.static <T> Qualifier<T>
byAnnotation(java.lang.annotation.Annotation annotation)
Build a qualifier for the given annotation.static <T> Qualifier<T>
byAnnotationSimple(io.micronaut.core.annotation.AnnotationMetadata metadata, java.lang.String type)
Build a qualifier for the given annotation.static <T> Qualifier<T>
byExactTypeArgumentName(java.lang.String typeName)
Build a qualifier for the given generic type argument name.static <T> Qualifier<T>
byInterceptorBinding(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata)
Reduces bean definitions by the given interceptor binding.static <T> Qualifier<T>
byInterceptorBinding(java.util.Collection<java.lang.String> bindingAnnotationNames)
Deprecated.static <T> Qualifier<T>
byInterceptorBindingValues(java.util.Collection<io.micronaut.core.annotation.AnnotationValue<?>> binding)
Reduces bean definitions by the given interceptor binding.static <T> Qualifier<T>
byName(java.lang.String name)
Build a qualifier for the given name.static <T> Qualifier<T>
byQualifiers(Qualifier<T>... qualifiers)
Build a qualifier from other qualifiers.static <T> Qualifier<T>
byRepeatableAnnotation(io.micronaut.core.annotation.AnnotationMetadata metadata, java.lang.String repeatableType)
Builds a qualifier that uses the given repeatable annotation.static <T> Qualifier<T>
byStereotype(java.lang.Class<? extends java.lang.annotation.Annotation> stereotype)
Build a qualifier for the given annotation.static <T> Qualifier<T>
byStereotype(java.lang.String stereotype)
Build a qualifier for the given annotation.static <T> Qualifier<T>
byType(java.lang.Class... typeArguments)
Build a qualifier for the given generic type arguments.static <T> Qualifier<T>
byTypeArguments(java.lang.Class... typeArguments)
Build a qualifier for the given generic type arguments.static <T> Qualifier<T>
byTypeArgumentsClosest(java.lang.Class... typeArguments)
Build a qualifier for the given generic type arguments.static <T> Qualifier<T>
forArgument(io.micronaut.core.type.Argument<?> argument)
Build a qualifier for the given argument.static <T> Qualifier<T>
none()
Allows looking up for beans without any qualifier.
-
-
-
Method Detail
-
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:
Any
-
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> Qualifier<T> forArgument(@NonNull io.micronaut.core.type.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(java.lang.String name)
Build a qualifier for the given name.- Type Parameters:
T
- The component type- Parameters:
name
- The name- Returns:
- The qualifier
-
byAnnotation
public static <T> Qualifier<T> byAnnotation(java.lang.annotation.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(io.micronaut.core.annotation.AnnotationMetadata metadata, java.lang.Class<? extends java.lang.annotation.Annotation> type)
Build a qualifier for the given annotation.- Type Parameters:
T
- The component type- Parameters:
metadata
- The metadatatype
- The annotation type- Returns:
- The qualifier
-
byAnnotation
public static <T> Qualifier<T> byAnnotation(io.micronaut.core.annotation.AnnotationMetadata metadata, java.lang.String type)
Build a qualifier for the given annotation. This qualifier will match a candidate under the following circumstances:
- Type Parameters:
T
- The component type- Parameters:
metadata
- The metadatatype
- The annotation type- Returns:
- The qualifier
-
byAnnotation
public static <T extends java.lang.annotation.Annotation> Qualifier<T> byAnnotation(io.micronaut.core.annotation.AnnotationMetadata metadata, io.micronaut.core.annotation.AnnotationValue<T> annotationValue)
Build a qualifier for the given annotation value.
- Type Parameters:
T
- The component type- Parameters:
metadata
- The metadataannotationValue
- The annotation value- Returns:
- The qualifier
-
byRepeatableAnnotation
public static <T> Qualifier<T> byRepeatableAnnotation(io.micronaut.core.annotation.AnnotationMetadata metadata, java.lang.String repeatableType)
Builds a qualifier that uses the given repeatable annotation.
- Type Parameters:
T
- The component type- Parameters:
metadata
- The metadatarepeatableType
- The annotation repeatable type. That is the annotation specified toRepeatable.value()
- Returns:
- The qualifier
-
byAnnotationSimple
@Internal public static <T> Qualifier<T> byAnnotationSimple(io.micronaut.core.annotation.AnnotationMetadata metadata, java.lang.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 metadatatype
- The annotation type- Returns:
- The qualifier
- Since:
- 3.1.0
-
byStereotype
public static <T> Qualifier<T> byStereotype(java.lang.Class<? extends java.lang.annotation.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(java.lang.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(java.lang.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> Qualifier<T> byExactTypeArgumentName(@NonNull java.lang.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(java.lang.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(java.lang.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> Qualifier<T> byInterceptorBinding(@NonNull io.micronaut.core.annotation.AnnotationMetadata annotationMetadata)
Reduces bean definitions by the given interceptor binding.- Type Parameters:
T
- The bean type- Parameters:
annotationMetadata
- The annotation metadata- Returns:
- The qualifier
-
byInterceptorBinding
@Deprecated @NonNull public static <T> Qualifier<T> byInterceptorBinding(@NonNull java.util.Collection<java.lang.String> bindingAnnotationNames)
Deprecated.Reduces bean definitions by the given interceptor binding.- Type Parameters:
T
- The bean type- Parameters:
bindingAnnotationNames
- The binding annotation names- Returns:
- The qualifier
- Since:
- 3.0.0
-
byInterceptorBindingValues
@NonNull public static <T> Qualifier<T> byInterceptorBindingValues(@NonNull java.util.Collection<io.micronaut.core.annotation.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
-
-