Class StringConcatRewriter

java.lang.Object
org.ek9lang.compiler.repair.StringConcatRewriter

public final class StringConcatRewriter extends Object
Editor primitive that rewrites a string-concatenation expression ("a" + var + "b") into the equivalent backtick interpolation (`a${var}b`). Selection-driven; single mode; produces a single replace edit.

Idempotent: when the selection is already a backtick literal or a single double-quoted literal, returns applied with meta.outcome = "already-in-target-form" and no edits.

Operand admissibility in V1 is restricted to:

  • String literals (become literal segments)
  • Plain identifier references
  • objectAccessExpression chains of identifier / method-call
  • Plain call expressions (foo(), bar(x))
  • A unary - or $ over one of the above ($total renders ${$total})

Everything else (ternary, logical operators, lambdas, ranges, list/dict literals, etc.) is refused with an escalation conflict. The grammar permits arbitrary expressions inside ${...} but tool policy is stricter — see docs/tooling/tools/ek9_rewrite_string_concat.md.

Each non-literal operand's type must define a _string() operator — this is the semantic admission gate, verified via MethodSymbolSearch against the recorded symbol type.

  • Constructor Details

    • StringConcatRewriter

      public StringConcatRewriter()
  • Method Details

    • rewrite

      public StringConcatRewriteOutcome rewrite(CompilableProgram program, Workspace workspace, String filePath, String sourceText, int startLine, int startCol, int endLine, int endCol)
      Rewrite the string-concat expression covered by the selection range.
      Parameters:
      program - current compiled program (read-only)
      workspace - current workspace
      filePath - absolute path of the target .ek9 source
      sourceText - on-disk source text
      startLine - 1-based inclusive
      startCol - 1-based inclusive
      endLine - 1-based inclusive
      endCol - 1-based inclusive
    • renderChain

      THE rendering of a + chain as one backtick String - shared by this tool and the E11068 repair (ConcatenationInterpolation); use it, do not re-derive the operand rules. The chain is flattened, each literal becomes a segment (escaped by BacktickString) and every other operand a ${...}, provided its SHAPE is admissible and typeProblem (the semantic gate: a reason, or null when the operand is fine) accepts it. The repair passes a gate that accepts everything: E11068 is raised after resolution, on a chain the compiler already typed as String concatenation.
    • transformDoubleQuoteBody

      static String transformDoubleQuoteBody(String body)
      A double-quoted literal's body as a backtick segment: BacktickString.literal(String) without its delimiters - THE escaping rule (\" plainly, every $ and backtick escaped), shared with the E07901 message and repair rather than kept as a second copy here. Visible for testing.
    • resolveSymbolForTest

      static ISymbol resolveSymbolForTest(ParsedModule parsedModule, EK9Parser.ExpressionContext expr)
      Visible for tests.