Interface Binding


  • public interface Binding
    Bindings represent targets where values can be injected into an instance. This can be a field or one of the parameters of a method or constructor.

    Target

    The target of a binding is determined by the AccessibleObject and the given Parameter, it can be:
    • A constructor. The parameter indicates which constructor parameter is the target.
    • A method. The parameter indicates which method parameter is the target.
    • A field. Parameter is null.
    • An owner class. In order to access non-static methods and fields the owner class is required as a binding. Both the parameter and the accessible object are null in this case.
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      <T> T associateIfAbsent​(java.lang.String key, java.util.function.Supplier<T> valueSupplier)
      Associate extra data with this binding.
      java.lang.reflect.AccessibleObject getAccessibleObject()
      Returns the target AccessibleObject for the binding.
      default java.lang.reflect.AnnotatedElement getAnnotatedElement()
      Returns the associated AnnotatedElement for this binding.
      Key getElementKey()
      Returns the Key of which individual elements of the injection target consist.
      java.lang.reflect.Parameter getParameter()
      Returns the Parameter when the AccessibleObject is a constructor or a method.
      default java.util.Set<java.lang.annotation.Annotation> getQualifiers()
      Returns the qualifiers on the injection target.
      java.lang.reflect.Type getType()
      Returns the Type of the injection target.
      java.util.Set<TypeTrait> getTypeTraits()
      Returns the TypeTraits of this binding.
      boolean isOptional()
      Returns whether this target accepts null as an injection value.
    • Method Detail

      • getType

        java.lang.reflect.Type getType()
        Returns the Type of the injection target.
        Returns:
        the Type of the injection target, never null
      • getQualifiers

        default java.util.Set<java.lang.annotation.Annotation> getQualifiers()
        Returns the qualifiers on the injection target.
        Returns:
        a set of qualifier annotations, never null and never contains null
      • isOptional

        boolean isOptional()
        Returns whether this target accepts null as an injection value. Normally null is rejected with UnsatisfiedResolutionException, but optional targets treat null differently. If the target is a method or constructor parameters, null is simply provided, leaving it up to the receiver to deal with the null. For fields, the injection is skipped leaving its default value intact.
        Returns:
        true if the target is optional, otherwise false
      • getElementKey

        Key getElementKey()
        Returns the Key of which individual elements of the injection target consist. For simple types, this will be the same as the injection target's type. For types which are provided by an injection target extension, this will be base type that is looked up for injection.
        Returns:
        a Key, never null
      • getAccessibleObject

        java.lang.reflect.AccessibleObject getAccessibleObject()
        Returns the target AccessibleObject for the binding. This is null when the binding refers to the declaring class which is required to access a non-static field or method.
        Returns:
        the target @link AccessibleObject} for the binding, can be null
      • getParameter

        java.lang.reflect.Parameter getParameter()
        Returns the Parameter when the AccessibleObject is a constructor or a method. Returns @{code null} for fields.
        Returns:
        a Parameter, can be null
      • getAnnotatedElement

        default java.lang.reflect.AnnotatedElement getAnnotatedElement()
        Returns the associated AnnotatedElement for this binding. This is null for owner bindings.
        Returns:
        the associated AnnotatedElement for this binding, can be null
      • getTypeTraits

        java.util.Set<TypeTrait> getTypeTraits()
        Returns the TypeTraits of this binding.
        Returns:
        a set of TypeTrait, never null
      • associateIfAbsent

        <T> T associateIfAbsent​(java.lang.String key,
                                java.util.function.Supplier<T> valueSupplier)
        Associate extra data with this binding. Currently only used for the instantiation contexts. Using binding in a WeakHashMap as key will too easily lead to bindings not being GC'd as these refer to type, which in turn is used in another WeakHashMap (see DefaultDiscoveryFactory). Likely to be replaced with a better solution later.
        Type Parameters:
        T - type of data to associate
        Parameters:
        key - a string key, cannot be null
        valueSupplier - a Supplier for the value if the key does not exist yet, cannot be null
        Returns:
        the current associated value, can be null if value supplied was null