Class ParamInfo

java.lang.Object
org.apache.juneau.reflect.ParamInfo

public final class ParamInfo extends Object
Lightweight utility class for introspecting information about a method parameter.
See Also:
  • Constructor Details

    • ParamInfo

      protected ParamInfo(ExecutableInfo eInfo, Parameter p, int index)
      Constructor.
      Parameters:
      eInfo - The constructor or method wrapper.
      p - The parameter being wrapped.
      index - The parameter index.
  • Method Details

    • getIndex

      public int getIndex()
      Returns the index position of this parameter.
      Returns:
      The index position of this parameter.
    • 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.
    • 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.
    • getParameterType

      Returns the class type of this parameter.
      Returns:
      The class type of this parameter.
    • forEachDeclaredAnnotation

      public <A extends Annotation> ParamInfo forEachDeclaredAnnotation(Class<A> type, Predicate<A> filter, Consumer<A> action)
      Performs an action on all matching annotations declared on this parameter.
      Type Parameters:
      A - The annotation type to look for.
      Parameters:
      type - The annotation type to look for.
      filter - A predicate to apply to the entries to determine if action should be performed. Can be null.
      action - An action to perform on the entry.
      Returns:
      This object.
    • getDeclaredAnnotation

      public <A extends Annotation> A getDeclaredAnnotation(Class<A> type)
      Returns the specified parameter annotation declared on this parameter.
      Type Parameters:
      A - The annotation type to look for.
      Parameters:
      type - The annotation type to look for.
      Returns:
      The specified parameter annotation declared on this parameter, or null if not found.
    • getAnnotation

      public <A extends Annotation> A getAnnotation(Class<A> type)
      Finds the annotation of the specified type defined on this method parameter.

      If the annotation cannot be found on the immediate method, searches methods with the same signature on the parent classes or interfaces.
      The search is performed in child-to-parent order.

      If still not found, searches for the annotation on the return type of the method.

      Type Parameters:
      A - The annotation type to look for.
      Parameters:
      type - The annotation type to look for.
      Returns:
      The annotation if found, or null if not.
    • hasAnnotation

      public <A extends Annotation> boolean hasAnnotation(Class<A> type)
      Returns true if this parameter has the specified annotation.
      Type Parameters:
      A - The annotation type to look for.
      Parameters:
      type - The annotation type to look for.
      Returns:
      The true if annotation if found.
    • hasNoAnnotation

      public <A extends Annotation> boolean hasNoAnnotation(Class<A> type)
      Returns true if this parameter doesn't have the specified annotation.
      Type Parameters:
      A - The annotation type to look for.
      Parameters:
      type - The annotation type to look for.
      Returns:
      The true if annotation if not found.
    • forEachAnnotation

      public <A extends Annotation> ParamInfo forEachAnnotation(Class<A> type, Predicate<A> filter, Consumer<A> action)
      Performs an action on all matching annotations on this parameter.

      Searches all methods with the same signature on the parent classes or interfaces and the return type on the method.

      Results are in parent-to-child order.

      Type Parameters:
      A - The annotation type to look for.
      Parameters:
      type - The annotation type to look for.
      filter - A predicate to apply to the entries to determine if action should be performed. Can be null.
      action - An action to perform on the entry.
      Returns:
      This object.
    • getAnnotation

      public <A extends Annotation> A getAnnotation(Class<A> type, Predicate<A> filter)
      Returns the first matching annotation on this method parameter.

      Searches all methods with the same signature on the parent classes or interfaces and the return type on the method.

      Results are in parent-to-child order.

      Type Parameters:
      A - The annotation type to look for.
      Parameters:
      type - The annotation type to look for.
      filter - A predicate to apply to the entries to determine if value should be used. Can be null.
      Returns:
      A list of all matching annotations found or an empty list if none found.
    • matches

      public boolean matches(Predicate<ParamInfo> test)
      Returns true if this object passes the specified predicate test.
      Parameters:
      test - The test to perform.
      Returns:
      true if this object passes the specified predicate test.
    • accept

      Performs an action on this object if the specified predicate test passes.
      Parameters:
      test - A test to apply to determine if action should be executed. Can be null.
      action - An action to perform on this object.
      Returns:
      This object.
    • isType

      public boolean isType(Class<?> c)
      Returns true 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.
    • hasName

      public boolean hasName()
      Returns true if the parameter has a name provided by the class file.
      Returns:
      true if the parameter has a name provided by the class file.
    • getName

      public String getName()
      Returns the name of the parameter.

      If the parameter's name is present, then this method returns the name provided by the class file. Otherwise, this method synthesizes a name of the form argN, where N is the index of the parameter in the descriptor of the method which declares the parameter.

      Returns:
      The name of the parameter.
      See Also:
    • canAccept

      public boolean canAccept(Object value)
      Returns true if this parameter can accept the specified value.
      Parameters:
      value - The value to check.
      Returns:
      true if this parameter can accept the specified value.
    • toString

      public String toString()
      Overrides:
      toString in class Object