package de.sormuras.bach.execution;

import java.nio.file.Path;

/** Snippet producer and default Java source code helpers. */
interface Scribe {

  /** Convert the string representation of the given object into a {@code String} literal. */
  default String $(Object object) {
    if (object == null) return "null";
    return '"' + object.toString().replace("\\", "\\\\") + '"';
  }

  /** Create {@code Path.of("some/path/...")} literal. */
  default String $(Path path) {
    return "Path.of(" + $((Object) path) + ")";
  }

  /** Create {@code "first" [, "second" [, ...]]} literal. */
  default String $(String[] strings) {
    if (strings.length == 0) return "";
    if (strings.length == 1) return $(strings[0]);
    if (strings.length == 2) return $(strings[0]) + ", " + $(strings[1]);
    return String.join(", ", strings);
  }

  /** Return source code snippet. */
  Snippet toSnippet();
}

@@ -56,16 +56,47 @@
 le.Path;
+%0Aimport java.util.StringJoiner;
 %0A%0A/** Sn
@@ -826,40 +826,125 @@
     
-return
+var joiner = new
  String
-.j
+J
 oin
+er
 (%22, %22
-, strings
+);%0A    for(var string : strings) joiner.add($(string));%0A    return joiner.toString(
 );%0A 

Fix generation of string literals