|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2024 the original author or authors. |
| 2 | + * Copyright 2012-2025 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
23 | 23 | import java.util.ArrayList;
|
24 | 24 | import java.util.List;
|
25 | 25 | import java.util.Map;
|
| 26 | +import java.util.Optional; |
26 | 27 | import java.util.Properties;
|
27 | 28 | import java.util.function.Consumer;
|
28 | 29 | import java.util.function.Predicate;
|
|
54 | 55 | import org.springframework.aot.hint.MemberCategory;
|
55 | 56 | import org.springframework.aot.hint.RuntimeHints;
|
56 | 57 | import org.springframework.aot.hint.SerializationHints;
|
| 58 | +import org.springframework.aot.hint.TypeHint; |
57 | 59 | import org.springframework.aot.hint.TypeReference;
|
58 | 60 | import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
59 | 61 | import org.springframework.aot.test.generate.TestGenerationContext;
|
@@ -214,6 +216,14 @@ void typeFromParentsDefaultClassAnnotatedSetterIsRegisteredForReflection() {
|
214 | 216 | .accepts(generationContext.getRuntimeHints());
|
215 | 217 | assertThat(invokePublicConstructorsAndInspectAndInvokePublicMethodsOf(Implementation.class))
|
216 | 218 | .accepts(generationContext.getRuntimeHints());
|
| 219 | + assertThat(invokePublicConstructorsAndInspectAndInvokePublicMethodsOf(BaseImplementation.Details.class)) |
| 220 | + .accepts(generationContext.getRuntimeHints()); |
| 221 | + |
| 222 | + assertThat(hasValidNestedTypeName(OuterWithDefaultClass.class)).accepts(generationContext.getRuntimeHints()); |
| 223 | + assertThat(hasValidNestedTypeName(Implementation.class)).accepts(generationContext.getRuntimeHints()); |
| 224 | + assertThat(hasValidNestedTypeName(BaseImplementation.Details.class)) |
| 225 | + .accepts(generationContext.getRuntimeHints()); |
| 226 | + |
217 | 227 | }
|
218 | 228 |
|
219 | 229 | @Test
|
@@ -250,6 +260,16 @@ private Predicate<RuntimeHints> invokePublicConstructorsAndInspectAndInvokePubli
|
250 | 260 | MemberCategory.INVOKE_PUBLIC_METHODS);
|
251 | 261 | }
|
252 | 262 |
|
| 263 | + private Predicate<RuntimeHints> hasValidNestedTypeName(Class<?> type) { |
| 264 | + return (runtimeHints) -> { |
| 265 | + String name = Optional.ofNullable(runtimeHints.reflection().getTypeHint(type)) |
| 266 | + .map(TypeHint::getType) |
| 267 | + .map(TypeReference::getName) |
| 268 | + .orElse(""); |
| 269 | + return name.equals(type.getEnclosingClass().getName() + "$" + type.getSimpleName()); |
| 270 | + }; |
| 271 | + } |
| 272 | + |
253 | 273 | private Properties load(InputStreamSource source) {
|
254 | 274 | try (InputStream inputStream = source.getInputStream()) {
|
255 | 275 | Properties properties = new Properties();
|
@@ -323,7 +343,21 @@ public void setContract(Contract contract) {
|
323 | 343 |
|
324 | 344 | }
|
325 | 345 |
|
326 |
| - public static class Implementation implements Contract { |
| 346 | + public static class BaseImplementation implements Contract { |
| 347 | + |
| 348 | + private Details details; |
| 349 | + |
| 350 | + public void setDetails(Details details) { |
| 351 | + this.details = details; |
| 352 | + } |
| 353 | + |
| 354 | + public static final class Details { |
| 355 | + |
| 356 | + } |
| 357 | + |
| 358 | + } |
| 359 | + |
| 360 | + public static class Implementation extends BaseImplementation { |
327 | 361 |
|
328 | 362 | }
|
329 | 363 |
|
|
0 commit comments