From 92c23aa0ed1d0039a47b8e391aa0a1adafe4e3e8 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gerasimov Date: Fri, 14 Jul 2017 16:12:52 +0300 Subject: [PATCH] UAST: override getFunctionalInterfaceType + test --- .../expressions/KotlinULambdaExpression.kt | 2 +- .../uast/kotlin/expressions/LocalFunction.kt | 3 +-- .../uast-kotlin/tests/KotlinUastApiTest.kt | 21 +++++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinULambdaExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinULambdaExpression.kt index 3259aa4d6ce..b40a5e5dab3 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinULambdaExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinULambdaExpression.kt @@ -28,7 +28,7 @@ class KotlinULambdaExpression( override val psi: KtLambdaExpression, givenParent: UElement? ) : KotlinAbstractUExpression(givenParent), ULambdaExpression, KotlinUElementWithType { - val functionalInterfaceType: PsiType? + override val functionalInterfaceType: PsiType? get() = getFunctionalInterfaceType() override val body by lz { KotlinConverter.convertOrEmpty(psi.bodyExpression, this) } diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/LocalFunction.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/LocalFunction.kt index 822e862c5e2..094fbbf7cfc 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/LocalFunction.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/LocalFunction.kt @@ -27,8 +27,7 @@ private class KotlinLocalFunctionULambdaExpression( override val psi: KtFunction, givenParent: UElement? ): KotlinAbstractUExpression(givenParent), ULambdaExpression { - val functionalInterfaceType: PsiType? - get() = null + override val functionalInterfaceType: PsiType? = null override val body by lz { KotlinConverter.convertOrEmpty(psi.bodyExpression, this) } diff --git a/plugins/uast-kotlin/tests/KotlinUastApiTest.kt b/plugins/uast-kotlin/tests/KotlinUastApiTest.kt index 11beb41d182..3d84c3e97b1 100644 --- a/plugins/uast-kotlin/tests/KotlinUastApiTest.kt +++ b/plugins/uast-kotlin/tests/KotlinUastApiTest.kt @@ -80,6 +80,27 @@ class KotlinUastApiTest : AbstractKotlinUastTest() { } } + @Test fun testSAM() { + doTest("SAM") { _, file -> + assertNull(file.findElementByText("{ /* Not SAM */ }").functionalInterfaceType) + + assertEquals("java.lang.Runnable", + file.findElementByText("{/* Variable */}").functionalInterfaceType?.canonicalText) + + assertEquals("java.lang.Runnable", + file.findElementByText("{/* Assignment */}").functionalInterfaceType?.canonicalText) + + assertEquals("java.lang.Runnable", + file.findElementByText("{/* Type Cast */}").functionalInterfaceType?.canonicalText) + + assertEquals("java.lang.Runnable", + file.findElementByText("{/* Argument */}").functionalInterfaceType?.canonicalText) + + assertEquals("java.lang.Runnable", + file.findElementByText("{/* Return */}").functionalInterfaceType?.canonicalText) + } + } + @Test fun testParameterPropertyWithAnnotation() { doTest("ParameterPropertyWithAnnotation") { _, file -> val test1 = file.classes.find { it.name == "Test1" }!!