Rename: Fix name quoting for automatic renamers

#KT-13282 Fixed
 #KT-13283 Fixed
This commit is contained in:
Alexey Sedunov
2016-08-10 17:10:56 +03:00
parent a5da9e81a0
commit 385640c86f
7 changed files with 35 additions and 1 deletions
+1
View File
@@ -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-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-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
@@ -164,6 +164,8 @@ fun KtCallableDeclaration.canOmitDeclaredType(initializerOrBodyExpression: KtExp
fun String.quoteIfNeeded(): String = if (KotlinNameSuggester.isIdentifier(this)) this else "`$this`"
fun String.unquote(): String = KtPsiUtil.unquoteIdentifier(this)
fun FqName.quoteSegmentsIfNeeded(): String {
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.VariableDescriptor
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.psiUtil.isAncestor
import org.jetbrains.kotlin.resolve.DescriptorUtils
@@ -79,7 +80,7 @@ class AutomaticVariableRenamer(
myElements.add(parameterOrVariable)
}
suggestAllNames(klass.name, newClassName)
suggestAllNames(klass.name?.unquote(), newClassName.unquote())
}
override fun getDialogTitle() = RefactoringBundle.message("rename.variables.title")
@@ -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`()
}
@@ -0,0 +1,6 @@
{
"type": "MARKED_ELEMENT",
"mainFile": "test/test.kt",
"newName": "A B",
"withRuntime": "true"
}
@@ -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);
}
@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")
public void testClashOfNestedWithOuterClass_ClashOfNestedWithOuterClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/clashOfNestedWithOuterClass/clashOfNestedWithOuterClass.test");