@ -39,25 +39,19 @@ class DefaultBindConstructorProvider implements BindConstructorProvider {
@Override
@Override
public Constructor < ? > getBindConstructor ( Bindable < ? > bindable , boolean isNestedConstructorBinding ) {
public Constructor < ? > getBindConstructor ( Bindable < ? > bindable , boolean isNestedConstructorBinding ) {
return getBindConstructor ( bindable . getType ( ) . resolve ( ) , bindable . hasExistingValu e( ) ,
Constructors constructors = Constructors . getConstructors ( bindable . getType ( ) . resolv e( ) ,
isNestedConstructorBinding ) ;
isNestedConstructorBinding ) ;
if ( constructors . getBind ( ) ! = null & & constructors . isDeducedBindConstructor ( ) ) {
if ( bindable . getValue ( ) ! = null & & bindable . getValue ( ) . get ( ) ! = null ) {
return null ;
}
}
return constructors . getBind ( ) ;
}
}
@Override
@Override
public Constructor < ? > getBindConstructor ( Class < ? > type , boolean isNestedConstructorBinding ) {
public Constructor < ? > getBindConstructor ( Class < ? > type , boolean isNestedConstructorBinding ) {
return getBindConstructor ( type , false , isNestedConstructorBinding ) ;
Constructors constructors = Constructors . getConstructors ( type , isNestedConstructorBinding ) ;
}
private Constructor < ? > getBindConstructor ( Class < ? > type , boolean hasExistingValue ,
boolean isNestedConstructorBinding ) {
if ( type = = null | | hasExistingValue ) {
return null ;
}
Constructors constructors = Constructors . getConstructors ( type ) ;
if ( constructors . getBind ( ) ! = null | | isNestedConstructorBinding ) {
Assert . state ( ! constructors . hasAutowired ( ) ,
( ) - > type . getName ( ) + " declares @ConstructorBinding and @Autowired constructor" ) ;
}
return constructors . getBind ( ) ;
return constructors . getBind ( ) ;
}
}
@ -66,13 +60,18 @@ class DefaultBindConstructorProvider implements BindConstructorProvider {
* /
* /
static final class Constructors {
static final class Constructors {
private static final Constructors NONE = new Constructors ( false , null , false ) ;
private final boolean hasAutowired ;
private final boolean hasAutowired ;
private final Constructor < ? > bind ;
private final Constructor < ? > bind ;
private Constructors ( boolean hasAutowired , Constructor < ? > bind ) {
private final boolean deducedBindConstructor ;
private Constructors ( boolean hasAutowired , Constructor < ? > bind , boolean deducedBindConstructor ) {
this . hasAutowired = hasAutowired ;
this . hasAutowired = hasAutowired ;
this . bind = bind ;
this . bind = bind ;
this . deducedBindConstructor = deducedBindConstructor ;
}
}
boolean hasAutowired ( ) {
boolean hasAutowired ( ) {
@ -83,18 +82,32 @@ class DefaultBindConstructorProvider implements BindConstructorProvider {
return this . bind ;
return this . bind ;
}
}
static Constructors getConstructors ( Class < ? > type ) {
boolean isDeducedBindConstructor ( ) {
return this . deducedBindConstructor ;
}
static Constructors getConstructors ( Class < ? > type , boolean isNestedConstructorBinding ) {
if ( type = = null ) {
return NONE ;
}
boolean hasAutowiredConstructor = isAutowiredPresent ( type ) ;
boolean hasAutowiredConstructor = isAutowiredPresent ( type ) ;
Constructor < ? > [ ] candidates = getCandidateConstructors ( type ) ;
Constructor < ? > [ ] candidates = getCandidateConstructors ( type ) ;
MergedAnnotations [ ] candidateAnnotations = getAnnotations ( candidates ) ;
MergedAnnotations [ ] candidateAnnotations = getAnnotations ( candidates ) ;
boolean deducedBindConstructor = false ;
Constructor < ? > bind = getConstructorBindingAnnotated ( type , candidates , candidateAnnotations ) ;
Constructor < ? > bind = getConstructorBindingAnnotated ( type , candidates , candidateAnnotations ) ;
if ( bind = = null & & ! hasAutowiredConstructor ) {
if ( bind = = null & & ! hasAutowiredConstructor ) {
bind = deduceBindConstructor ( type , candidates ) ;
bind = deduceBindConstructor ( type , candidates ) ;
deducedBindConstructor = bind ! = null ;
}
}
if ( bind = = null & & ! hasAutowiredConstructor & & isKotlinType ( type ) ) {
if ( bind = = null & & ! hasAutowiredConstructor & & isKotlinType ( type ) ) {
bind = deduceKotlinBindConstructor ( type ) ;
bind = deduceKotlinBindConstructor ( type ) ;
deducedBindConstructor = bind ! = null ;
}
if ( bind ! = null | | isNestedConstructorBinding ) {
Assert . state ( ! hasAutowiredConstructor ,
( ) - > type . getName ( ) + " declares @ConstructorBinding and @Autowired constructor" ) ;
}
}
return new Constructors ( hasAutowiredConstructor , bind ) ;
return new Constructors ( hasAutowiredConstructor , bind , deducedBindConstructor ) ;
}
}
private static boolean isAutowiredPresent ( Class < ? > type ) {
private static boolean isAutowiredPresent ( Class < ? > type ) {