edvin / tornadofx-idea-plugin

TornadoFX Plugin for IntelliJ IDEA
Apache License 2.0
73 stars 20 forks source link

Option to convert to TornadoFX property using new syntax #7

Closed ruckustboom closed 8 years ago

ruckustboom commented 8 years ago

Would it be possible to add an option to have the "Convert to TornadoFX Property" command use the new property syntax? e.g.

val idProperty = SimpleIntegerProperty()
val id: Int by idProperty

val nameProperty = SimpleStringProperty()
var name: String? by nameProperty

val birthdayProperty = SimpleObjectProperty<LocalDate>()
var birthday: LocalDate? by birthdayProperty

I'm not sure how difficult it would be as there would have to be checks for the primitive properties and Strings to create SimplePrimitivePropertys, while defaulting to SimpleObjectProperty<Type> for the rest, but I tend to prefer the new syntax myself (for the null safety and extra features added to the specific property classes).

ruckustboom commented 8 years ago

I think all the use cases that would have to be covered would be:

Original Type Property Type Mutator Type
Int SimpleIntegerProperty Int
Int? SimpleObjectProperty<Int> Int?
Long SimpleLongProperty Long
Long? SimpleObjectProperty<Long> Long?
Boolean SimpleBooleanProperty Boolean
Boolean? SimpleObjectProperty<Boolean> Boolean?
Float SimpleFloatrProperty Float
Float? SimpleObjectProperty<Float> Float?
Double SimpleDoubleProperty Double
Double? SimpleObjectProperty<Double> Double?
String SimpleStringProperty String?
String? SimpleStringProperty String?
T SimpleObjectProperty<T> T?
T? SimpleObjectProperty<T> T?
ruckustboom commented 8 years ago

It would also be nice if, when converting a constructor parameter, you have the option of keeping the passed in value as a default.

class Person(val name: String)

becomes

class Person(name: String) {
    val nameProperty = SimpleStringProperty(name)
    var name: String? by nameProperty
}
edvin commented 8 years ago

Absolutely, I will add this as a configuration option for the plugin :)

edvin commented 8 years ago

Implemented, will roll it out today, but would prefer it you have a few minutes to go over it first @t-boom