UAST properly handles string "when conditions" in lazy parent (KT-20709) (#1338)

This commit is contained in:
xiexed
2017-10-11 16:16:15 +03:00
committed by Dmitry Jemerov
parent 88595e1a58
commit 5c2962e195
6 changed files with 116 additions and 4 deletions
@@ -6,6 +6,7 @@ import org.jetbrains.kotlin.psi.KtBinaryExpression
import org.jetbrains.kotlin.psi.KtLiteralStringTemplateEntry
import org.jetbrains.kotlin.psi.KtStringTemplateExpression
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase
import org.jetbrains.uast.*
import org.jetbrains.uast.kotlin.KotlinUastLanguagePlugin
@@ -125,4 +126,34 @@ class KotlinUastApiTest : AbstractKotlinUastTest() {
UsefulTestCase.assertInstanceOf(uBinaryExpression.uastParent, UIfExpression::class.java)
}
}
@Test
fun testWhenStringLiteral() {
doTest("WhenStringLiteral") { _, file ->
fun UFile.findULiteralExpressionFromPsi(refText: String): ULiteralExpression =
this.psi.findElementAt(file.psi.text.indexOf(refText))!!
.parentsWithSelf.mapNotNull { it.toUElementOfType<ULiteralExpression>() }.first()
file.findULiteralExpressionFromPsi("abc").let { literalExpression ->
val psi = literalExpression.psi!!
Assert.assertTrue(psi is KtLiteralStringTemplateEntry)
UsefulTestCase.assertInstanceOf(literalExpression.uastParent, USwitchClauseExpressionWithBody::class.java)
}
file.findULiteralExpressionFromPsi("def").let { literalExpression ->
val psi = literalExpression.psi!!
Assert.assertTrue(psi is KtLiteralStringTemplateEntry)
UsefulTestCase.assertInstanceOf(literalExpression.uastParent, USwitchClauseExpressionWithBody::class.java)
}
file.findULiteralExpressionFromPsi("def1").let { literalExpression ->
val psi = literalExpression.psi!!
Assert.assertTrue(psi is KtLiteralStringTemplateEntry)
UsefulTestCase.assertInstanceOf(literalExpression.uastParent, UBlockExpression::class.java)
}
}
}
}
@@ -46,4 +46,6 @@ class SimpleKotlinRenderLogTest : AbstractKotlinRenderLogTest() {
@Test fun testParametersWithDefaultValues() = doTest("ParametersWithDefaultValues")
@Test fun testUnexpectedContainer() = doTest("UnexpectedContainerException") { testName, file -> check(testName, file, false) }
@Test fun testWhenStringLiteral() = doTest("WhenStringLiteral") { testName, file -> check(testName, file, false) }
}