ek9_convert_constructor

Replaces the no-arg constructor with its other spelling - 'default Name()' ↔ an explicit 'this.field :=? Type()' default-setter body - purity and visibility preserved; answers status, edits[] and summary.

Category: Editor · Compare: Convert Constructor (collapse/expand)

When to use it

'Expand Person's default constructor so I can customise it' (or collapse it back) is one call with symbol:'Person' - mode is inferred from the constructor.

When not to use it

Details

Class/record only; the no-arg constructor is found by name (parser-authoritative) and mode is inferred from its form - a 'default' constructor expands, an explicit one collapses; an explicit mode that contradicts the form is status:error. expand emits the guarded ':=?' default-setter, skipping injected ('name as Type!') fields and any field whose declaration already supplies a value (its ':=?' would be dead code, E08095), and errors when no field is left to set (keep 'default'). collapse returns would-fail when losing the explicit body would break the compile - e.g. uninitialised 'as Type?' fields with no co-initialising value ctor (E08070/E07175).

Arguments

ArgumentTypeRequiredWhat it is
filestringThe EK9 source file - OPTIONAL when symbol is a construct name; required to anchor on a member or a use site.
lineintegerIDE refinement: the 1-based line of the constructor declaration. Omit it - the no-arg constructor is found by symbol; needed only when two exist.
modestring: expand | collapseOptional - inferred from the constructor found: a 'default' constructor expands (→ explicit 'this.field :=? Type()' body), an explicit no-arg one collapses (→ 'default').
symbolstringyesThe class or record owning the no-arg constructor - a bare name ('Person') finds its file workspace-wide; 'mod::Person' when the name is declared in two modules.

It also takes the arguments every tool takes.

Recorded calls

Real calls, recorded against small projects and checked on every build - a changed answer fails it.

By name before compile

Request

{
  "dryRun" : true,
  "symbol" : "Account"
}

Response

{
  "conflicts" : [ ],
  "edits" : [ ],
  "error" : {
    "kind" : "not-compiled",
    "message" : "symbol:'Account' is found in the compiled workspace, and nothing has been compiled yet - run ek9_compile, then resend this call unchanged (or pass file:'<path>' with the symbol)."
  },
  "meta" : {
    "serverMs" : "<timing>"
  },
  "nextStep" : "ek9_compile",
  "status" : "error",
  "summary" : "symbol:'Account' is found in the compiled workspace, and nothing has been compiled yet - run ek9_compile, then resend this call unchanged (or pass file:'<path>' with the symbol).",
  "wouldBeDiagnostics" : [ ],
  "written" : false
}

See also