Package org.int4.dirk.core.definition
Interface Binding
-
public interface BindingBindings 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 theAccessibleObjectand the givenParameter, 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
nullin this case.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description <T> TassociateIfAbsent(java.lang.String key, java.util.function.Supplier<T> valueSupplier)Associate extra data with this binding.java.lang.reflect.AccessibleObjectgetAccessibleObject()Returns the targetAccessibleObjectfor the binding.default java.lang.reflect.AnnotatedElementgetAnnotatedElement()Returns the associatedAnnotatedElementfor this binding.KeygetElementKey()Returns theKeyof which individual elements of the injection target consist.java.lang.reflect.ParametergetParameter()Returns theParameterwhen theAccessibleObjectis a constructor or a method.default java.util.Set<java.lang.annotation.Annotation>getQualifiers()Returns the qualifiers on the injection target.java.lang.reflect.TypegetType()Returns theTypeof the injection target.java.util.Set<TypeTrait>getTypeTraits()Returns theTypeTraits of this binding.booleanisOptional()Returns whether this target acceptsnullas an injection value.
-
-
-
Method Detail
-
getType
java.lang.reflect.Type getType()
Returns theTypeof the injection target.- Returns:
- the
Typeof the injection target, nevernull
-
getQualifiers
default java.util.Set<java.lang.annotation.Annotation> getQualifiers()
Returns the qualifiers on the injection target.- Returns:
- a set of qualifier annotations, never
nulland never containsnull
-
isOptional
boolean isOptional()
Returns whether this target acceptsnullas an injection value. Normallynullis rejected withUnsatisfiedResolutionException, but optional targets treatnulldifferently. If the target is a method or constructor parameters,nullis simply provided, leaving it up to the receiver to deal with thenull. For fields, the injection is skipped leaving its default value intact.- Returns:
trueif the target is optional, otherwisefalse
-
getElementKey
Key getElementKey()
Returns theKeyof 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, nevernull
-
getAccessibleObject
java.lang.reflect.AccessibleObject getAccessibleObject()
Returns the targetAccessibleObjectfor the binding. This isnullwhen 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 theParameterwhen theAccessibleObjectis a constructor or a method. Returns @{code null} for fields.- Returns:
- a
Parameter, can benull
-
getAnnotatedElement
default java.lang.reflect.AnnotatedElement getAnnotatedElement()
Returns the associatedAnnotatedElementfor this binding. This isnullfor owner bindings.- Returns:
- the associated
AnnotatedElementfor this binding, can benull
-
getTypeTraits
java.util.Set<TypeTrait> getTypeTraits()
Returns theTypeTraits of this binding.- Returns:
- a set of
TypeTrait, nevernull
-
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 benullvalueSupplier- aSupplierfor the value if the key does not exist yet, cannot benull- Returns:
- the current associated value, can be
nullif value supplied wasnull
-
-