Rename: Fix name quoting for automatic renamers
#KT-13282 Fixed #KT-13283 Fixed
This commit is contained in:
@@ -262,6 +262,7 @@ Using 'this' as function argument in constructor of non-final class
|
|||||||
- [`KT-13054`](https://youtrack.jetbrains.com/issue/KT-13054) Introduce Variable: Skip leading/trailing comments inside selection
|
- [`KT-13054`](https://youtrack.jetbrains.com/issue/KT-13054) Introduce Variable: Skip leading/trailing comments inside selection
|
||||||
- [`KT-13277`](https://youtrack.jetbrains.com/issue/KT-13277) Change Signature: Fix usage processing to prevent interfering with Python support plugin
|
- [`KT-13277`](https://youtrack.jetbrains.com/issue/KT-13277) Change Signature: Fix usage processing to prevent interfering with Python support plugin
|
||||||
- [`KT-13254`](https://youtrack.jetbrains.com/issue/KT-13254) Rename: Conflict detection for type parameters
|
- [`KT-13254`](https://youtrack.jetbrains.com/issue/KT-13254) Rename: Conflict detection for type parameters
|
||||||
|
- [`KT-13282`](https://youtrack.jetbrains.com/issue/KT-13282), [`KT-13283`](https://youtrack.jetbrains.com/issue/KT-13283) Rename: Fix name quoting for automatic renamers
|
||||||
|
|
||||||
##### New features
|
##### New features
|
||||||
|
|
||||||
|
|||||||
@@ -164,6 +164,8 @@ fun KtCallableDeclaration.canOmitDeclaredType(initializerOrBodyExpression: KtExp
|
|||||||
|
|
||||||
fun String.quoteIfNeeded(): String = if (KotlinNameSuggester.isIdentifier(this)) this else "`$this`"
|
fun String.quoteIfNeeded(): String = if (KotlinNameSuggester.isIdentifier(this)) this else "`$this`"
|
||||||
|
|
||||||
|
fun String.unquote(): String = KtPsiUtil.unquoteIdentifier(this)
|
||||||
|
|
||||||
fun FqName.quoteSegmentsIfNeeded(): String {
|
fun FqName.quoteSegmentsIfNeeded(): String {
|
||||||
return pathSegments().map { it.asString().quoteIfNeeded() }.joinToString(".")
|
return pathSegments().map { it.asString().quoteIfNeeded() }.joinToString(".")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
|||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
|
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
|
||||||
|
import org.jetbrains.kotlin.idea.core.unquote
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.isAncestor
|
import org.jetbrains.kotlin.psi.psiUtil.isAncestor
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
@@ -79,7 +80,7 @@ class AutomaticVariableRenamer(
|
|||||||
myElements.add(parameterOrVariable)
|
myElements.add(parameterOrVariable)
|
||||||
}
|
}
|
||||||
|
|
||||||
suggestAllNames(klass.name, newClassName)
|
suggestAllNames(klass.name?.unquote(), newClassName.unquote())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getDialogTitle() = RefactoringBundle.message("rename.variables.title")
|
override fun getDialogTitle() = RefactoringBundle.message("rename.variables.title")
|
||||||
|
|||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
class `A B` {}
|
||||||
|
|
||||||
|
val THAT_A_B: `A B` = `A B`()
|
||||||
|
val A_B: `A B` = `A B`()
|
||||||
|
|
||||||
|
fun localize(anA: `A B`, aPrefixedA: `A B`) {
|
||||||
|
val `a BVal`: `A B` = `A B`()
|
||||||
|
val `prefixedA BVal`: `A B` = `A B`()
|
||||||
|
}
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"type": "MARKED_ELEMENT",
|
||||||
|
"mainFile": "test/test.kt",
|
||||||
|
"newName": "A B",
|
||||||
|
"withRuntime": "true"
|
||||||
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
class /*rename*/SomeName {}
|
||||||
|
|
||||||
|
val THAT_SOME_NAME: SomeName = SomeName()
|
||||||
|
val SOME_NAME: SomeName = SomeName()
|
||||||
|
|
||||||
|
fun localize(someNamePar: SomeName, prefixedSomeNamePar: SomeName) {
|
||||||
|
val someNameVal: SomeName = SomeName()
|
||||||
|
val prefixedSomeNameVal: SomeName = SomeName()
|
||||||
|
}
|
||||||
@@ -131,6 +131,12 @@ public class RenameTestGenerated extends AbstractRenameTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("automaticVariableRenamerWithQuotation/automaticVariableRenamerWithQuotation.test")
|
||||||
|
public void testAutomaticVariableRenamerWithQuotation_AutomaticVariableRenamerWithQuotation() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/automaticVariableRenamerWithQuotation/automaticVariableRenamerWithQuotation.test");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("clashOfNestedWithOuterClass/clashOfNestedWithOuterClass.test")
|
@TestMetadata("clashOfNestedWithOuterClass/clashOfNestedWithOuterClass.test")
|
||||||
public void testClashOfNestedWithOuterClass_ClashOfNestedWithOuterClass() throws Exception {
|
public void testClashOfNestedWithOuterClass_ClashOfNestedWithOuterClass() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/clashOfNestedWithOuterClass/clashOfNestedWithOuterClass.test");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/clashOfNestedWithOuterClass/clashOfNestedWithOuterClass.test");
|
||||||
|
|||||||
Reference in New Issue
Block a user