Package io.micronaut.core.type
Interface Argument<T>
- Type Parameters:
T
- The argument type
- All Superinterfaces:
AnnotatedElement
,AnnotationMetadataProvider
,AnnotationSource
,Named
,Type
,TypeInformation<T>
,TypeVariableResolver
- All Known Subinterfaces:
ArgumentValue<V>
,GenericPlaceholder<T>
,MutableArgumentValue<V>
- All Known Implementing Classes:
ArgumentBeanType
,DefaultArgument
,GenericArgument
Represents an argument to a method or constructor or type.
- Since:
- 1.0
- Author:
- Graeme Rocher
-
Field Summary
Modifier and TypeFieldDescriptionConstant for boolean argument.Constant for byte argument.Constant char argument.Constant for double argument.Constant for float argument.Constant for int argument.Constant forList<String>
argument.Constant for long argument.Default Object argument.Constant short argument.Constant for string argument.Constant for void argument.Constant for Void object argument.static final Argument[]
Constant representing zero arguments.Fields inherited from interface io.micronaut.core.annotation.AnnotationSource
EMPTY
-
Method Summary
Modifier and TypeMethodDescriptionboolean
equalsType
(@Nullable Argument<?> other) Whether the types are equivalent.getName()
default boolean
isAssignableFrom
(@NonNull Argument<?> candidateArgument) Checks if the argument can be assigned to this argument.default boolean
isAssignableFrom
(@NonNull Class<?> candidateType) Delegates toClass.isAssignableFrom(Class)
for this argument.default boolean
Whether the given argument is an instance.default boolean
Whether this argument is a type variable used in generics.Creates a new argument representing a generic list.Creates a new argument representing a generic list.Creates a new argument representing a generic map.Creates a new argument representing a generic map.Creates a new argument for the given type and name.of
(@NonNull Class<T> type, @Nullable AnnotationMetadata annotationMetadata, @Nullable Argument<?>... typeParameters) Creates a new argument for the given type and name.of
(@NonNull Class<T> type, @Nullable AnnotationMetadata annotationMetadata, @Nullable Class<?>[] typeParameters) Creates a new argument for the given type and name.Creates a new argument for the given type and name.Creates a new argument for the given type and name.Creates a new argument for the given type and name.of
(@NonNull Class<T> type, @Nullable String name, @Nullable AnnotationMetadata annotationMetadata, @Nullable Argument<?>... typeParameters) Creates a new argument for the given type and name.Creates a new argument for the given type and name.ofTypeVariable
(@NonNull Class<T> type, @Nullable String name) Creates a new argument for the given type and name that is a type variable.Creates a new argument for the given type and name that is a type variable.ofTypeVariable
(@NonNull Class<T> type, @Nullable String argumentName, @NonNull String variableName, @Nullable AnnotationMetadata annotationMetadata, @Nullable Argument<?>... typeParameters) Creates a new argument for the given type and name that is a type variable.ofTypeVariable
(@NonNull Class<T> type, @Nullable String name, @Nullable AnnotationMetadata annotationMetadata, @Nullable Argument<?>... typeParameters) Creates a new argument for the given type and name that is a type variable.optionalOf
(@NonNull Argument<T> optionalValueArgument) Creates a new argument representing an optional.optionalOf
(@NonNull Class<T> optionalValueClass) Creates a new argument representing an optional.Creates a new argument representing a generic set.Creates a new argument representing a generic set.toClassArray
(@Nullable Argument<?>... arguments) Convert an argument array to a class array.Convert the arguments to a string representation.int
The hash code including only the types.Methods inherited from interface io.micronaut.core.annotation.AnnotatedElement
isDeclaredNonNull, isDeclaredNullable, isNonNull, isNullable
Methods inherited from interface io.micronaut.core.annotation.AnnotationMetadataProvider
findAnnotation, findAnnotation, findDeclaredAnnotation, findDeclaredAnnotation, getAnnotationMetadata, getTargetAnnotationMetadata, isAnnotationPresent, isDeclaredAnnotationPresent, synthesize, synthesizeAll, synthesizeAnnotationsByType, synthesizeDeclared, synthesizeDeclared, synthesizeDeclaredAnnotationsByType
Methods inherited from interface io.micronaut.core.annotation.AnnotationSource
getAnnotation, getAnnotation, getDeclaredAnnotation, getDeclaredAnnotation, isAnnotationPresent, isDeclaredAnnotationPresent, synthesize, synthesizeDeclared
Methods inherited from interface io.micronaut.core.type.TypeInformation
asParameterizedType, asType, getSimpleName, getType, getTypeName, getTypeString, getWrappedType, getWrapperType, hasTypeVariables, isArray, isAsync, isAsyncOrReactive, isCompletable, isContainerType, isOptional, isPrimitive, isProvider, isReactive, isSpecifiedSingle, isVoid, isWrapperType
Methods inherited from interface io.micronaut.core.type.TypeVariableResolver
getFirstTypeVariable, getTypeParameters, getTypeVariable, getTypeVariables
-
Field Details
-
STRING
Constant for string argument. -
INT
Constant for int argument. Used by generated code, do not remove. -
LONG
Constant for long argument. Used by generated code, do not remove. -
FLOAT
Constant for float argument. Used by generated code, do not remove. -
DOUBLE
Constant for double argument. Used by generated code, do not remove. -
VOID
Constant for void argument. Used by generated code, do not remove. -
BYTE
Constant for byte argument. Used by generated code, do not remove. -
BOOLEAN
Constant for boolean argument. Used by generated code, do not remove. -
CHAR
Constant char argument. Used by generated code, do not remove. -
SHORT
Constant short argument. Used by generated code, do not remove. -
ZERO_ARGUMENTS
Constant representing zero arguments. Used by generated code, do not remove. -
OBJECT_ARGUMENT
Default Object argument. Used by generated code, do not remove. -
LIST_OF_STRING
Constant forList<String>
argument. -
VOID_OBJECT
Constant for Void object argument.
-
-
Method Details
-
getName
-
equalsType
Whether the types are equivalent. The regularObject.equals(Object)
implementation includes the argument name within the comparison so this method offers a variation that just compares types.- Parameters:
other
- The type- Returns:
- True if they are equal
-
typeHashCode
int typeHashCode()The hash code including only the types. The regularObject.hashCode()
implementation includes the argument name within the comparison so this method offers a variation that just compares types.- Returns:
- The type hash code
-
isTypeVariable
default boolean isTypeVariable()Whether this argument is a type variable used in generics.- Returns:
- True if it is a variable
- Since:
- 3.0.0
-
isInstance
Whether the given argument is an instance.- Parameters:
o
- The object- Returns:
- True if it is an instance of this type
-
isAssignableFrom
Delegates toClass.isAssignableFrom(Class)
for this argument.- Parameters:
candidateType
- The candidate type- Returns:
- True if it is assignable from.
- Since:
- 3.0.0
-
isAssignableFrom
Checks if the argument can be assigned to this argument.- Parameters:
candidateArgument
- The candidate argument- Returns:
- True if it is assignable from.
- Since:
- 3.0.0
-
toClassArray
Convert an argument array to a class array.- Parameters:
arguments
- The arguments- Returns:
- The class array
-
toString
Convert the arguments to a string representation.- Parameters:
arguments
- The arguments- Returns:
- The String representation
-
of
@NonNull static <T> @NonNull Argument<T> of(@NonNull @NonNull Class<T> type, @Nullable @Nullable String name, @Nullable @Nullable Argument<?>... typeParameters) Creates a new argument for the given type and name.- Type Parameters:
T
- The generic type- Parameters:
type
- The typename
- The nametypeParameters
- the type parameters- Returns:
- The argument instance
-
ofTypeVariable
@NonNull static <T> @NonNull Argument<T> ofTypeVariable(@NonNull @NonNull Class<T> type, @Nullable @Nullable String name, @Nullable @Nullable AnnotationMetadata annotationMetadata, @Nullable @Nullable Argument<?>... typeParameters) Creates a new argument for the given type and name that is a type variable.- Type Parameters:
T
- The generic type- Parameters:
type
- The typename
- The nameannotationMetadata
- The annotation metadatatypeParameters
- the type parameters- Returns:
- The argument instance
- Since:
- 3.0.0
-
ofTypeVariable
@NonNull static <T> @NonNull Argument<T> ofTypeVariable(@NonNull @NonNull Class<T> type, @Nullable @Nullable String argumentName, @NonNull @NonNull String variableName, @Nullable @Nullable AnnotationMetadata annotationMetadata, @Nullable @Nullable Argument<?>... typeParameters) Creates a new argument for the given type and name that is a type variable.- Type Parameters:
T
- The generic type- Parameters:
type
- The typeargumentName
- The name of the argumenntvariableName
- The variable nameannotationMetadata
- The annotation metadatatypeParameters
- the type parameters- Returns:
- The argument instance
- Since:
- 3.2.0
-
ofTypeVariable
@NonNull static <T> @NonNull Argument<T> ofTypeVariable(@NonNull @NonNull Class<T> type, @Nullable @Nullable String name) Creates a new argument for the given type and name that is a type variable.- Type Parameters:
T
- The generic type- Parameters:
type
- The typename
- The name- Returns:
- The argument instance
- Since:
- 3.0.0
-
ofTypeVariable
@NonNull static <T> @NonNull Argument<T> ofTypeVariable(@NonNull @NonNull Class<T> type, @Nullable @Nullable String argumentName, @NonNull @NonNull String variableName) Creates a new argument for the given type and name that is a type variable.- Type Parameters:
T
- The generic type- Parameters:
type
- The typeargumentName
- The name of the argumentvariableName
- The variable name- Returns:
- The argument instance
- Since:
- 3.2.0
-
of
@NonNull static <T> @NonNull Argument<T> of(@NonNull @NonNull Class<T> type, @Nullable @Nullable String name, @Nullable @Nullable AnnotationMetadata annotationMetadata, @Nullable @Nullable Argument<?>... typeParameters) Creates a new argument for the given type and name.- Type Parameters:
T
- The generic type- Parameters:
type
- The typename
- The nameannotationMetadata
- the annotation metadatatypeParameters
- the type parameters- Returns:
- The argument instance
-
of
@NonNull static <T> @NonNull Argument<T> of(@NonNull @NonNull Class<T> type, @Nullable @Nullable AnnotationMetadata annotationMetadata, @Nullable @Nullable Argument<?>... typeParameters) Creates a new argument for the given type and name.- Type Parameters:
T
- The generic type- Parameters:
type
- The typeannotationMetadata
- the annotation metadatatypeParameters
- the type parameters- Returns:
- The argument instance
-
of
@NonNull static <T> @NonNull Argument<T> of(@NonNull @NonNull Class<T> type, @Nullable @Nullable String name) Creates a new argument for the given type and name.- Type Parameters:
T
- The generic type- Parameters:
type
- The typename
- The name- Returns:
- The argument instance
-
of
@NonNull static <T> @NonNull Argument<T> of(@NonNull @NonNull Class<T> type, @Nullable @Nullable Argument<?>... typeParameters) Creates a new argument for the given type and name.- Type Parameters:
T
- The generic type- Parameters:
type
- The typetypeParameters
- The parameters type- Returns:
- The argument instance
-
of
- Parameters:
type
- The type- Returns:
- The argument
- Throws:
IllegalArgumentException
- If the type cannot be coerced- Since:
- 3.0.0
-
of
Creates a new argument for the given type and name.- Type Parameters:
T
- The generic type- Parameters:
type
- The type- Returns:
- The argument instance
-
of
@NonNull static <T> @NonNull Argument<T> of(@NonNull @NonNull Class<T> type, @Nullable @Nullable Class<?>... typeParameters) Creates a new argument for the given type and name.- Type Parameters:
T
- The generic type- Parameters:
type
- The typetypeParameters
- the parameters type- Returns:
- The argument instance
-
of
@NonNull static <T> @NonNull Argument<T> of(@NonNull @NonNull Class<T> type, @Nullable @Nullable AnnotationMetadata annotationMetadata, @Nullable @Nullable Class<?>[] typeParameters) Creates a new argument for the given type and name. NOTE: This method should be avoided as it does use the reflection to retrieve the type parameter names.- Type Parameters:
T
- The generic type- Parameters:
type
- The typeannotationMetadata
- The annotation metadatatypeParameters
- The parameters type- Returns:
- The argument instance
- Since:
- 3.0.0
-
listOf
Creates a new argument representing a generic list.- Type Parameters:
T
- list element type- Parameters:
type
- list element type- Returns:
- The argument instance
-
listOf
Creates a new argument representing a generic list.- Type Parameters:
T
- list element type- Parameters:
type
- list element type- Returns:
- The argument instance
- Since:
- 2.0.1
-
setOf
Creates a new argument representing a generic set.- Type Parameters:
T
- set element type- Parameters:
type
- set element type- Returns:
- The argument instance
-
setOf
Creates a new argument representing a generic set.- Type Parameters:
T
- set element type- Parameters:
type
- set element type- Returns:
- The argument instance
- Since:
- 2.0.1
-
mapOf
@NonNull static <K,V> @NonNull Argument<Map<K,V>> mapOf(@NonNull @NonNull Class<K> keyType, @NonNull @NonNull Class<V> valueType) Creates a new argument representing a generic map.- Type Parameters:
K
- The map key typeV
- The map value type- Parameters:
keyType
- The key typevalueType
- The value type- Returns:
- The argument instance
-
mapOf
@NonNull static <K,V> @NonNull Argument<Map<K,V>> mapOf(@NonNull @NonNull Argument<K> keyType, @NonNull @NonNull Argument<V> valueType) Creates a new argument representing a generic map.- Type Parameters:
K
- The map key typeV
- The map value type- Parameters:
keyType
- The key typevalueType
- The value type- Returns:
- The argument instance
- Since:
- 2.0.1
-
optionalOf
@NonNull static <T> @NonNull Argument<Optional<T>> optionalOf(@NonNull @NonNull Class<T> optionalValueClass) Creates a new argument representing an optional.- Type Parameters:
T
- The optional type- Parameters:
optionalValueClass
- The optional type- Returns:
- The argument instance
- Since:
- 4.0.0
-
optionalOf
@NonNull static <T> @NonNull Argument<Optional<T>> optionalOf(@NonNull @NonNull Argument<T> optionalValueArgument) Creates a new argument representing an optional.- Type Parameters:
T
- The optional type- Parameters:
optionalValueArgument
- The optional type- Returns:
- The argument instance
- Since:
- 4.0.0
-