Redundant curly braces in string template: do not report labeled 'this'

#KT-35475 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-12-17 17:57:24 +09:00
committed by Dmitry Gridin
parent 80d29cdad1
commit fabeca5955
3 changed files with 22 additions and 2 deletions
@@ -542,8 +542,11 @@ fun KtModifierList.normalize(): KtModifierList {
}
}
fun KtBlockStringTemplateEntry.canDropBraces() =
(expression is KtNameReferenceExpression || expression is KtThisExpression) && canPlaceAfterSimpleNameEntry(nextSibling)
fun KtBlockStringTemplateEntry.canDropBraces(): Boolean {
val expression = this.expression
return (expression is KtNameReferenceExpression || (expression is KtThisExpression && expression.labelQualifier == null))
&& canPlaceAfterSimpleNameEntry(nextSibling)
}
fun KtBlockStringTemplateEntry.dropBraces(): KtSimpleNameStringTemplateEntry {
val name = if (expression is KtThisExpression) {
@@ -0,0 +1,12 @@
// PROBLEM: none
fun main() {
"hello".foo()
}
fun bar(block: Int.() -> Unit) { block(42) }
fun String.foo() = bar {
println("this: <caret>${this@foo}")
}
fun println(s: String) {}
@@ -8247,6 +8247,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
runTest("idea/testData/inspectionsLocal/removeCurlyBracesFromTemplate/necessaryBrackets7.kt");
}
@TestMetadata("necessaryBrackets8.kt")
public void testNecessaryBrackets8() throws Exception {
runTest("idea/testData/inspectionsLocal/removeCurlyBracesFromTemplate/necessaryBrackets8.kt");
}
@TestMetadata("unnecessaryBrackets1.kt")
public void testUnnecessaryBrackets1() throws Exception {
runTest("idea/testData/inspectionsLocal/removeCurlyBracesFromTemplate/unnecessaryBrackets1.kt");