Fix: String templates suggest removing curly braces for backtick escaped identifiers
This commit is contained in:
committed by
Nikolay Krasko
parent
17a4506575
commit
9ab54d0e44
@@ -521,7 +521,7 @@ fun KtBlockStringTemplateEntry.canDropBraces() =
|
||||
expression is KtNameReferenceExpression && canPlaceAfterSimpleNameEntry(nextSibling)
|
||||
|
||||
fun KtBlockStringTemplateEntry.dropBraces(): KtSimpleNameStringTemplateEntry {
|
||||
val name = (expression as KtNameReferenceExpression).getReferencedName()
|
||||
val name = (expression as KtNameReferenceExpression).getReferencedNameElement().text
|
||||
val newEntry = KtPsiFactory(this).createSimpleNameStringTemplateEntry(name)
|
||||
return replaced(newEntry)
|
||||
}
|
||||
+4
-2
@@ -22,9 +22,11 @@ import org.jetbrains.kotlin.idea.core.dropBraces
|
||||
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
|
||||
import org.jetbrains.kotlin.psi.KtBlockStringTemplateEntry
|
||||
|
||||
class RemoveCurlyBracesFromTemplateInspection : IntentionBasedInspection<KtBlockStringTemplateEntry>(RemoveCurlyBracesFromTemplateIntention::class)
|
||||
class RemoveCurlyBracesFromTemplateInspection :
|
||||
IntentionBasedInspection<KtBlockStringTemplateEntry>(RemoveCurlyBracesFromTemplateIntention::class)
|
||||
|
||||
class RemoveCurlyBracesFromTemplateIntention : SelfTargetingOffsetIndependentIntention<KtBlockStringTemplateEntry>(KtBlockStringTemplateEntry::class.java, "Remove curly braces") {
|
||||
class RemoveCurlyBracesFromTemplateIntention :
|
||||
SelfTargetingOffsetIndependentIntention<KtBlockStringTemplateEntry>(KtBlockStringTemplateEntry::class.java, "Remove curly braces") {
|
||||
override fun isApplicableTo(element: KtBlockStringTemplateEntry) = element.canDropBraces()
|
||||
|
||||
override fun applyTo(element: KtBlockStringTemplateEntry, editor: Editor?) {
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// IS_APPLICABLE: true
|
||||
fun foo(`object`: Any) {
|
||||
val bar = "$<caret>{`object`}"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// IS_APPLICABLE: true
|
||||
fun foo(`object`: Any) {
|
||||
val bar = "$`object`"
|
||||
}
|
||||
@@ -13850,6 +13850,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
public void testUnnecessaryBrackets6() throws Exception {
|
||||
runTest("idea/testData/intentions/removeCurlyBracesFromTemplate/unnecessaryBrackets6.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unnecessaryBrackets7.kt")
|
||||
public void testUnnecessaryBrackets7() throws Exception {
|
||||
runTest("idea/testData/intentions/removeCurlyBracesFromTemplate/unnecessaryBrackets7.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/intentions/removeEmptyClassBody")
|
||||
|
||||
Reference in New Issue
Block a user