Detect use of deprecated API

This commit is a best effort attempt at identifying the members that
code generation invokes and might be deprecated. It introduces
a CodeWarnings helper class that records warnings, with special
handling for `@Deprecated`.

See gh-29597
This commit is contained in:
Stéphane Nicoll
2023-10-10 14:52:18 +02:00
parent 35372e5e72
commit ea66883d79
12 changed files with 614 additions and 3 deletions

View File

@@ -0,0 +1,27 @@
/*
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.beans.testfixture.beans.factory.generator.deprecation;
/**
* A sample bean that's fully deprecated.
*
* @author Stephane Nicoll
*/
@Deprecated
public class DeprecatedBean {
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.beans.testfixture.beans.factory.generator.deprecation;
import org.springframework.core.env.Environment;
/**
* A sample whose factory method (constructor) is deprecated.
*
* @author Stephane Nicoll
*/
public class DeprecatedConstructor {
@Deprecated
public DeprecatedConstructor(Environment environment) {
}
}

View File

@@ -0,0 +1,27 @@
/*
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.beans.testfixture.beans.factory.generator.deprecation;
/**
* A sample bean that's fully deprecated for removal.
*
* @author Stephane Nicoll
*/
@Deprecated(forRemoval = true)
public class DeprecatedForRemovalBean {
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.beans.testfixture.beans.factory.generator.deprecation;
import org.springframework.core.env.Environment;
/**
* A sample whose factory method (constructor) is deprecated for removal
*
* @author Stephane Nicoll
*/
public class DeprecatedForRemovalConstructor {
@Deprecated(forRemoval = true)
public DeprecatedForRemovalConstructor(Environment environment) {
}
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.beans.testfixture.beans.factory.generator.deprecation;
/**
* A class with deprecated members for removal to test various use cases.
*
* @author Stephane Nicoll
*/
public class DeprecatedForRemovalMemberConfiguration {
@Deprecated(forRemoval = true)
public String deprecatedString() {
return "deprecated";
}
public String deprecatedParameter(DeprecatedForRemovalBean bean) {
return bean.toString();
}
}

View File

@@ -0,0 +1,40 @@
/*
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.beans.testfixture.beans.factory.generator.deprecation;
/**
* A class with deprecated members to test various use cases.
*
* @author Stephane Nicoll
*/
public class DeprecatedMemberConfiguration {
@Deprecated
public String deprecatedString() {
return "deprecated";
}
public String deprecatedParameter(DeprecatedBean bean) {
return bean.toString();
}
public DeprecatedBean deprecatedReturnType() {
return new DeprecatedBean();
}
}