Class ParameterInfo
- All Implemented Interfaces:
Annotatable
This class provides a convenient wrapper around Parameter that extends the standard Java reflection
API with additional functionality for parameter introspection, annotation handling, and name resolution.
It supports resolving parameter names from bytecode (when compiled with @Name annotations.
Features:
- Parameter introspection - access parameter metadata, type, annotations
- Name resolution - resolve parameter names from bytecode or annotations
- Qualifier support - extract qualifier names from annotations
- Hierarchy traversal - find matching parameters in parent methods/constructors
- Annotation support - get annotations declared on the parameter
Use Cases:
- Introspecting parameter metadata for code generation or analysis
- Resolving parameter names for dependency injection frameworks
- Finding annotations on parameters
- Working with parameter types and qualifiers
- Building frameworks that need to analyze method/constructor signatures
Usage:
Parameter Name Resolution:
Parameter names are resolved in the following order:
@Nameannotation value (if present)- Bytecode parameter names (if compiled with
-parameters flag) arg0 ,arg1 , etc. (fallback if names unavailable)
See Also:
MethodInfo- Method introspectionConstructorInfo- Constructor introspectionExecutableInfo- Common executable functionality- Reflection Package
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedParameterInfo(ExecutableInfo executable, Parameter inner, int index, ClassInfo type) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturnstrue if this parameter can accept the specified value.booleanCompares this ParameterInfo with the specified object for equality.Returns the type of this annotatable object.Returns anAnnotatedTypeobject that represents the use of a type to specify the type of this parameter.Returns all annotations declared on this parameter.<A extends Annotation>
Stream<AnnotationInfo<A>>getAnnotations(Class<A> type) Returns a stream of annotation infos of the specified type declared on this parameter.Returns the constructor that this parameter belongs to.Returns theExecutableInfowhich declares this parameter.intgetIndex()Returns the index position of this parameter.getLabel()Returns a human-readable label for this annotatable element.Returns this parameter and all matching parameters in parent classes.Returns the method that this parameter belongs to.intReturns the Java language modifiers for the parameter represented by this object, as an integer.getName()Returns the name of the parameter.Returns aTypeobject that identifies the parameterized type for this parameter.Returns the class type of this parameter.Finds the name of this parameter for bean property mapping.Finds the bean injection qualifier for this parameter.inthashCode()Returns a hash code value for this ParameterInfo.booleanhasName()Returnstrue if the parameter has a name.inner()Returns the wrappedParameterobject.booleanis(ElementFlag flag) Returnstrue if the specified flag is applicable to this element.booleanReturnstrue if this parameter is implicitly declared in source code.booleanReturnstrue if the parameter has a name according to the.class file.booleanReturnstrue if this parameter is a synthetic construct as defined by the Java Language Specification.booleanReturnstrue if the parameter type is an exact match for the specified class.booleanReturnstrue if this parameter represents a variable argument list.static ParameterInfoCreates a ParameterInfo wrapper for the specified parameter.toString()Methods inherited from class org.apache.juneau.commons.reflect.ElementInfo
ai, isAbstract, isAll, isAny, isFinal, isInterface, isNative, isNotAbstract, isNotFinal, isNotInterface, isNotNative, isNotPrivate, isNotProtected, isNotPublic, isNotStatic, isNotSynchronized, isNotTransient, isNotVolatile, isPrivate, isProtected, isPublic, isStatic, isSynchronized, isTransient, isVolatile
-
Constructor Details
-
ParameterInfo
Constructor.Creates a new ParameterInfo wrapper for the specified parameter. This constructor is protected and should not be called directly. ParameterInfo instances are typically obtained from
ExecutableInfo.getParameters()orof(Parameter).- Parameters:
executable- The ExecutableInfo (MethodInfo or ConstructorInfo) that contains this parameter.inner- The parameter being wrapped.index- The zero-based index of this parameter in the method/constructor signature.type- The ClassInfo representing the parameter type.
-
-
Method Details
-
of
Creates a ParameterInfo wrapper for the specified parameter.This convenience method automatically determines the declaring executable from the parameter and finds the matching ParameterInfo.
Example:
Parameter
p = ...; ParameterInfopi = ParameterInfo.of (p );- Parameters:
inner- The parameter being wrapped. Must not benull .- Returns:
- A ParameterInfo object wrapping the parameter.
- Throws:
IllegalArgumentException- If the parameter isnull or cannot be found in its declaring executable.
-
canAccept
Returnstrue if this parameter can accept the specified value.- Parameters:
value- The value to check.- Returns:
true if this parameter can accept the specified value.
-
getAnnotatableType
Description copied from interface:AnnotatableReturns the type of this annotatable object.- Specified by:
getAnnotatableTypein interfaceAnnotatable- Returns:
- The type of annotatable object this represents.
-
getAnnotatedType
Returns anAnnotatedTypeobject that represents the use of a type to specify the type of this parameter.Same as calling
Parameter.getAnnotatedType().Example:
// Get annotated type: void method(@NotNull String value) ParameterInfopi = ...; AnnotatedTypeaType =pi .getAnnotatedType();// Check for @NotNull on the type - Returns:
- An
AnnotatedTypeobject representing the type of this parameter. - See Also:
-
getAnnotations
Returns all annotations declared on this parameter.Returns annotations directly declared on this parameter, wrapped as
AnnotationInfoobjects.Note on Repeatable Annotations: Repeatable annotations (those marked with
@Repeatable) are automatically expanded into their individual annotation instances. For example, if a parameter has multiple@Beanannotations, this method returns each@Beanannotation separately, rather than the container annotation.- Returns:
- An unmodifiable list of annotations on this parameter, never
null .
Repeatable annotations are expanded into individual instances.
-
getAnnotations
Returns a stream of annotation infos of the specified type declared on this parameter.- Type Parameters:
A- The annotation type.- Parameters:
type- The annotation type.- Returns:
- A stream of annotation infos, never
null .
-
getConstructor
Returns the constructor that this parameter belongs to.- Returns:
- The constructor that this parameter belongs to, or
null if it belongs to a method.
-
getDeclaringExecutable
Returns theExecutableInfowhich declares this parameter.Same as calling
Parameter.getDeclaringExecutable()but returnsExecutableInfoinstead.Example:
// Get the method or constructor that declares this parameter ParameterInfopi = ...; ExecutableInfoexecutable =pi .getDeclaringExecutable();if (executable .isConstructor()) { ConstructorInfoci = (ConstructorInfo)executable ; }- Returns:
- The
ExecutableInfodeclaring this parameter. - See Also:
-
getIndex
Returns the index position of this parameter.- Returns:
- The index position of this parameter.
-
getLabel
Description copied from interface:AnnotatableReturns a human-readable label for this annotatable element.The label format depends on the type of annotatable:
CLASS_TYPE- Simple class name (e.g.,"MyClass" )METHOD_TYPE- Class and method with parameter types (e.g.,"MyClass.myMethod(String,int)" )FIELD_TYPE- Class and field name (e.g.,"MyClass.myField" )CONSTRUCTOR_TYPE- Class and constructor with parameter types (e.g.,"MyClass.MyClass(String)" )PARAMETER_TYPE- Class, method/constructor, and parameter index (e.g.,"MyClass.myMethod[0]" )PACKAGE_TYPE- Package name (e.g.,"com.example.package" )
- Specified by:
getLabelin interfaceAnnotatable- Returns:
- The human-readable label for this annotatable element.
-
getMatchingParameters
Returns this parameter and all matching parameters in parent classes.For constructors, searches parent class constructors for parameters with matching name and type, regardless of parameter count or position. This allows finding annotated parameters that may be inherited by child classes even when constructor signatures differ.
For methods, searches matching methods (same signature) in parent classes/interfaces for parameters at the same index with matching name and type.
Examples:
// Constructor with different parameter counts: class A { A(Stringfoo ,int bar ) {} }class Bextends A { B(Stringfoo ) {} }// For B's foo parameter, returns: [B.foo, A.foo] ParameterInfopi = ...; List<ParameterInfo>matching =pi .getMatchingParameters();- Returns:
- A list of matching parameters including this one, in child-to-parent order.
-
getMethod
Returns the method that this parameter belongs to.- Returns:
- The method that this parameter belongs to, or
null if it belongs to a constructor.
-
getModifiers
Returns the Java language modifiers for the parameter represented by this object, as an integer.The
Modifierclass should be used to decode the modifiers.Same as calling
Parameter.getModifiers().Example:
// Check if parameter is final ParameterInfopi = ...;int modifiers =pi .getModifiers();boolean isFinal = Modifier.isFinal (modifiers );- Overrides:
getModifiersin classElementInfo- Returns:
- The Java language modifiers for this parameter.
- See Also:
-
getName
Returns the name of the parameter.Searches for the name in the following order:
- @Name annotation value (takes precedence over bytecode parameter names)
- Bytecode parameter name (if compiled with -parameters flag)
- Matching parameters in parent classes/interfaces (for methods)
- Synthetic name like "arg0", "arg1", etc. (fallback)
This method works with any annotation named "Name" (from any package) that has a
String value() method.- Returns:
- The name of the parameter, never
null . - See Also:
-
getParameterizedType
Returns aTypeobject that identifies the parameterized type for this parameter.Same as calling
Parameter.getParameterizedType().Example:
// Get generic type information for parameter: List<String> values ParameterInfopi = ...; Typetype =pi .getParameterizedType();if (type instanceof ParameterizedType) { ParameterizedTypepType = (ParameterizedType)type ;// pType.getActualTypeArguments()[0] is String.class }- Returns:
- A
Typeobject identifying the parameterized type. - See Also:
-
getParameterType
Returns the class type of this parameter.- Returns:
- The class type of this parameter.
-
getResolvedName
Finds the name of this parameter for bean property mapping.Searches for the parameter name in the following order:
@Nameannotation value- Bytecode parameter name (if available and not disabled via system property)
- Matching parameters in parent classes/interfaces
This method is used for mapping constructor parameters to bean properties.
Note: This is different from
getResolvedQualifier()which looks for@Namedannotations for bean injection purposes.- Returns:
- The parameter name if found, or
null if not available. - See Also:
-
getResolvedQualifier
Finds the bean injection qualifier for this parameter.Searches for the
@Namedannotation value to determine which named bean should be injected.This method is used by the
BeanStorefor bean injection.Note: This is different from
getResolvedName()which looks for@Nameannotations for bean property mapping.- Returns:
- The bean qualifier name if
@Namedannotation is found, ornull if not annotated. - See Also:
-
hasName
Returnstrue if the parameter has a name.This returns
true if the parameter has an annotation with the simple name "Name", or if the parameter's name is present in the class file.- Returns:
true if the parameter has a name.
-
inner
Returns the wrappedParameterobject.- Returns:
- The wrapped
Parameterobject.
-
equals
Compares this ParameterInfo with the specified object for equality.Two ParameterInfo objects are considered equal if they wrap the same underlying
Parameterobject. This delegates to the underlyingParameter.equals(Object)method.This method makes ParameterInfo suitable for use as keys in hash-based collections such as
HashMapandHashSet. -
hashCode
Returns a hash code value for this ParameterInfo.This delegates to the underlying
Parameter.hashCode()method.This method makes ParameterInfo suitable for use as keys in hash-based collections such as
HashMapandHashSet. -
is
Description copied from class:ElementInfoReturnstrue if the specified flag is applicable to this element.Subclasses should override this method and call
super.is(flag)to handle common modifier flags, then handle their own specific flags.- Overrides:
isin classElementInfo- Parameters:
flag- The flag to test for.- Returns:
true if the specified flag is applicable to this element.
-
isImplicit
Returnstrue if this parameter is implicitly declared in source code.Returns
true if this parameter is neither explicitly nor implicitly declared in source code.Same as calling
Parameter.isImplicit().Example:
// Filter out implicit parameters ParameterInfopi = ...;if (!pi .isImplicit()) {// Process explicit parameter }- Returns:
true if this parameter is implicitly declared.- See Also:
-
isNamePresent
Returnstrue if the parameter has a name according to the.class file.Same as calling
Parameter.isNamePresent().Note: This method is different from
hasName()which also checks for the presence of a@Name annotation. This method only checks if the name is present in the bytecode.Example:
// Check if parameter name is in bytecode ParameterInfopi = ...;if (pi .isNamePresent()) { Stringname =pi .getName(); }- Returns:
true if the parameter has a name in the bytecode.- See Also:
-
isSynthetic
Returnstrue if this parameter is a synthetic construct as defined by the Java Language Specification.Same as calling
Parameter.isSynthetic().Example:
// Filter out compiler-generated parameters ParameterInfopi = ...;if (!pi .isSynthetic()) {// Process real parameter }- Returns:
true if this parameter is a synthetic construct.- See Also:
-
isType
Returnstrue if the parameter type is an exact match for the specified class.- Parameters:
c- The type to check.- Returns:
true if the parameter type is an exact match for the specified class.
-
isVarArgs
Returnstrue if this parameter represents a variable argument list.Same as calling
Parameter.isVarArgs().Only returns
true for the last parameter of a variable arity method.Example:
// Check if this is a varargs parameter ParameterInfopi = ...;if (pi .isVarArgs()) {// Handle variable arguments }- Returns:
true if this parameter represents a variable argument list.- See Also:
-
toString
-