63
63
import org .springframework .beans .factory .aot .BeanRegistrationAotContribution ;
64
64
import org .springframework .beans .factory .aot .BeanRegistrationAotProcessor ;
65
65
import org .springframework .beans .factory .aot .BeanRegistrationCode ;
66
+ import org .springframework .beans .factory .aot .CodeWarnings ;
66
67
import org .springframework .beans .factory .config .ConfigurableListableBeanFactory ;
67
68
import org .springframework .beans .factory .config .DependencyDescriptor ;
68
69
import org .springframework .beans .factory .config .SmartInstantiationAwareBeanPostProcessor ;
@@ -984,8 +985,11 @@ public void applyTo(GenerationContext generationContext, BeanRegistrationCode be
984
985
method .addParameter (RegisteredBean .class , REGISTERED_BEAN_PARAMETER );
985
986
method .addParameter (this .target , INSTANCE_PARAMETER );
986
987
method .returns (this .target );
987
- method .addCode (generateMethodCode (generatedClass .getName (),
988
- generationContext .getRuntimeHints ()));
988
+ CodeWarnings codeWarnings = new CodeWarnings ();
989
+ codeWarnings .detectDeprecation (this .target );
990
+ method .addCode (generateMethodCode (codeWarnings ,
991
+ generatedClass .getName (), generationContext .getRuntimeHints ()));
992
+ codeWarnings .suppress (method );
989
993
});
990
994
beanRegistrationCode .addInstancePostProcessor (generateMethod .toMethodReference ());
991
995
@@ -994,35 +998,37 @@ public void applyTo(GenerationContext generationContext, BeanRegistrationCode be
994
998
}
995
999
}
996
1000
997
- private CodeBlock generateMethodCode (ClassName targetClassName , RuntimeHints hints ) {
1001
+ private CodeBlock generateMethodCode (CodeWarnings codeWarnings ,
1002
+ ClassName targetClassName , RuntimeHints hints ) {
1003
+
998
1004
CodeBlock .Builder code = CodeBlock .builder ();
999
1005
for (AutowiredElement autowiredElement : this .autowiredElements ) {
1000
1006
code .addStatement (generateMethodStatementForElement (
1001
- targetClassName , autowiredElement , hints ));
1007
+ codeWarnings , targetClassName , autowiredElement , hints ));
1002
1008
}
1003
1009
code .addStatement ("return $L" , INSTANCE_PARAMETER );
1004
1010
return code .build ();
1005
1011
}
1006
1012
1007
- private CodeBlock generateMethodStatementForElement (ClassName targetClassName ,
1008
- AutowiredElement autowiredElement , RuntimeHints hints ) {
1013
+ private CodeBlock generateMethodStatementForElement (CodeWarnings codeWarnings ,
1014
+ ClassName targetClassName , AutowiredElement autowiredElement , RuntimeHints hints ) {
1009
1015
1010
1016
Member member = autowiredElement .getMember ();
1011
1017
boolean required = autowiredElement .required ;
1012
1018
if (member instanceof Field field ) {
1013
1019
return generateMethodStatementForField (
1014
- targetClassName , field , required , hints );
1020
+ codeWarnings , targetClassName , field , required , hints );
1015
1021
}
1016
1022
if (member instanceof Method method ) {
1017
1023
return generateMethodStatementForMethod (
1018
- targetClassName , method , required , hints );
1024
+ codeWarnings , targetClassName , method , required , hints );
1019
1025
}
1020
1026
throw new IllegalStateException (
1021
1027
"Unsupported member type " + member .getClass ().getName ());
1022
1028
}
1023
1029
1024
- private CodeBlock generateMethodStatementForField (ClassName targetClassName ,
1025
- Field field , boolean required , RuntimeHints hints ) {
1030
+ private CodeBlock generateMethodStatementForField (CodeWarnings codeWarnings ,
1031
+ ClassName targetClassName , Field field , boolean required , RuntimeHints hints ) {
1026
1032
1027
1033
hints .reflection ().registerField (field );
1028
1034
CodeBlock resolver = CodeBlock .of ("$T.$L($S)" ,
@@ -1033,18 +1039,22 @@ private CodeBlock generateMethodStatementForField(ClassName targetClassName,
1033
1039
return CodeBlock .of ("$L.resolveAndSet($L, $L)" , resolver ,
1034
1040
REGISTERED_BEAN_PARAMETER , INSTANCE_PARAMETER );
1035
1041
}
1036
- return CodeBlock .of ("$L.$L = $L.resolve($L)" , INSTANCE_PARAMETER ,
1037
- field .getName (), resolver , REGISTERED_BEAN_PARAMETER );
1042
+ else {
1043
+ codeWarnings .detectDeprecation (field );
1044
+ return CodeBlock .of ("$L.$L = $L.resolve($L)" , INSTANCE_PARAMETER ,
1045
+ field .getName (), resolver , REGISTERED_BEAN_PARAMETER );
1046
+ }
1038
1047
}
1039
1048
1040
- private CodeBlock generateMethodStatementForMethod (ClassName targetClassName ,
1041
- Method method , boolean required , RuntimeHints hints ) {
1049
+ private CodeBlock generateMethodStatementForMethod (CodeWarnings codeWarnings ,
1050
+ ClassName targetClassName , Method method , boolean required , RuntimeHints hints ) {
1042
1051
1043
1052
CodeBlock .Builder code = CodeBlock .builder ();
1044
1053
code .add ("$T.$L" , AutowiredMethodArgumentsResolver .class ,
1045
1054
(!required ? "forMethod" : "forRequiredMethod" ));
1046
1055
code .add ("($S" , method .getName ());
1047
1056
if (method .getParameterCount () > 0 ) {
1057
+ codeWarnings .detectDeprecation (method .getParameterTypes ());
1048
1058
code .add (", $L" , generateParameterTypesCode (method .getParameterTypes ()));
1049
1059
}
1050
1060
code .add (")" );
@@ -1054,6 +1064,7 @@ private CodeBlock generateMethodStatementForMethod(ClassName targetClassName,
1054
1064
code .add (".resolveAndInvoke($L, $L)" , REGISTERED_BEAN_PARAMETER , INSTANCE_PARAMETER );
1055
1065
}
1056
1066
else {
1067
+ codeWarnings .detectDeprecation (method );
1057
1068
hints .reflection ().registerMethod (method , ExecutableMode .INTROSPECT );
1058
1069
CodeBlock arguments = new AutowiredArgumentsCodeGenerator (this .target ,
1059
1070
method ).generateCode (method .getParameterTypes ());
0 commit comments