Class ConstructorInfo

java.lang.Object
org.apache.juneau.reflect.ExecutableInfo
org.apache.juneau.reflect.ConstructorInfo
All Implemented Interfaces:
Comparable<ConstructorInfo>

public final class ConstructorInfo extends ExecutableInfo implements Comparable<ConstructorInfo>
Lightweight utility class for introspecting information about a constructor.
See Also:
  • Constructor Details

    • ConstructorInfo

      protected ConstructorInfo(ClassInfo declaringClass, Constructor<?> c)
      Constructor.
      Parameters:
      declaringClass - The class that declares this method.
      c - The constructor being wrapped.
  • Method Details

    • of

      public static ConstructorInfo of(ClassInfo declaringClass, Constructor<?> c)
      Convenience method for instantiating a ConstructorInfo;
      Parameters:
      declaringClass - The class that declares this method.
      c - The constructor being wrapped.
      Returns:
      A new ConstructorInfo object, or null if the method was null;
    • of

      public static ConstructorInfo of(Constructor<?> c)
      Convenience method for instantiating a ConstructorInfo;
      Parameters:
      c - The constructor being wrapped.
      Returns:
      A new ConstructorInfo object, or null if the method was null;
    • inner

      public <T> Constructor<T> inner()
      Returns the wrapped method.
      Type Parameters:
      T - The inner class type.
      Returns:
      The wrapped method.
    • getAnnotation

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

      public final <A extends Annotation> A getAnnotation(AnnotationProvider annotationProvider, Class<A> type)
      Finds the annotation of the specified type defined on this constructor.
      Type Parameters:
      A - The annotation type to look for.
      Parameters:
      annotationProvider - The annotation provider.
      type - The annotation to look for.
      Returns:
      The first annotation found, or null if it doesn't exist.
    • hasAnnotation

      public final <A extends Annotation> boolean hasAnnotation(Class<A> type)
      Returns true if the specified annotation is present on this constructor.
      Type Parameters:
      A - The annotation type to look for.
      Parameters:
      type - The annotation to look for.
      Returns:
      true if the specified annotation is present on this constructor.
    • hasAnnotation

      public final <A extends Annotation> boolean hasAnnotation(AnnotationProvider annotationProvider, Class<A> type)
      Returns true if the specified annotation is present on this constructor.
      Type Parameters:
      A - The annotation type to look for.
      Parameters:
      annotationProvider - The annotation provider.
      type - The annotation to look for.
      Returns:
      true if the specified annotation is present on this constructor.
    • hasNoAnnotation

      public final <A extends Annotation> boolean hasNoAnnotation(AnnotationProvider annotationProvider, Class<A> type)
      Returns true if the specified annotation is not present on this constructor.
      Type Parameters:
      A - The annotation type to look for.
      Parameters:
      annotationProvider - The annotation provider.
      type - The annotation to look for.
      Returns:
      true if the specified annotation is not present on this constructor.
    • matches

      public boolean matches(Predicate<ConstructorInfo> 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.
    • canAccept

      public boolean canAccept(Object... args)
      Returns true if this constructor can accept the specified arguments in the specified order.
      Parameters:
      args - The arguments to check.
      Returns:
      true if this constructor can accept the specified arguments in the specified order.
    • invokeFuzzy

      public <T> T invokeFuzzy(Object... args) throws ExecutableException
      Shortcut for calling the new-instance method on the underlying constructor.
      Type Parameters:
      T - The constructor class type.
      Parameters:
      args - the arguments used for the method call.
      Extra parameters are ignored.
      Missing parameters are set to null.
      Returns:
      The object returned from the constructor.
      Throws:
      ExecutableException - Exception occurred on invoked constructor/method/field.
    • invoke

      public <T> T invoke(Object... args) throws ExecutableException
      Shortcut for calling the new-instance method on the underlying constructor.
      Type Parameters:
      T - The constructor class type.
      Parameters:
      args - the arguments used for the method call.
      Returns:
      The object returned from the constructor.
      Throws:
      ExecutableException - Exception occurred on invoked constructor/method/field.
    • accessible

      Makes constructor accessible if it matches the visibility requirements, or returns null if it doesn't.

      Security exceptions thrown on the call to Constructor.setAccessible(boolean) are quietly ignored.

      Parameters:
      v - The minimum visibility.
      Returns:
      The same constructor if visibility requirements met, or null if visibility requirement not met or call to Constructor.setAccessible(boolean) throws a security exception.
    • compareTo

      public int compareTo(ConstructorInfo o)
      Specified by:
      compareTo in interface Comparable<ConstructorInfo>
    • accessible

      Description copied from class: ExecutableInfo
      Attempts to call x.setAccessible(true) and quietly ignores security exceptions.
      Overrides:
      accessible in class ExecutableInfo
      Returns:
      This object.