Make constructor parameter a property: select 'private' to be able to remove it #KT-13187 Fixed
(cherry picked from commit dc8c195)
This commit is contained in:
committed by
Mikhail Glukhikh
parent
0278a6c8a4
commit
838cfc7dca
@@ -28,9 +28,7 @@ import org.jetbrains.kotlin.psi.KtFile
|
|||||||
import org.jetbrains.kotlin.psi.KtNameReferenceExpression
|
import org.jetbrains.kotlin.psi.KtNameReferenceExpression
|
||||||
import org.jetbrains.kotlin.psi.KtParameter
|
import org.jetbrains.kotlin.psi.KtParameter
|
||||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.containingClass
|
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getAssignmentByLHS
|
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.nonStaticOuterClasses
|
|
||||||
|
|
||||||
class MakeConstructorParameterPropertyFix(
|
class MakeConstructorParameterPropertyFix(
|
||||||
element: KtParameter, private val kotlinValVar: KotlinValVar, className: String?
|
element: KtParameter, private val kotlinValVar: KotlinValVar, className: String?
|
||||||
@@ -49,6 +47,12 @@ class MakeConstructorParameterPropertyFix(
|
|||||||
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
||||||
element.addBefore(kotlinValVar.createKeyword(KtPsiFactory(project))!!, element.firstChild)
|
element.addBefore(kotlinValVar.createKeyword(KtPsiFactory(project))!!, element.firstChild)
|
||||||
element.addModifier(KtTokens.PRIVATE_KEYWORD)
|
element.addModifier(KtTokens.PRIVATE_KEYWORD)
|
||||||
|
element.visibilityModifier()?.let { private ->
|
||||||
|
editor?.apply {
|
||||||
|
selectionModel.setSelection(private.startOffset, private.endOffset)
|
||||||
|
caretModel.moveToOffset(private.endOffset)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object Factory : KotlinIntentionActionsFactory() {
|
companion object Factory : KotlinIntentionActionsFactory() {
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
// "Make constructor parameter a property in class 'B'" "true"
|
// "Make constructor parameter a property in class 'B'" "true"
|
||||||
|
|
||||||
class B(private val bar: String) {
|
class B(<selection>private</selection><caret> val bar: String) {
|
||||||
|
|
||||||
inner class A {
|
inner class A {
|
||||||
fun foo() {
|
fun foo() {
|
||||||
val a = bar<caret>
|
val a = bar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
// "Make constructor parameter a property" "true"
|
// "Make constructor parameter a property" "true"
|
||||||
|
|
||||||
class A(private val foo: String) {
|
class A(<selection>private<caret></selection> val foo: String) {
|
||||||
fun bar() {
|
fun bar() {
|
||||||
val a = foo<caret>
|
val a = foo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
// "Make constructor parameter a property" "true"
|
// "Make constructor parameter a property" "true"
|
||||||
|
|
||||||
class A(private var foo: String) {
|
class A(<selection>private<caret></selection> var foo: String) {
|
||||||
fun bar() {
|
fun bar() {
|
||||||
foo<caret> = ""
|
foo = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user