Add support for AnnotatedType in MethodParameter.hasNullableAnnotation

This commit adds support for detecting annotated types.

See gh-28797
This commit is contained in:
Sébastien Deleuze
2024-12-03 19:57:27 +01:00
parent 61545fabfc
commit b3586560c1
2 changed files with 36 additions and 12 deletions

View File

@@ -49,6 +49,10 @@ class MethodParameterTests {
private MethodParameter intReturnType;
private MethodParameter jspecifyNullableParameter;
private MethodParameter springNullableParameter;
@BeforeEach
void setup() throws NoSuchMethodException {
@@ -56,6 +60,10 @@ class MethodParameterTests {
stringParameter = new MethodParameter(method, 0);
longParameter = new MethodParameter(method, 1);
intReturnType = new MethodParameter(method, -1);
Method jspecifyNullableMethod = getClass().getMethod("jspecifyNullableMethod", String.class);
jspecifyNullableParameter = new MethodParameter(jspecifyNullableMethod, 0);
Method springNullableMethod = getClass().getMethod("springNullableMethod", String.class);
springNullableParameter = new MethodParameter(springNullableMethod, 0);
}
@@ -238,21 +246,29 @@ class MethodParameterTests {
}
@Test
void nullableWithSpringAnnotation() {
MethodParameter m = MethodParameter.forExecutable(method, 1);
assertThat(m.isOptional()).isTrue();
void jspecifyNullableParameter() {
assertThat(jspecifyNullableParameter.isOptional()).isTrue();
}
@Test
void nullableWithJSpecifyAnnotation() {
MethodParameter m = MethodParameter.forExecutable(method, 0);
assertThat(m.isOptional()).isTrue();
void springNullableParameter() {
assertThat(springNullableParameter.isOptional()).isTrue();
}
public int method(@org.jspecify.annotations.Nullable String p1, @org.springframework.lang.Nullable long p2) {
public int method(String p1, long p2) {
return 42;
}
public @org.jspecify.annotations.Nullable String jspecifyNullableMethod(@org.jspecify.annotations.Nullable String parameter) {
return parameter;
}
@SuppressWarnings("deprecation")
@org.springframework.lang.Nullable
public String springNullableMethod(@org.springframework.lang.Nullable String parameter) {
return parameter;
}
@SuppressWarnings("unused")
private static class NestedClass {