ek9_change_visibility

Rewrites the method's declaration line with the new access modifier (public = none); answers status, edits[] and summary, an unchanged method as conflicts[] (already-<visibility>). Method-only: fields, operators and trait methods have fixed visibility.

Category: Editor · Compare: Refactor → Change Signature (visibility) (IntelliJ) / Change Method Visibility (Eclipse)

When to use it

'Make Order.decorate private' is one call with symbol:'Order.decorate' and visibility:'private' | 'protected' | 'public' - no file, line or column needed.

When not to use it

Details

visibility:'public' REMOVES the modifier (public is EK9's default; writing it explicitly is E07280). A method already at the requested visibility is conflicts[] kind already-public / already-private / already-protected (nothing written). Structurally-impossible changes - an override (visibility locked to its parent), protected on a component/service method, protected on a non-open class method (E07260), any non-public modifier on a trait method (E07270) - are refused up-front as status:'error' by the shared VisibilityChangePredicate, the same rule core the compiler enforces. Narrowing (to private / protected) that leaves a call site unable to reach the member is NOT an up-front error - the scratch compile surfaces it as status:'would-fail' with the E06180 NOT_ACCESSIBLE diagnostics.

Arguments

ArgumentTypeRequiredWhat it is
columnintegerIDE cursor offset (0-based) on 'line'. Omit it - pass symbol instead.
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 method - 'Order.total' finds its file and declaration workspace-wide; with file (+ line), the identifier you mean there.
visibilitystring: public | protected | privateyesThe new access modifier.

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 10 recorded are shown.

Change visibility operator error

Request

{
  "column" : 7,
  "file" : "main.ek9",
  "line" : 23,
  "visibility" : "private"
}

Response

{
  "conflicts" : [ ],
  "edits" : [ ],
  "error" : {
    "message" : "Operators are always public in EK9 and cannot carry an access modifier"
  },
  "meta" : {
    "serverMs" : "<timing>"
  },
  "status" : "error",
  "summary" : "Operators are always public in EK9 and cannot carry an access modifier",
  "wouldBeDiagnostics" : [ ],
  "written" : false
}

Change visibility trait error

Request

{
  "column" : 7,
  "file" : "main.ek9",
  "line" : 6,
  "visibility" : "private"
}

Response

{
  "conflicts" : [ ],
  "edits" : [ ],
  "error" : {
    "message" : "trait methods cannot be marked with an access modifier, they are always public"
  },
  "meta" : {
    "serverMs" : "<timing>"
  },
  "status" : "error",
  "summary" : "trait methods cannot be marked with an access modifier, they are always public",
  "wouldBeDiagnostics" : [ ],
  "written" : false
}

Change visibility closed class protected error

Request

{
  "column" : 7,
  "file" : "main.ek9",
  "line" : 27,
  "visibility" : "protected"
}

Response

{
  "conflicts" : [ ],
  "edits" : [ ],
  "error" : {
    "message" : "class methods can only be marked with the 'protected' access modifier in classes that are 'open'"
  },
  "meta" : {
    "serverMs" : "<timing>"
  },
  "status" : "error",
  "summary" : "class methods can only be marked with the 'protected' access modifier in classes that are 'open'",
  "wouldBeDiagnostics" : [ ],
  "written" : false
}

See also