diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinAbstractUElement.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinAbstractUElement.kt index 5feb90aff7c..9c71e18f054 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinAbstractUElement.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinAbstractUElement.kt @@ -90,6 +90,14 @@ abstract class KotlinAbstractUElement(private val givenParent: UElement?) : UEle parent = parent.parent } + if (psi is KtFunctionLiteral && parent is KtLambdaExpression) { + parent = parent.parent + } + + if (parent is KtLambdaArgument) { + parent = parent.parent + } + if (psi is KtSuperTypeCallEntry) { parent = parent?.parent } 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 73ddf132a62..4a96e939178 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt @@ -166,7 +166,7 @@ class KotlinUastLanguagePlugin : UastLanguagePlugin { is KtFunction -> if (original.isLocal) { el { - if (original.name.isNullOrEmpty()) { + if (original.name.isNullOrEmpty() || original.parent is KtLambdaExpression) { createLocalFunctionLambdaExpression(original, givenParent) } else { diff --git a/plugins/uast-kotlin/testData/Anonymous.kt b/plugins/uast-kotlin/testData/Anonymous.kt index b9b1a5bff64..5c7b53ee275 100644 --- a/plugins/uast-kotlin/testData/Anonymous.kt +++ b/plugins/uast-kotlin/testData/Anonymous.kt @@ -5,6 +5,8 @@ import java.io.InputStream fun foo() { val runnable = object : Runnable { override fun run() {} } runnable.run() + val runnable2 = Runnable { println() } + runnable2.run() val closeableRunnable = object : Runnable, Closeable { override fun close() {} override fun run() {} } val runnableIs = object : InputStream(), Runnable { override fun read(): Int = 0; override fun run() {} } } \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/Anonymous.log.txt b/plugins/uast-kotlin/testData/Anonymous.log.txt index a32d211c109..5588ec211eb 100644 --- a/plugins/uast-kotlin/testData/Anonymous.log.txt +++ b/plugins/uast-kotlin/testData/Anonymous.log.txt @@ -16,6 +16,21 @@ UFile (package = ) UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) UIdentifier (Identifier (run)) USimpleNameReferenceExpression (identifier = run) + UDeclarationsExpression + ULocalVariable (name = runnable2) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (Runnable)) + USimpleNameReferenceExpression (identifier = Runnable) + ULambdaExpression + UBlockExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (println)) + USimpleNameReferenceExpression (identifier = println) + UQualifiedReferenceExpression + USimpleNameReferenceExpression (identifier = runnable2) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (run)) + USimpleNameReferenceExpression (identifier = run) UDeclarationsExpression ULocalVariable (name = closeableRunnable) UObjectLiteralExpression diff --git a/plugins/uast-kotlin/testData/Anonymous.render.txt b/plugins/uast-kotlin/testData/Anonymous.render.txt index ae3c8e5ed6a..20214e56d9f 100644 --- a/plugins/uast-kotlin/testData/Anonymous.render.txt +++ b/plugins/uast-kotlin/testData/Anonymous.render.txt @@ -5,6 +5,10 @@ public final class AnonymousKt { public static final fun foo() : void { var runnable: = anonymous object : Runnable { override fun run() {} } runnable.run() + var runnable2: java.lang.Runnable = Runnable({ + println() + }) + runnable2.run() var closeableRunnable: = anonymous object : Runnable, Closeable { override fun close() {} override fun run() {} } var runnableIs: = anonymous object : InputStream(), Runnable { override fun read(): Int = 0; override fun run() {} } } diff --git a/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt b/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt index e06cf29402e..18d4d6345b1 100644 --- a/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt +++ b/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt @@ -49,9 +49,11 @@ class SimpleKotlinRenderLogTest : AbstractKotlinRenderLogTest() { @Test fun testParametersWithDefaultValues() = doTest("ParametersWithDefaultValues") - @Test fun testUnexpectedContainer() = doTest("UnexpectedContainerException") { testName, file -> check(testName, file, false) } + @Test + fun testUnexpectedContainer() = doTest("UnexpectedContainerException") - @Test fun testWhenStringLiteral() = doTest("WhenStringLiteral") { testName, file -> check(testName, file, false) } + @Test + fun testWhenStringLiteral() = doTest("WhenStringLiteral") @Test fun testWhenAndDestructing() = doTest("WhenAndDestructing") { testName, file -> check(testName, file, false) }