Is your feature request related to a problem? Please describe.
Not sure who else wants that, but I often find myself writing a class implementation and then realise that I'd rather have it as a trait + implementation class.
This code action can be especially useful on an already existing class with a non trivial amount of public methods implemented.
Describe the solution you'd like
A code action that
Extracts all public methods into a trait named the same as the class
Explicitly annotates the methods with inferred return types
Renames class to NameImpl
Converts all methods into overrides
object BEFORE:
class Client(bla: String):
def test() = 1
def hello(x: String, b: Int) = bla + x
// Apply code action "Extract interface"
object AFTER:
trait Client:
def test(): Int
def hello(x: String, b: Int): String
class ClientImpl(bla: String) extends Client:
override def test() = 1
override def hello(x: String, b: Int) = bla + x
There's complexity around type parameters of course, but it doesn't have to be part of MVP.
Describe alternatives you've considered
For my personal use an alternative would be to plan ahead and always create traits, but I don't have that level of control over my life.
Is your feature request related to a problem? Please describe.
Not sure who else wants that, but I often find myself writing a class implementation and then realise that I'd rather have it as a trait + implementation class.
This code action can be especially useful on an already existing class with a non trivial amount of public methods implemented.
Describe the solution you'd like
A code action that
NameImpl
There's complexity around type parameters of course, but it doesn't have to be part of MVP.
Describe alternatives you've considered
For my personal use an alternative would be to plan ahead and always create traits, but I don't have that level of control over my life.
Additional context
No response
Search terms
code action, extract, trait, implementation, interface