From b638febc41d8cccb5a56ba6fea6a32b059e1816b Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 13 Sep 2017 12:58:58 +0200 Subject: [PATCH] Fix conversion of destructuring declarations --- .../uast/kotlin/KotlinUastLanguagePlugin.kt | 7 ++++--- .../testData/DestructuringDeclaration.kt | 3 +++ .../testData/DestructuringDeclaration.log.txt | 21 +++++++++++++++++++ .../DestructuringDeclaration.render.txt | 7 +++++++ .../tests/SimpleKotlinRenderLogTest.kt | 4 +++- 5 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 plugins/uast-kotlin/testData/DestructuringDeclaration.kt create mode 100644 plugins/uast-kotlin/testData/DestructuringDeclaration.log.txt create mode 100644 plugins/uast-kotlin/testData/DestructuringDeclaration.render.txt diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt index 8e8c11004de..7f601ac0b99 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt @@ -285,13 +285,14 @@ internal object KotlinConverter { } } is KtDestructuringDeclaration -> expr { - KotlinUDeclarationsExpression(givenParent).apply { - val tempAssignment = KotlinULocalVariable(UastKotlinPsiVariable.create(expression, uastParent!!), givenParent) + val declarationsExpression = KotlinUDeclarationsExpression(givenParent) + declarationsExpression.apply { + val tempAssignment = KotlinULocalVariable(UastKotlinPsiVariable.create(expression, declarationsExpression), declarationsExpression) val destructuringAssignments = expression.entries.mapIndexed { i, entry -> val psiFactory = KtPsiFactory(expression.project) val initializer = psiFactory.createAnalyzableExpression("${tempAssignment.name}.component${i + 1}()", expression.containingFile) - KotlinULocalVariable(UastKotlinPsiVariable.create(entry, tempAssignment.psi, uastParent!!, initializer), givenParent) + KotlinULocalVariable(UastKotlinPsiVariable.create(entry, tempAssignment.psi, declarationsExpression, initializer), declarationsExpression) } declarations = listOf(tempAssignment) + destructuringAssignments } diff --git a/plugins/uast-kotlin/testData/DestructuringDeclaration.kt b/plugins/uast-kotlin/testData/DestructuringDeclaration.kt new file mode 100644 index 00000000000..7d7e604ed29 --- /dev/null +++ b/plugins/uast-kotlin/testData/DestructuringDeclaration.kt @@ -0,0 +1,3 @@ +fun foo() { + val (a, b) = "foo" to 1 +} diff --git a/plugins/uast-kotlin/testData/DestructuringDeclaration.log.txt b/plugins/uast-kotlin/testData/DestructuringDeclaration.log.txt new file mode 100644 index 00000000000..aa299050640 --- /dev/null +++ b/plugins/uast-kotlin/testData/DestructuringDeclaration.log.txt @@ -0,0 +1,21 @@ +UFile (package = ) + UClass (name = DestructuringDeclarationKt) + UAnnotationMethod (name = foo) + UBlockExpression + UDeclarationsExpression + ULocalVariable (name = var268d4034) + UBinaryExpression (operator = ) + ULiteralExpression (value = "foo") + ULiteralExpression (value = 1) + ULocalVariable (name = a) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = var268d4034) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (component1)) + USimpleNameReferenceExpression (identifier = ) + ULocalVariable (name = b) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = var268d4034) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (component2)) + USimpleNameReferenceExpression (identifier = ) diff --git a/plugins/uast-kotlin/testData/DestructuringDeclaration.render.txt b/plugins/uast-kotlin/testData/DestructuringDeclaration.render.txt new file mode 100644 index 00000000000..576307cf1ec --- /dev/null +++ b/plugins/uast-kotlin/testData/DestructuringDeclaration.render.txt @@ -0,0 +1,7 @@ +public final class DestructuringDeclarationKt { + public static final fun foo() : void { + var var268d4034: kotlin.Pair = "foo" 1 + var a: = var268d4034.() + var b: = var268d4034.() + } +} diff --git a/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt b/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt index f3d47239e54..762e2fa9d60 100644 --- a/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt +++ b/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt @@ -37,7 +37,9 @@ class SimpleKotlinRenderLogTest : AbstractKotlinRenderLogTest() { @Test fun testSimpleScript() = doTest("SimpleScript") + @Test fun testDestructuringDeclaration() = doTest("DestructuringDeclaration") + @Test fun testParameterPropertyWithAnnotation() = doTest("ParameterPropertyWithAnnotation") @Test fun testParametersWithDefaultValues() = doTest("ParametersWithDefaultValues") -} \ No newline at end of file +}