KotlinCommonIntentionActionsFactory is able to remove constructors parameters (EA-104621) (#1187)
This commit is contained in:
+12
-6
@@ -16,7 +16,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.intentions
|
||||
|
||||
import com.intellij.codeInsight.intention.*
|
||||
import com.intellij.codeInsight.intention.IntentionAction
|
||||
import com.intellij.codeInsight.intention.JvmCommonIntentionActionsFactory
|
||||
import com.intellij.codeInsight.intention.MethodInsertionInfo
|
||||
import com.intellij.codeInsight.intention.QuickFixFactory
|
||||
import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.project.Project
|
||||
@@ -217,11 +220,14 @@ class KotlinCommonIntentionActionsFactory : JvmCommonIntentionActionsFactory() {
|
||||
}
|
||||
|
||||
private fun fakeParametersExpressions(parameters: List<PsiParameter>): Array<PsiExpression> =
|
||||
JavaPsiFacade.getElementFactory(parameters.first().project)
|
||||
.createParameterList(
|
||||
parameters.map { it.name }.toTypedArray(),
|
||||
parameters.map { it.type }.toTypedArray()
|
||||
).parameters.map { FakeExpressionFromParameter(it) }.toTypedArray()
|
||||
when {
|
||||
parameters.isEmpty() -> emptyArray<PsiExpression>()
|
||||
else -> JavaPsiFacade.getElementFactory(parameters.first().project)
|
||||
.createParameterList(
|
||||
parameters.map { it.name }.toTypedArray(),
|
||||
parameters.map { it.type }.toTypedArray()
|
||||
).parameters.map { FakeExpressionFromParameter(it) }.toTypedArray()
|
||||
}
|
||||
|
||||
private class FakeExpressionFromParameter(private val psiParam: PsiParameter) : PsiReferenceExpressionImpl() {
|
||||
|
||||
|
||||
@@ -168,6 +168,20 @@ class CommonIntentionActionsTest : LightPlatformCodeInsightFixtureTestCase() {
|
||||
""".trim().trimMargin(), true)
|
||||
}
|
||||
|
||||
fun testRemoveConstructorParameters() {
|
||||
myFixture.configureByText("foo.kt", """
|
||||
|class <caret>Foo(i: Int) {
|
||||
|}
|
||||
""".trim().trimMargin())
|
||||
|
||||
myFixture.launchAction(codeModifications.createAddCallableMemberActions(MethodInsertionInfo.constructorInfo(
|
||||
atCaret<UClass>(myFixture), makeParams())).findWithText("Remove 1st parameter from method 'Foo'"))
|
||||
myFixture.checkResult("""
|
||||
|class Foo() {
|
||||
|}
|
||||
""".trim().trimMargin(), true)
|
||||
}
|
||||
|
||||
fun testAddStringVarProperty() {
|
||||
myFixture.configureByText("foo.kt", """
|
||||
|class Foo<caret> {
|
||||
|
||||
Reference in New Issue
Block a user