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:
+5
-3
@@ -452,10 +452,12 @@ object KotlinIntroduceVariableHandler : KotlinIntroduceHandlerBase() {
|
||||
|
||||
private fun suggestNamesForComponent(descriptor: FunctionDescriptor, project: Project, validator: (String) -> Boolean): Set<String> {
|
||||
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
|
||||
?: descriptor.name.asString()
|
||||
?: descriptorName
|
||||
if (componentName == descriptorName) {
|
||||
descriptor.returnType?.let { addAll(KotlinNameSuggester.suggestNamesByType(it, validator)) }
|
||||
}
|
||||
add(KotlinNameSuggester.suggestNameByName(componentName, validator))
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
fun test() {
|
||||
<selection>Dimension(1, 2)</selection>
|
||||
}
|
||||
|
||||
data class Dimension(val width: Int, val height: Int)
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
fun test() {
|
||||
val (width, height) = Dimension(1, 2)
|
||||
}
|
||||
|
||||
data class Dimension(val width: Int, val height: Int)
|
||||
+6
@@ -563,6 +563,12 @@ public class ExtractionTestGenerated extends AbstractExtractionTest {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/multiDeclarations/usedExpr.kt");
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user