Hello :slightly_smiling_face: Do you guys know of ...
# intellij
s
Hello 🙂 Do you guys know of a way to automatically turn a constructor argument into an abstract property? For example, how to change this:
Copy code
abstract class BaseGreeter(val salutation: String) {
    fun greet(name: String) = println("$salutation, $name!")
}

class HelloGreeter: BaseGreeter("Hello") {
    // class specific stuff here
}
class HiGreeter: BaseGreeter("Hi") {
    // class specific stuff here
}
class AhoiGreeter: BaseGreeter("Ahoi") {
    // class specific stuff here
}

fun main() {
    AhoiGreeter().greet("Kotlin")
}
into this:
Copy code
abstract class BaseGreeter {
    abstract val salutation: String
    fun greet(name: String) = println("$salutation, $name!")
}

class HelloGreeter: BaseGreeter() {
    override val salutation = "Hello"
    // class specific stuff here
}
class HiGreeter: BaseGreeter() {
    override val salutation = "Hi"
    // class specific stuff here
}
class AhoiGreeter: BaseGreeter() {
    override val salutation = "Ahoi"
    // class specific stuff here
}

fun main() {
    AhoiGreeter().greet("Kotlin")
}
I have some refactoring to do and this is a task that would probably take me half a day if I have to do this all manually ^^
m
FYI. This isn't an IntelliJ support forum, so you may not get a very good response. It's intended for questions around the Kotlin IntelliJ plugin. You will likely have better results in Jetbrains forums or StackOverflow.
Having said that, this seems like a very infrequent/unlikely thing, so very unlikely to be automated. But that's my opinion.
s
Ah ok, thanks for the clarification 🙂 My reasoning was, that if that feature exists, it must be an intention provided by the Kotlin plugin ^^
m
Then it's borderline... And people are generally relaxed here.