Class StringConcatRewriter
java.lang.Object
org.ek9lang.compiler.repair.StringConcatRewriter
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
objectAccessExpressionchains of identifier / method-call- Plain
callexpressions (foo(),bar(x)) - A unary
-or$over one of the above ($totalrenders${$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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final recordA+chain rendered as a backtick String, or the first operand that cannot be one: setrenderedwith the operand counts, orconflictKind/reasonnaming the refusal. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static StringConcatRewriter.ChainRenderingrenderChain(EK9Parser.ExpressionContext chain, String sourceText, Function<EK9Parser.ExpressionContext, String> typeProblem) 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.(package private) static ISymbolresolveSymbolForTest(ParsedModule parsedModule, EK9Parser.ExpressionContext expr) Visible for tests.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.(package private) static StringA 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.
-
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 workspacefilePath- absolute path of the target .ek9 sourcesourceText- on-disk source textstartLine- 1-based inclusivestartCol- 1-based inclusiveendLine- 1-based inclusiveendCol- 1-based inclusive
-
renderChain
static StringConcatRewriter.ChainRendering renderChain(EK9Parser.ExpressionContext chain, String sourceText, Function<EK9Parser.ExpressionContext, String> typeProblem) 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 byBacktickString) and every other operand a${...}, provided its SHAPE is admissible andtypeProblem(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
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
Visible for tests.
-