Skip to content

Commit

Permalink
Merge branch '6.1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed Jul 25, 2024
2 parents 65faca8 + 5284981 commit fc28926
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void register(String warning) {
*/
public CodeWarnings detectDeprecation(AnnotatedElement... elements) {
for (AnnotatedElement element : elements) {
register(element.getAnnotation(Deprecated.class));
registerDeprecationIfNecessary(element);
}
return this;
}
Expand Down Expand Up @@ -112,6 +112,16 @@ protected Set<String> getWarnings() {
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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,27 @@ void detectDeprecationOnAnnotatedElementWithDeprecated() {
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() {
this.codeWarnings.detectDeprecation(DeprecatedForRemovalBean.class);
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) {
Expand All @@ -107,11 +121,17 @@ void detectDeprecationOnResolvableTypeWithDeprecated(ResolvableType resolvableTy

@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))),
Arguments.of(ResolvableType.forClassWithGenerics(GenericBean.class,
ResolvableType.forClassWithGenerics(GenericBean.class, DeprecatedBean.class)))
ResolvableType.forClassWithGenerics(GenericBean.class, nested)))
);
}

Expand All @@ -124,11 +144,17 @@ void detectDeprecationOnResolvableTypeWithDeprecatedForRemoval(ResolvableType re

@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, deprecatedBean))),
Arguments.of(ResolvableType.forClassWithGenerics(GenericBean.class,
ResolvableType.forClassWithGenerics(GenericBean.class, DeprecatedForRemovalBean.class)))
ResolvableType.forClassWithGenerics(GenericBean.class, nested)))
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -23,4 +23,8 @@
*/
@Deprecated
public class DeprecatedBean {

// This isn't flag deprecated on purpose
public static class Nested {}

}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -23,4 +23,7 @@
*/
@Deprecated(forRemoval = true)
public class DeprecatedForRemovalBean {

// This isn't flag deprecated on purpose
public static class Nested {}
}

0 comments on commit fc28926

Please sign in to comment.