Class ReflectionArguments
java.lang.Object
io.micronaut.reflection.ReflectionArguments
Builds
Arguments from the types read reflectively from parameters, fields, return types and type
hierarchies, in the shape the annotation processors give the arguments they generate: the raw type, the type
arguments recursively, the type variables as GenericPlaceholders, and the annotations of the element
and of every level of its type as metadata built by ReflectionAnnotations.
The reverse direction, toType(Argument), renders an argument as a Type for the APIs
defined on java.lang.reflect, either keeping an unresolved type variable or rendering it as the type
it is bounded by.
- Since:
- 5.2.0
- Author:
- Denis Stepanov
-
Method Summary
Modifier and TypeMethodDescriptionstatic Argument<?>[]argumentsOf(Executable executable) Converts the parameters of a method or constructor toArguments.static Argument<?>[]argumentsOf(Executable executable, Class<?> context) Converts the parameters of a method or constructor toArguments as the type reading them sees them.static Argument<?> of(@Nullable String name, AnnotatedType annotatedType) Converts an annotated type to a namedArgument.static Argument<?> Converts a type to a namedArgument.static Argument<?> of(AnnotatedType annotatedType) Converts an annotated type to anArgument: the raw type, the type arguments recursively, and the type-use annotations of each level.static Argument<?> Converts a field to anArgumentnamed after it, whose metadata holds the annotations of the field and the type-use annotations of its type.static Argument<?> Converts a field to anArgumentas the type reading it sees it: a variable the declaring type leaves open and the reading type gives a value to -Tof aclass Base<T>read through aclass Impl extends Base<Book>- is resolved to that value rather than left aGenericPlaceholder, which is what the processors generate for the reading type.static Argument<?> Converts a parameter to anArgumentnamed after it, whose metadata holds the annotations of the parameter and the type-use annotations of its type.static Argument<?> Converts a parameter to anArgumentas the type reading it sees it.static Argument<?> Converts a type to anArgument.static <T> @Nullable Argument<T> resolveGenericToArgument(Class<?> type, Class<T> superType) Resolves the type arguments a type gives to one of its super types, as an argument of the super type: for aclass A extends AbstractList<@Nullable String>, the argument ofCollectionisCollection<@Nullable String>.static Argument<?> Converts the return type of a method to anArgumentwhose metadata holds the annotations of the method and the type-use annotations of its return type, asof(Parameter)builds the argument of a parameter from the parameter and its type: a generated executable method of a bean definition reports the return value with the annotations of the method on it, and a constraint declared on a method constrains the value it returns.static Argument<?> Converts the return type of a method to anArgumentas the type invoking it sees it, with the annotations of the method and the type-use annotations of its return type.static TypeRenders an argument as aType: the raw class when it has no type argument, aParameterizedTypeotherwise, and aTypeVariablebounded by either when the argument is aGenericPlaceholder.static TypeRenders an argument as aType, choosing what an unresolved type variable becomes.
-
Method Details
-
of
Converts an annotated type to anArgument: the raw type, the type arguments recursively, and the type-use annotations of each level.- Parameters:
annotatedType- The annotated type- Returns:
- The argument
-
of
Converts an annotated type to a namedArgument.- Parameters:
name- The name of the argument, can benullannotatedType- The annotated type- Returns:
- The argument
-
of
Converts a type to anArgument. UnlikeArgument.of(Type), a type variable is converted to aGenericPlaceholderof its first bound, a wildcard to its upper bound and a generic array to the array of its raw component.- Parameters:
type- The type- Returns:
- The argument
-
of
-
of
-
of
-
argumentsOf
Converts the parameters of a method or constructor toArguments.- Parameters:
executable- The method or constructor- Returns:
- The arguments, in the order of the parameters
-
returnOf
Converts the return type of a method to anArgumentwhose metadata holds the annotations of the method and the type-use annotations of its return type, asof(Parameter)builds the argument of a parameter from the parameter and its type: a generated executable method of a bean definition reports the return value with the annotations of the method on it, and a constraint declared on a method constrains the value it returns. An annotation written before the return type whose target includesTYPE_USEis on both the method and the type (JLS 9.7.4) and is read once.- Parameters:
method- The method- Returns:
- The argument
-
of
Converts a field to anArgumentas the type reading it sees it: a variable the declaring type leaves open and the reading type gives a value to -Tof aclass Base<T>read through aclass Impl extends Base<Book>- is resolved to that value rather than left aGenericPlaceholder, which is what the processors generate for the reading type.- Parameters:
field- The fieldcontext- The type the field is read through, an implementation of its declaring type- Returns:
- The argument
-
of
Converts a parameter to anArgumentas the type reading it sees it.- Parameters:
parameter- The parametercontext- The type the parameter is read through, an implementation of the type declaring the method or constructor- Returns:
- The argument
- See Also:
-
argumentsOf
Converts the parameters of a method or constructor toArguments as the type reading them sees them.- Parameters:
executable- The method or constructorcontext- The type the executable is read through, an implementation of its declaring type- Returns:
- The arguments, in the order of the parameters
- See Also:
-
returnOf
Converts the return type of a method to anArgumentas the type invoking it sees it, with the annotations of the method and the type-use annotations of its return type.- Parameters:
method- The methodcontext- The type the method is invoked on, an implementation of its declaring type- Returns:
- The argument
- See Also:
-
resolveGenericToArgument
Resolves the type arguments a type gives to one of its super types, as an argument of the super type: for aclass A extends AbstractList<@Nullable String>, the argument ofCollectionisCollection<@Nullable String>. The type-use annotations of everyextendsandimplementsclause of the hierarchy are carried.- Type Parameters:
T- The super type- Parameters:
type- The type, an implementation of the super typesuperType- The super type, a class or an interface- Returns:
- The argument of the super type, or
nullwhen the type does not extend or implement it
-
toType
Renders an argument as aType: the raw class when it has no type argument, aParameterizedTypeotherwise, and aTypeVariablebounded by either when the argument is aGenericPlaceholder.- Parameters:
argument- The argument- Returns:
- The type
- See Also:
-
toType
Renders an argument as aType, choosing what an unresolved type variable becomes.An API that describes a declaration - the type of an injection point, of an observed event - wants the variable itself, so that it can tell
List<T>fromList<String>; an API that compares types by assignability wants the type the variable is bounded by, which is what the erasure of the declaration yields. The generated metadata carries aGenericPlaceholderfor both cases, so the caller says which of the two it means.- Parameters:
argument- The argumenttypeVariables- Whether aGenericPlaceholderis rendered as aTypeVariablerather than as the type it is bounded by- Returns:
- The type
-