Rename: Quote non-identifier names in Kotlin references
#KT-9156 Fixed
This commit is contained in:
@@ -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
|
||||
|
||||
+2
-1
@@ -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()
|
||||
}
|
||||
Vendored
+5
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user