ek9_rename_field

Renames a private field and every use inside its owning construct body in one atomic edit; answers status and edits[] (one REPLACE per rewritten line).

Category: Editor · Compare: Refactor → Rename (IntelliJ, field scope)

When to use it

'Rename the field farewell on Greeter to signoff' is one call with symbol:'Greeter.farewell', newName:'signoff' - no file or line needed. Use it for a class/record/component FIELD: the declaration plus every use inside the construct body, in one atomic edit.

When not to use it

Details

Every blocking case is an error, never conflicts[]: construct/field not found, name collision on the same construct, newName equals oldName, invalid/reserved identifier, or a synthesised member with no source occurrence. V1 find-references is a word-boundary textual scan over the construct's body byte range, so a same-named local that shadows the field is also renamed.

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.
newNamestringyesNew field name. Must be a valid EK9 identifier and not collide with an existing field on the same construct.
oldNamestringCurrent field name. Must exist on the construct (omit when symbol is 'Type.field').
symbolstringyesThe construct that owns the field ('Greeter'), or the field itself as 'Greeter.farewell' (then oldName may be omitted) - found workspace-wide, no file 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.

Rename field same name disambiguation

Request

{
  "constructName" : "Greeter",
  "file" : "GreeterB.ek9",
  "newName" : "signoff",
  "oldName" : "farewell"
}

Response

{
  "conflicts" : [ ],
  "edits" : [ {
    "after" : "      signoff as String: \"Bye\"",
    "before" : "      farewell as String: \"Bye\"",
    "endLine" : 6,
    "file" : "GreeterB.ek9",
    "startLine" : 6,
    "type" : "replace"
  }, {
    "after" : "        <- result as String: signoff",
    "before" : "        <- result as String: farewell",
    "endLine" : 9,
    "file" : "GreeterB.ek9",
    "startLine" : 9,
    "type" : "replace"
  } ],
  "meta" : {
    "serverMs" : "<timing>"
  },
  "risk" : {
    "crossesModuleBoundary" : false,
    "estimatedSeverity" : "trivial",
    "fileCount" : 1,
...

Cut short here: 10 more lines. The whole recorded call.

Rename field and reference apply

Request

{
  "constructName" : "Greeter",
  "file" : "Greeter.ek9",
  "newName" : "salutation",
  "oldName" : "greeting"
}

Response

{
  "conflicts" : [ ],
  "edits" : [ {
    "after" : "      salutation as String: \"Hello\"",
    "before" : "      greeting as String: \"Hello\"",
    "endLine" : 6,
    "file" : "Greeter.ek9",
    "startLine" : 6,
    "type" : "replace"
  }, {
    "after" : "        <- result as String: salutation",
    "before" : "        <- result as String: greeting",
    "endLine" : 9,
    "file" : "Greeter.ek9",
    "startLine" : 9,
    "type" : "replace"
  } ],
  "meta" : {
    "serverMs" : "<timing>"
  },
  "risk" : {
    "crossesModuleBoundary" : false,
    "estimatedSeverity" : "trivial",
    "fileCount" : 1,
...

Cut short here: 10 more lines. The whole recorded call.

Field assigned from same named parameter

Request

{
  "constructName" : "Account",
  "file" : "account.ek9",
  "newName" : "amount",
  "oldName" : "balance"
}

Response

{
  "conflicts" : [ ],
  "edits" : [ {
    "after" : "      amount as Float?",
    "before" : "      balance as Float?",
    "endLine" : 7,
    "file" : "account.ek9",
    "startLine" : 7,
    "type" : "replace"
  }, {
    "after" : "        this.amount: amount",
    "before" : "        this.balance: balance",
    "endLine" : 14,
    "file" : "account.ek9",
    "startLine" : 14,
    "type" : "replace"
  }, {
    "after" : "        <- rtn as Float: amount * 2.0",
    "before" : "        <- rtn as Float: balance * 2.0",
    "endLine" : 17,
    "file" : "account.ek9",
    "startLine" : 17,
    "type" : "replace"
  }, {
...

Cut short here: 31 more lines. The whole recorded call.

See also