UAST: yet another fight with string literals in string literals (KT-20990)

This commit is contained in:
Nicolay Mitropolsky
2017-11-04 00:30:04 +03:00
committed by xiexed
parent 132285ea03
commit 9730d50e10
4 changed files with 41 additions and 5 deletions
@@ -57,12 +57,11 @@ abstract class KotlinAbstractUElement(private val givenParent: UElement?) : UEle
parent = parent.parent
}
if (parent is KtStringTemplateExpression && parent.entries.size == 1) {
parent = parent.parent
}
if (parent is KtStringTemplateEntryWithExpression) {
while (parent is KtStringTemplateEntryWithExpression ||
parent is KtStringTemplateExpression && parent.entries.size == 1) {
parent = parent.parent
}
if (parent is KtWhenConditionWithExpression) {
parent = parent.parent
}
+9 -1
View File
@@ -4,4 +4,12 @@ val baz = "dolor"
val foobarbaz = "$foo $bar $baz"
val case4 = "a ${"literal"} z"
val case4 = "a ${"literal"} z"
fun simpleForTemplate(i: Int = 0) = "$i"
fun foo() {
println("$baz")
val template1 = "${simpleForTemplate()}"
val template2 = ".${simpleForTemplate()}"
}
+23
View File
@@ -28,3 +28,26 @@ UFile (package = )
UAnnotationMethod (name = getBaz)
UAnnotationMethod (name = getFoobarbaz)
UAnnotationMethod (name = getCase4)
UAnnotationMethod (name = simpleForTemplate)
UParameter (name = i)
UAnnotation (fqName = null)
ULiteralExpression (value = 0)
USimpleNameReferenceExpression (identifier = i)
UAnnotationMethod (name = foo)
UBlockExpression
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))
UIdentifier (Identifier (println))
USimpleNameReferenceExpression (identifier = println)
USimpleNameReferenceExpression (identifier = baz)
UDeclarationsExpression
ULocalVariable (name = template1)
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0))
UIdentifier (Identifier (simpleForTemplate))
USimpleNameReferenceExpression (identifier = simpleForTemplate)
UDeclarationsExpression
ULocalVariable (name = template2)
UPolyadicExpression (operator = +)
ULiteralExpression (value = ".")
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0))
UIdentifier (Identifier (simpleForTemplate))
USimpleNameReferenceExpression (identifier = simpleForTemplate)
@@ -9,4 +9,10 @@ public final class StringTemplateKt {
public static final fun getBaz() : java.lang.String = UastEmptyExpression
public static final fun getFoobarbaz() : java.lang.String = UastEmptyExpression
public static final fun getCase4() : java.lang.String = UastEmptyExpression
public static final fun simpleForTemplate(i: int) : java.lang.String = i
public static final fun foo() : void {
println(baz)
var template1: java.lang.String = simpleForTemplate()
var template2: java.lang.String = "." + simpleForTemplate()
}
}