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.
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
- The visibility change is part of a wider signature change (params / return type) - use
ek9_change_signature. - The method shouldn't exist at all - use
ek9_safe_deleterather than restricting access. - Factoring part of a method into a private helper - use
ek9_extract_method(extracted methods are private by default). - The target is a field, an operator, or a trait method - their visibility is fixed in EK9 (class/component fields private, record fields public, operators and trait methods public); this tool returns status:'error'.
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
| Argument | Type | Required | What it is |
|---|---|---|---|
column | integer | IDE cursor offset (0-based) on 'line'. Omit it - pass symbol instead. | |
file | string | The EK9 source file - OPTIONAL when symbol is a construct name; required to anchor on a member or a use site. | |
line | integer | 1-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). | |
symbol | string | yes | The method - 'Order.total' finds its file and declaration workspace-wide; with file (+ line), the identifier you mean there. |
visibility | string: public | protected | private | yes | The 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
- Show me in the IDE: Change Visibility