public class DependencyDescriptor extends InjectionPoint implements java.io.Serializable
field, methodParameter
Constructor and Description |
---|
DependencyDescriptor(DependencyDescriptor original)
Copy constructor.
|
DependencyDescriptor(java.lang.reflect.Field field,
boolean required)
Create a new descriptor for a field.
|
DependencyDescriptor(java.lang.reflect.Field field,
boolean required,
boolean eager)
Create a new descriptor for a field.
|
DependencyDescriptor(MethodParameter methodParameter,
boolean required)
Create a new descriptor for a method or constructor parameter.
|
DependencyDescriptor(MethodParameter methodParameter,
boolean required,
boolean eager)
Create a new descriptor for a method or constructor parameter.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object other) |
boolean |
fallbackMatchAllowed()
Return whether a fallback match is allowed.
|
DependencyDescriptor |
forFallbackMatch()
Return a variant of this descriptor that is intended for a fallback match.
|
java.lang.String |
getDependencyName()
Determine the name of the wrapped parameter/field.
|
java.lang.Class<?> |
getDependencyType()
Determine the declared (non-generic) type of the wrapped parameter/field.
|
ResolvableType |
getResolvableType()
Build a ResolvableType object for the wrapped parameter/field.
|
int |
hashCode() |
void |
increaseNestingLevel()
Increase this descriptor's nesting level.
|
void |
initParameterNameDiscovery(ParameterNameDiscoverer parameterNameDiscoverer)
Initialize parameter name discovery for the underlying method parameter, if any.
|
boolean |
isEager()
Return whether this dependency is 'eager' in the sense of
eagerly resolving potential target beans for type matching.
|
boolean |
isRequired()
Return whether this dependency is required.
|
boolean |
isStreamAccess()
Return whether this descriptor allows for stream-style access to
result instances.
|
java.lang.Object |
resolveCandidate(java.lang.String beanName,
java.lang.Class<?> requiredType,
BeanFactory beanFactory)
Resolve the specified bean name, as a candidate result of the matching
algorithm for this dependency, to a bean instance from the given factory.
|
java.lang.Object |
resolveNotUnique(java.lang.Class<?> type,
java.util.Map<java.lang.String,java.lang.Object> matchingBeans)
Deprecated.
as of 5.1, in favor of
resolveNotUnique(ResolvableType, Map) |
java.lang.Object |
resolveNotUnique(ResolvableType type,
java.util.Map<java.lang.String,java.lang.Object> matchingBeans)
Resolve the specified not-unique scenario: by default,
throwing a
NoUniqueBeanDefinitionException . |
java.lang.Object |
resolveShortcut(BeanFactory beanFactory)
Resolve a shortcut for this dependency against the given factory, for example
taking some pre-resolved information into account.
|
void |
setContainingClass(java.lang.Class<?> containingClass)
Optionally set the concrete class that contains this dependency.
|
getAnnotatedElement, getAnnotation, getAnnotations, getDeclaredType, getField, getMember, getMethodParameter, obtainMethodParameter, toString
public DependencyDescriptor(MethodParameter methodParameter, boolean required)
methodParameter
- the MethodParameter to wraprequired
- whether the dependency is requiredpublic DependencyDescriptor(MethodParameter methodParameter, boolean required, boolean eager)
methodParameter
- the MethodParameter to wraprequired
- whether the dependency is requiredeager
- whether this dependency is 'eager' in the sense of
eagerly resolving potential target beans for type matchingpublic DependencyDescriptor(java.lang.reflect.Field field, boolean required)
field
- the field to wraprequired
- whether the dependency is requiredpublic DependencyDescriptor(java.lang.reflect.Field field, boolean required, boolean eager)
field
- the field to wraprequired
- whether the dependency is requiredeager
- whether this dependency is 'eager' in the sense of
eagerly resolving potential target beans for type matchingpublic DependencyDescriptor(DependencyDescriptor original)
original
- the original descriptor to create a copy frompublic boolean isRequired()
Optional semantics are derived from Java 8's Optional
,
any variant of a parameter-level Nullable
annotation (such as from
JSR-305 or the FindBugs set of annotations), or a language-level nullable
type declaration in Kotlin.
public boolean isEager()
public boolean isStreamAccess()
By default, dependencies are strictly resolved to the declaration of
the injection point and therefore only resolve multiple entries if the
injection point is declared as an array, collection or map. This is
indicated by returning false
here.
Overriding this method to return true
indicates that the
injection point declares the bean type but the resolution is meant to
end up in a Stream
for the declared bean type,
with the caller handling the multi-instance case for the injection point.
@Nullable public java.lang.Object resolveNotUnique(ResolvableType type, java.util.Map<java.lang.String,java.lang.Object> matchingBeans) throws BeansException
NoUniqueBeanDefinitionException
.
Subclasses may override this to select one of the instances or
to opt out with no result at all through returning null
.
type
- the requested bean typematchingBeans
- a map of bean names and corresponding bean
instances which have been pre-selected for the given type
(qualifiers etc already applied)null
for noneBeansException
- in case of the not-unique scenario being fatal@Deprecated @Nullable public java.lang.Object resolveNotUnique(java.lang.Class<?> type, java.util.Map<java.lang.String,java.lang.Object> matchingBeans) throws BeansException
resolveNotUnique(ResolvableType, Map)
NoUniqueBeanDefinitionException
.
Subclasses may override this to select one of the instances or
to opt out with no result at all through returning null
.
type
- the requested bean typematchingBeans
- a map of bean names and corresponding bean
instances which have been pre-selected for the given type
(qualifiers etc already applied)null
for noneBeansException
- in case of the not-unique scenario being fatal@Nullable public java.lang.Object resolveShortcut(BeanFactory beanFactory) throws BeansException
The resolution algorithm will first attempt to resolve a shortcut through this
method before going into the regular type matching algorithm across all beans.
Subclasses may override this method to improve resolution performance based on
pre-cached information while still receiving InjectionPoint
exposure etc.
beanFactory
- the associated factorynull
if noneBeansException
- if the shortcut could not be obtainedpublic java.lang.Object resolveCandidate(java.lang.String beanName, java.lang.Class<?> requiredType, BeanFactory beanFactory) throws BeansException
The default implementation calls BeanFactory.getBean(String)
.
Subclasses may provide additional arguments or other customizations.
beanName
- the bean name, as a candidate result for this dependencyrequiredType
- the expected type of the bean (as an assertion)beanFactory
- the associated factorynull
)BeansException
- if the bean could not be obtainedBeanFactory.getBean(String)
public void increaseNestingLevel()
MethodParameter.increaseNestingLevel()
public void setContainingClass(java.lang.Class<?> containingClass)
public ResolvableType getResolvableType()
public boolean fallbackMatchAllowed()
This is false
by default but may be overridden to return true
in order
to suggest to an AutowireCandidateResolver
that a fallback match is acceptable as well.
public DependencyDescriptor forFallbackMatch()
fallbackMatchAllowed()
public void initParameterNameDiscovery(@Nullable ParameterNameDiscoverer parameterNameDiscoverer)
This method does not actually try to retrieve the parameter name at
this point; it just allows discovery to happen when the application calls
getDependencyName()
(if ever).
@Nullable public java.lang.String getDependencyName()
null
)public java.lang.Class<?> getDependencyType()
null
)public boolean equals(java.lang.Object other)
equals
in class InjectionPoint
public int hashCode()
hashCode
in class InjectionPoint