Rename: Quote non-identifier names in Kotlin references

#KT-9156 Fixed
This commit is contained in:
Alexey Sedunov
2016-05-24 15:30:02 +03:00
parent a743098aba
commit 691de677b3
8 changed files with 34 additions and 1 deletions
+5
View File
@@ -169,6 +169,11 @@
- [`KT-11574`](https://youtrack.jetbrains.com/issue/KT-11574) Support predefined Java positions for language injection
- [`KT-11472`](https://youtrack.jetbrains.com/issue/KT-11472) Add comment or @Language annotation after "Inject language or reference" intention automatically
#### Refactorings
###### Issues fixed
- [`KT-9156`](https://youtrack.jetbrains.com/issue/KT-9156) Quote non-identifier names in Kotlin references
#### Java to Kotlin converter
###### New features
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.idea.codeInsight.shorten.addToShorteningWaitSet
import org.jetbrains.kotlin.idea.intentions.OperatorToFunctionIntention
import org.jetbrains.kotlin.idea.refactoring.fqName.getKotlinFqName
import org.jetbrains.kotlin.idea.core.ShortenReferences
import org.jetbrains.kotlin.idea.core.quoteIfNeeded
import org.jetbrains.kotlin.lexer.KtToken
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.load.java.descriptors.JavaPropertyDescriptor
@@ -114,7 +115,7 @@ class KtSimpleNameReference(expression: KtSimpleNameExpression) : KtSimpleRefere
val element = Extensions.getArea(expression.project).getExtensionPoint(SimpleNameReferenceExtension.EP_NAME).extensions
.asSequence()
.map { it.handleElementRename(this, psiFactory, newElementName) }
.firstOrNull { it != null } ?: psiFactory.createNameIdentifier(newElementName)
.firstOrNull { it != null } ?: psiFactory.createNameIdentifier(newElementName.quoteIfNeeded())
val nameElement = expression.getReferencedNameElement()
@@ -0,0 +1,5 @@
public class JFoo {
public void fun() {
}
}
@@ -0,0 +1,3 @@
fun test(foo: JFoo) {
foo.`fun`()
}
@@ -0,0 +1,5 @@
public class JFoo {
public void /*rename*/foo() {
}
}
@@ -0,0 +1,3 @@
fun test(foo: JFoo) {
foo.foo()
}
@@ -0,0 +1,5 @@
{
"type": "MARKED_ELEMENT",
"mainFile": "JFoo.java",
"newName": "fun"
}
@@ -215,6 +215,12 @@ public class RenameTestGenerated extends AbstractRenameTest {
doTest(fileName);
}
@TestMetadata("renameJavaMethodToKtKeyword/renameJavaMethodToKtKeyword.test")
public void testRenameJavaMethodToKtKeyword_RenameJavaMethodToKtKeyword() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameJavaMethodToKtKeyword/renameJavaMethodToKtKeyword.test");
doTest(fileName);
}
@TestMetadata("renameJavaSyntheticIsPropertyByGetterRef/renameJavaSyntheticIsPropertyByGetterRef.test")
public void testRenameJavaSyntheticIsPropertyByGetterRef_RenameJavaSyntheticIsPropertyByGetterRef() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameJavaSyntheticIsPropertyByGetterRef/renameJavaSyntheticIsPropertyByGetterRef.test");