Safe Delete

Safe Delete removes a class, a function, a method or a field once it has checked that nothing uses it. Here Derived's doWork repeats Base's word for word, so EK9 refuses it - E11044, explained in the Hovers panel; Derived has doWork from Base without it. To play it in the IDE: Help > Lessons > Refactoring…, or ek9 -ide -lesson safe-delete.

The EK9 IDE as the lesson opens: the code to read and, in the Hovers panel, its error explained

Start from

The code the lesson starts from: copy it into a file of your own and follow the steps.

Fails with E11044: override method body is identical to super - remove the override

#!ek9
defines module error.e11044.bad

  defines class

    Base as open
      doWork()
        <- rtn as String: "working"

    Derived extends Base
      override doWork()
        <- rtn as String: "working"

Step 1: Where it is

Put the caret on doWork, on line 11.

The EK9 IDE once this is done: Put the caret on doWork, on line 11

Step 2: Safe Delete

Choose Refactor > Safe Delete…

The EK9 IDE once this is done: Choose Refactor > Safe Delete…

Step 3: Preview and apply

The preview shows every change the refactoring makes; then the IDE formats each file it changed. Choose Apply.

The result

That is Safe Delete: Derived's doWork is gone, and Derived has Base's. Had anything still used what you deleted, the preview would have listed each place instead of offering Apply. It is on the right-click menu wherever the caret is on a declaration, and is Delete safely… on each entry of the Unused Code navigator; AI assistants use the ek9_safe_delete tool.

The EK9 IDE when the lesson has finished

Where this lesson comes from