Interface ParameterContext
-
@API(status=STABLE, since="5.0") public interface ParameterContext
ParameterContext
encapsulates the context in which anExecutable
will be invoked for a givenParameter
.A
ParameterContext
is used to support parameter resolution via aParameterResolver
.- Since:
- 5.0
- See Also:
ParameterResolver
,Parameter
,Executable
,Method
,Constructor
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description <A extends java.lang.annotation.Annotation>
java.util.Optional<A>findAnnotation(java.lang.Class<A> annotationType)
Find the first annotation ofannotationType
that is either present or meta-present on theParameter
for this context.<A extends java.lang.annotation.Annotation>
java.util.List<A>findRepeatableAnnotations(java.lang.Class<A> annotationType)
Find all repeatable annotations ofannotationType
that are either present or meta-present on theParameter
for this context.default java.lang.reflect.Executable
getDeclaringExecutable()
Get theExecutable
(i.e., theMethod
orConstructor
) that declares theParameter
for this context.int
getIndex()
Get the index of theParameter
for this context within the parameter list of theExecutable
that declares the parameter.java.lang.reflect.Parameter
getParameter()
Get theParameter
for this context.java.util.Optional<java.lang.Object>
getTarget()
Get the target on which theExecutable
that declares theParameter
for this context will be invoked, if available.boolean
isAnnotated(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Determine if an annotation ofannotationType
is either present or meta-present on theParameter
for this context.
-
-
-
Method Detail
-
getParameter
java.lang.reflect.Parameter getParameter()
Get theParameter
for this context.WARNING
When searching for annotations on the parameter in this context, favor
isAnnotated(Class)
,findAnnotation(Class)
, andfindRepeatableAnnotations(Class)
over methods in theParameter
API due to a bug injavac
on JDK versions prior to JDK 9.- Returns:
- the parameter; never
null
- See Also:
getIndex()
-
getIndex
int getIndex()
Get the index of theParameter
for this context within the parameter list of theExecutable
that declares the parameter.- Returns:
- the index of the parameter
- See Also:
getParameter()
,Executable.getParameters()
-
getDeclaringExecutable
default java.lang.reflect.Executable getDeclaringExecutable()
Get theExecutable
(i.e., theMethod
orConstructor
) that declares theParameter
for this context.- Returns:
- the declaring
Executable
; nevernull
- See Also:
Parameter.getDeclaringExecutable()
-
getTarget
java.util.Optional<java.lang.Object> getTarget()
Get the target on which theExecutable
that declares theParameter
for this context will be invoked, if available.- Returns:
- an
Optional
containing the target on which theExecutable
will be invoked; nevernull
but will be empty if theExecutable
is a constructor or astatic
method.
-
isAnnotated
boolean isAnnotated(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Determine if an annotation ofannotationType
is either present or meta-present on theParameter
for this context.WARNING
Favor the use of this method over directly invoking
AnnotatedElement.isAnnotationPresent(Class)
due to a bug injavac
on JDK versions prior to JDK 9.- Parameters:
annotationType
- the annotation type to search for; nevernull
- Returns:
true
if the annotation is present or meta-present- Since:
- 5.1.1
- See Also:
findAnnotation(Class)
,findRepeatableAnnotations(Class)
-
findAnnotation
<A extends java.lang.annotation.Annotation> java.util.Optional<A> findAnnotation(java.lang.Class<A> annotationType)
Find the first annotation ofannotationType
that is either present or meta-present on theParameter
for this context.WARNING
Favor the use of this method over directly invoking annotation lookup methods in the
Parameter
API due to a bug injavac
on JDK versions prior to JDK 9.- Type Parameters:
A
- the annotation type- Parameters:
annotationType
- the annotation type to search for; nevernull
- Returns:
- an
Optional
containing the annotation; nevernull
but potentially empty - Since:
- 5.1.1
- See Also:
isAnnotated(Class)
,findRepeatableAnnotations(Class)
-
findRepeatableAnnotations
<A extends java.lang.annotation.Annotation> java.util.List<A> findRepeatableAnnotations(java.lang.Class<A> annotationType)
Find all repeatable annotations ofannotationType
that are either present or meta-present on theParameter
for this context.WARNING
Favor the use of this method over directly invoking annotation lookup methods in the
Parameter
API due to a bug injavac
on JDK versions prior to JDK 9.- Type Parameters:
A
- the annotation type- Parameters:
annotationType
- the repeatable annotation type to search for; nevernull
- Returns:
- the list of all such annotations found; neither
null
nor mutable, but potentially empty - Since:
- 5.1.1
- See Also:
isAnnotated(Class)
,findAnnotation(Class)
,Repeatable
-
-