implements PLN-0068
This commit is contained in:
+33
@@ -0,0 +1,33 @@
|
||||
package p.studio.compiler.models;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record FrontendEditorPaletteSpec(
|
||||
String baseForeground,
|
||||
String selectionBackground,
|
||||
String activeHighlightBackground,
|
||||
String lineNumberForeground,
|
||||
String statusChipBackground,
|
||||
String statusChipBorder,
|
||||
String statusChipForeground) {
|
||||
|
||||
public FrontendEditorPaletteSpec {
|
||||
baseForeground = requireColor(baseForeground, "baseForeground");
|
||||
selectionBackground = requireColor(selectionBackground, "selectionBackground");
|
||||
activeHighlightBackground = requireColor(activeHighlightBackground, "activeHighlightBackground");
|
||||
lineNumberForeground = requireColor(lineNumberForeground, "lineNumberForeground");
|
||||
statusChipBackground = requireColor(statusChipBackground, "statusChipBackground");
|
||||
statusChipBorder = requireColor(statusChipBorder, "statusChipBorder");
|
||||
statusChipForeground = requireColor(statusChipForeground, "statusChipForeground");
|
||||
}
|
||||
|
||||
private static String requireColor(
|
||||
final String value,
|
||||
final String field) {
|
||||
final String candidate = Objects.requireNonNull(value, field).trim();
|
||||
if (candidate.isEmpty()) {
|
||||
throw new IllegalArgumentException(field + " must not be blank");
|
||||
}
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
+42
-3
@@ -5,14 +5,53 @@ import java.util.Objects;
|
||||
|
||||
public record FrontendSemanticPresentationSpec(
|
||||
List<String> semanticKeys,
|
||||
List<String> resources) {
|
||||
List<FrontendVisualThemeSpec> themes,
|
||||
String defaultThemeId) {
|
||||
|
||||
public FrontendSemanticPresentationSpec {
|
||||
semanticKeys = List.copyOf(Objects.requireNonNull(semanticKeys, "semanticKeys"));
|
||||
resources = List.copyOf(Objects.requireNonNull(resources, "resources"));
|
||||
themes = List.copyOf(Objects.requireNonNull(themes, "themes"));
|
||||
defaultThemeId = Objects.requireNonNull(defaultThemeId, "defaultThemeId").trim();
|
||||
if (semanticKeys.isEmpty() && themes.isEmpty()) {
|
||||
if (!defaultThemeId.isEmpty()) {
|
||||
throw new IllegalArgumentException("defaultThemeId must be blank when no themes are declared");
|
||||
}
|
||||
} else {
|
||||
defaultThemeId = requireText(defaultThemeId, "defaultThemeId");
|
||||
if (themes.isEmpty()) {
|
||||
throw new IllegalArgumentException("themes must not be empty");
|
||||
}
|
||||
if (themes.stream().map(FrontendVisualThemeSpec::themeId).noneMatch(defaultThemeId::equals)) {
|
||||
throw new IllegalArgumentException("defaultThemeId must reference one of the declared themes");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static FrontendSemanticPresentationSpec empty() {
|
||||
return new FrontendSemanticPresentationSpec(List.of(), List.of());
|
||||
return new FrontendSemanticPresentationSpec(List.of(), List.of(), "");
|
||||
}
|
||||
|
||||
public FrontendVisualThemeSpec defaultTheme() {
|
||||
if (themes.isEmpty()) {
|
||||
throw new IllegalStateException("empty semantic presentation has no default theme");
|
||||
}
|
||||
return themes.stream()
|
||||
.filter(theme -> theme.themeId().equals(defaultThemeId))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new IllegalStateException("defaultThemeId must resolve to a declared theme"));
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return semanticKeys.isEmpty() && themes.isEmpty() && defaultThemeId.isEmpty();
|
||||
}
|
||||
|
||||
private static String requireText(
|
||||
final String value,
|
||||
final String field) {
|
||||
final String candidate = Objects.requireNonNull(value, field).trim();
|
||||
if (candidate.isEmpty()) {
|
||||
throw new IllegalArgumentException(field + " must not be blank");
|
||||
}
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package p.studio.compiler.models;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record FrontendTokenStyleSpec(
|
||||
String semanticKey,
|
||||
String foreground,
|
||||
boolean italic,
|
||||
boolean bold,
|
||||
boolean underline) {
|
||||
|
||||
public FrontendTokenStyleSpec {
|
||||
semanticKey = requireText(semanticKey, "semanticKey");
|
||||
foreground = requireText(foreground, "foreground");
|
||||
}
|
||||
|
||||
private static String requireText(
|
||||
final String value,
|
||||
final String field) {
|
||||
final String candidate = Objects.requireNonNull(value, field).trim();
|
||||
if (candidate.isEmpty()) {
|
||||
throw new IllegalArgumentException(field + " must not be blank");
|
||||
}
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package p.studio.compiler.models;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public record FrontendVisualThemeSpec(
|
||||
String themeId,
|
||||
String displayName,
|
||||
FrontendEditorPaletteSpec editorPalette,
|
||||
List<FrontendTokenStyleSpec> tokenStyles) {
|
||||
|
||||
public FrontendVisualThemeSpec {
|
||||
themeId = requireText(themeId, "themeId");
|
||||
displayName = requireText(displayName, "displayName");
|
||||
editorPalette = Objects.requireNonNull(editorPalette, "editorPalette");
|
||||
tokenStyles = List.copyOf(Objects.requireNonNull(tokenStyles, "tokenStyles"));
|
||||
if (tokenStyles.isEmpty()) {
|
||||
throw new IllegalArgumentException("tokenStyles must not be empty");
|
||||
}
|
||||
final Map<String, FrontendTokenStyleSpec> bySemanticKey = new LinkedHashMap<>();
|
||||
for (final FrontendTokenStyleSpec tokenStyle : tokenStyles) {
|
||||
final FrontendTokenStyleSpec previous = bySemanticKey.put(tokenStyle.semanticKey(), tokenStyle);
|
||||
if (previous != null) {
|
||||
throw new IllegalArgumentException("duplicate token style for semantic key: " + tokenStyle.semanticKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public FrontendTokenStyleSpec requireTokenStyle(final String semanticKey) {
|
||||
return tokenStyles.stream()
|
||||
.filter(tokenStyle -> tokenStyle.semanticKey().equals(semanticKey))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new IllegalArgumentException("missing token style for semantic key: " + semanticKey));
|
||||
}
|
||||
|
||||
private static String requireText(
|
||||
final String value,
|
||||
final String field) {
|
||||
final String candidate = Objects.requireNonNull(value, field).trim();
|
||||
if (candidate.isEmpty()) {
|
||||
throw new IllegalArgumentException(field + " must not be blank");
|
||||
}
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user