From bb5f966e7b05471c6a28f4428ff8f1fc68167988 Mon Sep 17 00:00:00 2001 From: Arnaud Roques Date: Sun, 24 Nov 2024 21:12:13 +0100 Subject: [PATCH] refactor: theme header --- src/net/sourceforge/plantuml/theme/Theme.java | 11 ++++++++--- src/net/sourceforge/plantuml/tim/TContext.java | 9 +++++---- .../plantuml/tim/builtin/GetCurrentTheme.java | 5 +---- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/net/sourceforge/plantuml/theme/Theme.java b/src/net/sourceforge/plantuml/theme/Theme.java index 2b33a00c1d1..e2229380c8e 100644 --- a/src/net/sourceforge/plantuml/theme/Theme.java +++ b/src/net/sourceforge/plantuml/theme/Theme.java @@ -36,8 +36,9 @@ package net.sourceforge.plantuml.theme; import java.io.IOException; -import java.util.Map; +import java.util.Map.Entry; +import net.sourceforge.plantuml.json.JsonObject; import net.sourceforge.plantuml.preproc.ReadLine; import net.sourceforge.plantuml.preproc.ReadLineWithYamlHeader; import net.sourceforge.plantuml.text.StringLocated; @@ -58,8 +59,12 @@ public void close() throws IOException { source.close(); } - public Map getMetadata() { - return source.getMetadata(); + public JsonObject getMetadata() { + final JsonObject result = new JsonObject(); + for (Entry ent : source.getMetadata().entrySet()) + result.add(ent.getKey(), ent.getValue()); + + return result; } } diff --git a/src/net/sourceforge/plantuml/tim/TContext.java b/src/net/sourceforge/plantuml/tim/TContext.java index 005b272feb1..cc04a342d93 100644 --- a/src/net/sourceforge/plantuml/tim/TContext.java +++ b/src/net/sourceforge/plantuml/tim/TContext.java @@ -52,6 +52,7 @@ import net.sourceforge.plantuml.FileSystem; import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.json.Json; +import net.sourceforge.plantuml.json.JsonObject; import net.sourceforge.plantuml.json.JsonValue; import net.sourceforge.plantuml.log.Logme; import net.sourceforge.plantuml.preproc.Defines; @@ -636,10 +637,10 @@ private void executeIncludeDef(TMemory memory, StringLocated s) throws EaterExce } } - private Map headerMetadata = Collections.emptyMap(); + private JsonObject themeMetadata = new JsonObject(); - public Map getHeaderMetadata() { - return headerMetadata; + public JsonObject getThemeMetadata() { + return themeMetadata; } private void executeTheme(TMemory memory, StringLocated s) throws EaterException { @@ -663,7 +664,7 @@ private void executeTheme(TMemory memory, StringLocated s) throws EaterException Logme.error(e); throw new EaterException("Error reading theme " + e, s); } finally { - this.headerMetadata = theme.getMetadata(); + this.themeMetadata = theme.getMetadata(); try { theme.close(); } catch (IOException e) { diff --git a/src/net/sourceforge/plantuml/tim/builtin/GetCurrentTheme.java b/src/net/sourceforge/plantuml/tim/builtin/GetCurrentTheme.java index b0a98aa77d3..6c930b332d1 100644 --- a/src/net/sourceforge/plantuml/tim/builtin/GetCurrentTheme.java +++ b/src/net/sourceforge/plantuml/tim/builtin/GetCurrentTheme.java @@ -36,7 +36,6 @@ import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; import net.sourceforge.plantuml.json.JsonObject; @@ -61,9 +60,7 @@ public boolean canCover(int nbArg, Set namedArgument) { @Override public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, Map named) throws EaterException { - final JsonObject result = new JsonObject(); - for (Entry ent : context.getHeaderMetadata().entrySet()) - result.add(ent.getKey(), ent.getValue()); + final JsonObject result = context.getThemeMetadata(); return TValue.fromJson(result); }