UAST: yet another fight with string literals in string literals (KT-20990)
This commit is contained in:
committed by
xiexed
parent
132285ea03
commit
9730d50e10
@@ -57,12 +57,11 @@ abstract class KotlinAbstractUElement(private val givenParent: UElement?) : UEle
|
|||||||
parent = parent.parent
|
parent = parent.parent
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parent is KtStringTemplateExpression && parent.entries.size == 1) {
|
while (parent is KtStringTemplateEntryWithExpression ||
|
||||||
parent = parent.parent
|
parent is KtStringTemplateExpression && parent.entries.size == 1) {
|
||||||
}
|
|
||||||
if (parent is KtStringTemplateEntryWithExpression) {
|
|
||||||
parent = parent.parent
|
parent = parent.parent
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parent is KtWhenConditionWithExpression) {
|
if (parent is KtWhenConditionWithExpression) {
|
||||||
parent = parent.parent
|
parent = parent.parent
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-1
@@ -4,4 +4,12 @@ val baz = "dolor"
|
|||||||
|
|
||||||
val foobarbaz = "$foo $bar $baz"
|
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()}"
|
||||||
|
}
|
||||||
|
|||||||
@@ -28,3 +28,26 @@ UFile (package = )
|
|||||||
UAnnotationMethod (name = getBaz)
|
UAnnotationMethod (name = getBaz)
|
||||||
UAnnotationMethod (name = getFoobarbaz)
|
UAnnotationMethod (name = getFoobarbaz)
|
||||||
UAnnotationMethod (name = getCase4)
|
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 getBaz() : java.lang.String = UastEmptyExpression
|
||||||
public static final fun getFoobarbaz() : 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 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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user