"Extract Field" in Kotlin don't work as expected

Answered
I often use "Extract Field" (https://www.jetbrains.com/help/idea/extract-field.html) to declare member variable in Java, but this is not work in Kotlin as expected:
 
Before:
class Class {

fun method() {
val a = 1
val b = 2
var c = a + b
}
}
 
When I select "c" and "Extract Field", IDEA prompts "cannot introduce property for this expression". I assumed it should goes:
 
class Class {
var c1: String? = null
lateinit var c2: String
var c3 by Delegates.notNull<String>()

fun method() {
val a = "a"
val b = "b"
c1 = "$a $b"
c2 = "$a $b"
c3 = "$a $b"
}
}
 
Is there any way to introduce an expression to a member variable using a built-in refactor function provided by IDEA when using Kotlin as language?
0
8 comments

Hello, Phoenix!

Would you please use Kotlin forum at https://discuss.kotlinlang.org/c/support for Kotlin-related issues/questions. Thank you!

0
Avatar
Permanently deleted user

Thank you for your reply, but I think this is a function support issue for IDEA.

The " extract field" is a shortcut key for IDEA. It can well support Java but cannot support Kotlin.

I don't know whether this is a bug or an expected feature.

0

The mentioned feature in IDEA editor is a Kotlin-specific and is provided by the Kotlin plugin. Please use mentioned forum for this. Thank you.

0
Avatar
Permanently deleted user

Thank you,I see.Should I delete this post?

0

It is not necessary. You could post here the link to the created on Kotlin forum thread just for future references. Thanks!

0
Avatar
Permanently deleted user

Do you mean this plugin? https://plugins.jetbrains.com/plugin/6954-kotlin/ If so I'm still not seeing this working.

0

Please use https://discuss.kotlinlang.org/ for any Kotlin related questions.

0
Avatar
Permanently deleted user
0

Please sign in to leave a comment.