Introduce Variable: Do not suggest type-based names for multi-declaration entries if component function corresponds to value parameter

#KT-10287 Fixed
This commit is contained in:
Alexey Sedunov
2015-12-07 19:12:19 +03:00
parent 15faa6610c
commit 76cf284b77
4 changed files with 21 additions and 3 deletions
@@ -452,10 +452,12 @@ object KotlinIntroduceVariableHandler : KotlinIntroduceHandlerBase() {
private fun suggestNamesForComponent(descriptor: FunctionDescriptor, project: Project, validator: (String) -> Boolean): Set<String> { private fun suggestNamesForComponent(descriptor: FunctionDescriptor, project: Project, validator: (String) -> Boolean): Set<String> {
return LinkedHashSet<String>().apply { return LinkedHashSet<String>().apply {
descriptor.returnType?.let { addAll(KotlinNameSuggester.suggestNamesByType(it, validator)) } val descriptorName = descriptor.name.asString()
val componentName = (DescriptorToSourceUtilsIde.getAnyDeclaration(project, descriptor) as? PsiNamedElement)?.name val componentName = (DescriptorToSourceUtilsIde.getAnyDeclaration(project, descriptor) as? PsiNamedElement)?.name
?: descriptor.name.asString() ?: descriptorName
if (componentName == descriptorName) {
descriptor.returnType?.let { addAll(KotlinNameSuggester.suggestNamesByType(it, validator)) }
}
add(KotlinNameSuggester.suggestNameByName(componentName, validator)) add(KotlinNameSuggester.suggestNameByName(componentName, validator))
} }
} }
@@ -0,0 +1,5 @@
fun test() {
<selection>Dimension(1, 2)</selection>
}
data class Dimension(val width: Int, val height: Int)
@@ -0,0 +1,5 @@
fun test() {
val (width, height) = Dimension(1, 2)
}
data class Dimension(val width: Int, val height: Int)
@@ -563,6 +563,12 @@ public class ExtractionTestGenerated extends AbstractExtractionTest {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/multiDeclarations/usedExpr.kt"); String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/multiDeclarations/usedExpr.kt");
doIntroduceVariableTest(fileName); doIntroduceVariableTest(fileName);
} }
@TestMetadata("userDataClass.kt")
public void testUserDataClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/multiDeclarations/userDataClass.kt");
doIntroduceVariableTest(fileName);
}
} }
@TestMetadata("idea/testData/refactoring/introduceVariable/script") @TestMetadata("idea/testData/refactoring/introduceVariable/script")