|
17 | 17 |
|
18 | 18 | import java.util.List;
|
19 | 19 | import java.util.Optional;
|
20 |
| -import java.util.function.Supplier; |
21 | 20 | import java.util.stream.Stream;
|
22 | 21 |
|
23 | 22 | import org.springframework.modulith.Modulith;
|
|
33 | 32 | public interface ModulithMetadata {
|
34 | 33 |
|
35 | 34 | static final String ANNOTATION_MISSING = "Modules can only be retrieved from a root type, but %s is not annotated with either @%s, @%s or @%s!";
|
| 35 | + static final String WITH_ANNOTATIONS = ANNOTATION_MISSING.formatted("%s", Modulith.class.getSimpleName(), |
| 36 | + Modulithic.class.getSimpleName(), SpringTypes.AT_SPRING_BOOT_APPLICATION); |
36 | 37 |
|
37 | 38 | /**
|
38 | 39 | * Creates a new {@link ModulithMetadata} for the given annotated type. Expects the type either be annotated with
|
39 | 40 | * {@link Modulith}, {@link Modulithic} or {@link org.springframework.boot.autoconfigure.SpringBootApplication}.
|
40 | 41 | *
|
41 | 42 | * @param annotated must not be {@literal null}.
|
42 |
| - * @return |
| 43 | + * @return will never be {@literal null}. |
43 | 44 | * @throws IllegalArgumentException in case none of the above mentioned annotations is present on the given type.
|
44 | 45 | */
|
45 | 46 | public static ModulithMetadata of(Class<?> annotated) {
|
46 | 47 |
|
47 | 48 | Assert.notNull(annotated, "Annotated type must not be null!");
|
48 | 49 |
|
49 |
| - Supplier<IllegalArgumentException> exception = () -> new IllegalArgumentException( |
50 |
| - String.format(ANNOTATION_MISSING, annotated.getSimpleName(), Modulith.class.getSimpleName(), |
51 |
| - Modulithic.class.getSimpleName(), SpringTypes.AT_SPRING_BOOT_APPLICATION)); |
52 |
| - |
53 |
| - Supplier<ModulithMetadata> withDefaults = () -> SpringBootModulithMetadata.of(annotated).orElseThrow(exception); |
54 |
| - |
55 |
| - return AnnotationModulithMetadata.of(annotated).orElseGet(withDefaults); |
| 50 | + return AnnotationModulithMetadata.of(annotated) |
| 51 | + .or(() -> SpringBootModulithMetadata.of(annotated)) |
| 52 | + .orElseThrow(() -> new IllegalArgumentException(WITH_ANNOTATIONS.formatted(annotated.getSimpleName()))); |
56 | 53 | }
|
57 | 54 |
|
58 | 55 | /**
|
|
0 commit comments