|
2 | 2 |
|
3 | 3 | import org.comroid.annotations.internal.Annotations; |
4 | 4 | import org.comroid.api.attr.Described; |
| 5 | +import org.comroid.api.func.exc.ThrowingFunction; |
| 6 | +import org.comroid.api.text.Capitalization; |
| 7 | +import org.comroid.interaction.component.NameCapitalizer; |
5 | 8 | import org.comroid.interaction.registry.RegistryHelper; |
6 | 9 | import org.jspecify.annotations.Nullable; |
7 | 10 |
|
@@ -51,22 +54,33 @@ record Resolved( |
51 | 54 | ) implements Interaction, Described { |
52 | 55 | public static Resolved of(Element element, @Nullable Element parent) { |
53 | 56 | var detached = element.interaction.detached(); |
54 | | - return new Resolved(RegistryHelper.findName(element).orElseThrow(), |
| 57 | + var filters = Stream.concat(Arrays.stream(element.interaction.filter()), |
| 58 | + Stream.ofNullable(parent) |
| 59 | + .filter($ -> !detached) |
| 60 | + .filter(Objects::nonNull) |
| 61 | + .map(Element::interaction) |
| 62 | + .flatMap(it -> Arrays.stream(it.filter()))).toArray(ContextFilter[]::new); |
| 63 | + var definitions = Stream.concat(Arrays.stream(element.interaction.definitions()), |
| 64 | + Stream.ofNullable(parent) |
| 65 | + .filter($ -> !detached) |
| 66 | + .filter(Objects::nonNull) |
| 67 | + .map(Element::interaction) |
| 68 | + .flatMap(it -> Arrays.stream(it.definitions()))).toArray(ContextDefinition[]::new); |
| 69 | + var nameCapitalization = Arrays.stream(definitions) |
| 70 | + .filter(def -> def.value().equalsIgnoreCase(NameCapitalizer.CONTEXT_KEY)) |
| 71 | + .map(ContextDefinition::expr) |
| 72 | + .flatMap(Arrays::stream) |
| 73 | + .map(ThrowingFunction.fallback(Capitalization::valueOf)) |
| 74 | + .filter(Objects::nonNull) |
| 75 | + .findAny() |
| 76 | + .orElse(Capitalization.lowerCamelCase); |
| 77 | + |
| 78 | + return new Resolved(RegistryHelper.findName(element).map(nameCapitalization::convert).orElseThrow(), |
55 | 79 | RegistryHelper.findDescription(element.annotated).orElse(null), |
56 | 80 | element.interaction.async() || parent != null && parent.interaction.async(), |
57 | 81 | element.interaction.privacy(), |
58 | | - Stream.concat(Arrays.stream(element.interaction.filter()), |
59 | | - Stream.ofNullable(parent) |
60 | | - .filter($ -> !detached) |
61 | | - .filter(Objects::nonNull) |
62 | | - .map(Element::interaction) |
63 | | - .flatMap(it -> Arrays.stream(it.filter()))).toArray(ContextFilter[]::new), |
64 | | - Stream.concat(Arrays.stream(element.interaction.definitions()), |
65 | | - Stream.ofNullable(parent) |
66 | | - .filter($ -> !detached) |
67 | | - .filter(Objects::nonNull) |
68 | | - .map(Element::interaction) |
69 | | - .flatMap(it -> Arrays.stream(it.definitions()))).toArray(ContextDefinition[]::new), |
| 82 | + filters, |
| 83 | + definitions, |
70 | 84 | detached); |
71 | 85 | } |
72 | 86 |
|
|
0 commit comments