ek9_generate_delegation

Rewrites the class header's 'with trait of <Trait>' clause to '... by <field>' so the compiler forwards every trait method (no bodies generated); answers status, edits[] and summary.

Category: Editor · Compare: Generate Delegate (IntelliJ)

When to use it

'Forward every Processor method of DelegatingProcessor to its inner field' is one call with symbol, traitName:'Processor' and delegate:'inner'.

When not to use it

Details

Modifies ONE line - the class declaration - because 'by' attaches to the trait reference at class-declaration time, not per-method (per-method 'name by field' syntax does not exist). status:'error' for validation failures: target not a class, class declares no traits, trait not declared on the class, ambiguous trait name, delegate field missing, trait already delegated, or a malformed class-header line (the grammar keeps the whole header on one physical line, so a multi-line clause cannot occur). A non-conforming delegate field type is NOT blocked - the tool proceeds and notes it; a genuine mismatch surfaces as status:'would-fail' from the whole-workspace verify (never 'conflicts'; no banned-identifier check since the field already exists).

Arguments

ArgumentTypeRequiredWhat it is
delegatestringyesThe name of an existing field on the class to delegate to. Its declared type should implement the trait (the compile gate confirms).
filestringThe EK9 source file - OPTIONAL when symbol is a construct name; required to anchor on a member or a use site.
lineinteger1-based line of the declaration or a reference - OMIT it and pass symbol:'<name>' to let the tool find the line (a model counting lines in a file miscounts); if you do count, use ek9_read_file(lineNumbers:true).
symbolstringyesThe class that declares the trait - a bare name ('DelegatingProcessor') finds its file and declaration workspace-wide; 'mod::Name' when the name is declared in two modules.
traitNamestringyesThe trait already declared on the class via 'with trait of'. Simple name (Processor) when unambiguous; fully-qualified (com.acme::Processor) when needed.

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. 3 of the 4 recorded are shown.

Delegate field missing

Request

{
  "delegate" : "nope",
  "file" : "processors.ek9",
  "line" : 16,
  "traitName" : "Processor"
}

Response

{
  "conflicts" : [ ],
  "edits" : [ ],
  "error" : {
    "message" : "delegate field 'nope' not found on class 'DelegatingProcessor'"
  },
  "meta" : {
    "serverMs" : "<timing>"
  },
  "status" : "error",
  "summary" : "delegate field 'nope' not found on class 'DelegatingProcessor'",
  "wouldBeDiagnostics" : [ ],
  "written" : false
}

Non class target

Request

{
  "delegate" : "delegate",
  "file" : "processors.ek9",
  "line" : 6,
  "traitName" : "Processor"
}

Response

{
  "conflicts" : [ ],
  "edits" : [ ],
  "error" : {
    "message" : "'Processor' is a trait - `with trait of X by field` applies to a class only"
  },
  "meta" : {
    "serverMs" : "<timing>"
  },
  "status" : "error",
  "summary" : "'Processor' is a trait - `with trait of X by field` applies to a class only",
  "wouldBeDiagnostics" : [ ],
  "written" : false
}

Trait not declared

Request

{
  "delegate" : "delegate",
  "file" : "processors.ek9",
  "line" : 21,
  "traitName" : "Processor"
}

Response

{
  "conflicts" : [ ],
  "edits" : [ ],
  "error" : {
    "message" : "Class 'NoTraitClass' does not declare trait 'Processor' in its header — add the trait declaration first"
  },
  "meta" : {
    "serverMs" : "<timing>"
  },
  "status" : "error",
  "summary" : "Class 'NoTraitClass' does not declare trait 'Processor' in its header — add the trait declaration first",
  "wouldBeDiagnostics" : [ ],
  "written" : false
}

See also