Introduce Parameter: Forbid inside of default values

This commit is contained in:
Alexey Sedunov
2017-09-28 19:44:27 +03:00
parent 790b615fa1
commit 1c3a3cd651
4 changed files with 14 additions and 0 deletions
@@ -377,6 +377,10 @@ open class KotlinIntroduceParameterHandler(
showErrorHint(project, editor, "Introduce Parameter is not available inside of annotation entries", INTRODUCE_PARAMETER)
return
}
if (elementAtCaret.getNonStrictParentOfType<KtParameter>() != null) {
showErrorHint(project, editor, "Introduce Parameter is not available for default value", INTRODUCE_PARAMETER)
return
}
selectNewParameterContext(editor, file) { elements, targetParent ->
val expression = ((elements.singleOrNull() as? KtBlockExpression)?.statements ?: elements).singleOrNull()
@@ -0,0 +1,3 @@
fun foo(s: String = <caret>"abc") {
}
@@ -0,0 +1 @@
Introduce Parameter is not available for default value
@@ -3512,6 +3512,12 @@ public class ExtractionTestGenerated extends AbstractExtractionTest {
doIntroduceSimpleParameterTest(fileName);
}
@TestMetadata("inDefaultValue.kt")
public void testInDefaultValue() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/introduceParameter/inDefaultValue.kt");
doIntroduceSimpleParameterTest(fileName);
}
@TestMetadata("lambdaArgument.kt")
public void testLambdaArgument() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/introduceParameter/lambdaArgument.kt");