Merge branch '6.1.x'
This commit is contained in:
commit
fc28926c15
|
@ -58,7 +58,7 @@ class CodeWarnings {
|
|||
*/
|
||||
public CodeWarnings detectDeprecation(AnnotatedElement... elements) {
|
||||
for (AnnotatedElement element : elements) {
|
||||
register(element.getAnnotation(Deprecated.class));
|
||||
registerDeprecationIfNecessary(element);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -112,6 +112,16 @@ class CodeWarnings {
|
|||
return Collections.unmodifiableSet(this.warnings);
|
||||
}
|
||||
|
||||
private void registerDeprecationIfNecessary(@Nullable AnnotatedElement element) {
|
||||
if (element == null) {
|
||||
return;
|
||||
}
|
||||
register(element.getAnnotation(Deprecated.class));
|
||||
if (element instanceof Class<?> type) {
|
||||
registerDeprecationIfNecessary(type.getEnclosingClass());
|
||||
}
|
||||
}
|
||||
|
||||
private void register(@Nullable Deprecated annotation) {
|
||||
if (annotation != null) {
|
||||
if (annotation.forRemoval()) {
|
||||
|
|
|
@ -91,6 +91,13 @@ class CodeWarningsTests {
|
|||
assertThat(this.codeWarnings.getWarnings()).containsOnly("deprecation");
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void detectDeprecationOnAnnotatedElementWhoseEnclosingElementIsDeprecated() {
|
||||
this.codeWarnings.detectDeprecation(DeprecatedBean.Nested.class);
|
||||
assertThat(this.codeWarnings.getWarnings()).containsExactly("deprecation");
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("removal")
|
||||
void detectDeprecationOnAnnotatedElementWithDeprecatedForRemoval() {
|
||||
|
@ -98,6 +105,13 @@ class CodeWarningsTests {
|
|||
assertThat(this.codeWarnings.getWarnings()).containsOnly("removal");
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("removal")
|
||||
void detectDeprecationOnAnnotatedElementWhoseEnclosingElementIsDeprecatedForRemoval() {
|
||||
this.codeWarnings.detectDeprecation(DeprecatedForRemovalBean.Nested.class);
|
||||
assertThat(this.codeWarnings.getWarnings()).containsExactly("removal");
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("resolvableTypesWithDeprecated")
|
||||
void detectDeprecationOnResolvableTypeWithDeprecated(ResolvableType resolvableType) {
|
||||
|
@ -107,11 +121,17 @@ class CodeWarningsTests {
|
|||
|
||||
@SuppressWarnings("deprecation")
|
||||
static Stream<Arguments> resolvableTypesWithDeprecated() {
|
||||
Class<?> deprecatedBean = DeprecatedBean.class;
|
||||
Class<?> nested = DeprecatedBean.Nested.class;
|
||||
return Stream.of(
|
||||
Arguments.of(ResolvableType.forClass(DeprecatedBean.class)),
|
||||
Arguments.of(ResolvableType.forClassWithGenerics(GenericBean.class, DeprecatedBean.class)),
|
||||
Arguments.of(ResolvableType.forClass(deprecatedBean)),
|
||||
Arguments.of(ResolvableType.forClass(nested)),
|
||||
Arguments.of(ResolvableType.forClassWithGenerics(GenericBean.class, deprecatedBean)),
|
||||
Arguments.of(ResolvableType.forClassWithGenerics(GenericBean.class, nested)),
|
||||
Arguments.of(ResolvableType.forClassWithGenerics(GenericBean.class,
|
||||
ResolvableType.forClassWithGenerics(GenericBean.class, DeprecatedBean.class)))
|
||||
ResolvableType.forClassWithGenerics(GenericBean.class, deprecatedBean))),
|
||||
Arguments.of(ResolvableType.forClassWithGenerics(GenericBean.class,
|
||||
ResolvableType.forClassWithGenerics(GenericBean.class, nested)))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -124,11 +144,17 @@ class CodeWarningsTests {
|
|||
|
||||
@SuppressWarnings("removal")
|
||||
static Stream<Arguments> resolvableTypesWithDeprecatedForRemoval() {
|
||||
Class<?> deprecatedBean = DeprecatedForRemovalBean.class;
|
||||
Class<?> nested = DeprecatedForRemovalBean.Nested.class;
|
||||
return Stream.of(
|
||||
Arguments.of(ResolvableType.forClass(DeprecatedForRemovalBean.class)),
|
||||
Arguments.of(ResolvableType.forClassWithGenerics(GenericBean.class, DeprecatedForRemovalBean.class)),
|
||||
Arguments.of(ResolvableType.forClass(deprecatedBean)),
|
||||
Arguments.of(ResolvableType.forClass(nested)),
|
||||
Arguments.of(ResolvableType.forClassWithGenerics(GenericBean.class, deprecatedBean)),
|
||||
Arguments.of(ResolvableType.forClassWithGenerics(GenericBean.class, nested)),
|
||||
Arguments.of(ResolvableType.forClassWithGenerics(GenericBean.class,
|
||||
ResolvableType.forClassWithGenerics(GenericBean.class, DeprecatedForRemovalBean.class)))
|
||||
ResolvableType.forClassWithGenerics(GenericBean.class, deprecatedBean))),
|
||||
Arguments.of(ResolvableType.forClassWithGenerics(GenericBean.class,
|
||||
ResolvableType.forClassWithGenerics(GenericBean.class, nested)))
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 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.
|
||||
|
@ -23,4 +23,8 @@ package org.springframework.beans.testfixture.beans.factory.generator.deprecatio
|
|||
*/
|
||||
@Deprecated
|
||||
public class DeprecatedBean {
|
||||
|
||||
// This isn't flag deprecated on purpose
|
||||
public static class Nested {}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 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.
|
||||
|
@ -23,4 +23,7 @@ package org.springframework.beans.testfixture.beans.factory.generator.deprecatio
|
|||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public class DeprecatedForRemovalBean {
|
||||
|
||||
// This isn't flag deprecated on purpose
|
||||
public static class Nested {}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue