Convert Receiver to Parameter: Place new parameter at the start

This affects editor template only since Change Signature already
puts converted receiver at the parameter list start by default

 #KT-15543 Fixed
This commit is contained in:
Alexey Sedunov
2017-04-18 15:37:41 +03:00
parent 6f984d8260
commit c305a42128
5 changed files with 19 additions and 2 deletions
@@ -60,6 +60,11 @@ public class KtParameterList extends KtElementImplStub<KotlinPlaceHolderStub<KtP
return EditCommaSeparatedListHelper.INSTANCE.addItemBefore(this, getParameters(), parameter, anchor);
}
@NotNull
public KtParameter addParameterAfter(@NotNull KtParameter parameter, @Nullable KtParameter anchor) {
return EditCommaSeparatedListHelper.INSTANCE.addItemAfter(this, getParameters(), parameter, anchor);
}
public void removeParameter(@NotNull KtParameter parameter) {
EditCommaSeparatedListHelper.INSTANCE.removeItem(parameter);
}
@@ -48,7 +48,7 @@ class ConvertReceiverToParameterIntention : SelfTargetingOffsetIndependentIntent
return originalDescriptor.modify {
it.receiver = null
if (newName != null) {
it.parameters.last().name = newName
it.parameters.first().name = newName
}
}
}
@@ -74,7 +74,7 @@ class ConvertReceiverToParameterIntention : SelfTargetingOffsetIndependentIntent
project.executeWriteCommand(text) {
function.setReceiverTypeReference(null)
val addedParameter = function.getOrCreateValueParameterList().addParameter(newParameter)
val addedParameter = function.getOrCreateValueParameterList().addParameterAfter(newParameter, null)
with(PsiDocumentManager.getInstance(project)) {
commitDocument(editor.document)
@@ -0,0 +1,3 @@
fun <caret>String.foo(s: String): String {
return this + s
}
@@ -0,0 +1,3 @@
fun <caret>foo(s1: String, s: String): String {
return s1 + s
}
@@ -5384,6 +5384,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/convertReceiverToParameter"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("autoSuggestedName.kt")
public void testAutoSuggestedName() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertReceiverToParameter/autoSuggestedName.kt");
doTest(fileName);
}
@TestMetadata("functionExpression.kt")
public void testFunctionExpression() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertReceiverToParameter/functionExpression.kt");