diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUFunctionCallExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUFunctionCallExpression.kt index 46fa81c660f..4b328da46f9 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUFunctionCallExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUFunctionCallExpression.kt @@ -82,7 +82,10 @@ class KotlinUFunctionCallExpression( ) is KtLambdaExpression -> KotlinUIdentifier(calleeExpression.functionLiteral.lBrace, this) - else -> KotlinUIdentifier(calleeExpression, this) + else -> KotlinUIdentifier( + sourcePsi.valueArgumentList?.leftParenthesis + ?: sourcePsi.lambdaArguments.singleOrNull()?.getLambdaExpression()?.functionLiteral?.lBrace + ?: calleeExpression, this) } } diff --git a/plugins/uast-kotlin/testData/NonTrivialIdentifiers.identifiers.txt b/plugins/uast-kotlin/testData/NonTrivialIdentifiers.identifiers.txt new file mode 100644 index 00000000000..896be53a3ca --- /dev/null +++ b/plugins/uast-kotlin/testData/NonTrivialIdentifiers.identifiers.txt @@ -0,0 +1,17 @@ +A -> UClass (name = A) +invoke -> UMethod (name = invoke) + this -> USimpleNameReferenceExpression (identifier = this) +invoke -> UMethod (name = invoke) +f -> UParameter (name = f) +Unit -> USimpleNameReferenceExpression (identifier = Unit) +main -> UMethod (name = main) +a -> UParameter (name = a) +A -> USimpleNameReferenceExpression (identifier = A) + a -> USimpleNameReferenceExpression (identifier = a) + !! -> USimpleNameReferenceExpression (identifier = !!) + p -> ULocalVariable (name = p) + A -> UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) + a -> USimpleNameReferenceExpression (identifier = a) + !! -> USimpleNameReferenceExpression (identifier = !!) + p -> UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + A -> UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) diff --git a/plugins/uast-kotlin/testData/NonTrivialIdentifiers.kt b/plugins/uast-kotlin/testData/NonTrivialIdentifiers.kt new file mode 100644 index 00000000000..e67e145e5af --- /dev/null +++ b/plugins/uast-kotlin/testData/NonTrivialIdentifiers.kt @@ -0,0 +1,21 @@ +class A { + + operator fun invoke(){ + this() + } + + operator fun invoke(f: ()-> Unit){ + + } + +} + +fun main(a: A?){ + a!!() + val p = A() + a!! { + p { + A()() + } + } +} \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/NonTrivialIdentifiers.log.txt b/plugins/uast-kotlin/testData/NonTrivialIdentifiers.log.txt new file mode 100644 index 00000000000..4291e10bc4a --- /dev/null +++ b/plugins/uast-kotlin/testData/NonTrivialIdentifiers.log.txt @@ -0,0 +1,38 @@ +UFile (package = ) + UClass (name = NonTrivialIdentifiersKt) + UMethod (name = main) + UParameter (name = a) + UAnnotation (fqName = org.jetbrains.annotations.Nullable) + UBlockExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (()) + USimpleNameReferenceExpression (identifier = invoke, resolvesTo = null) + UDeclarationsExpression + ULocalVariable (name = p) + UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) + UIdentifier (Identifier (A)) + USimpleNameReferenceExpression (identifier = , resolvesTo = A) + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier ({)) + USimpleNameReferenceExpression (identifier = invoke, resolvesTo = null) + ULambdaExpression + UBlockExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) + UIdentifier (Identifier (p)) + USimpleNameReferenceExpression (identifier = invoke, resolvesTo = null) + ULambdaExpression + UBlockExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (()) + USimpleNameReferenceExpression (identifier = invoke, resolvesTo = null) + UClass (name = A) + UMethod (name = invoke) + UBlockExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (()) + USimpleNameReferenceExpression (identifier = invoke, resolvesTo = null) + UMethod (name = invoke) + UParameter (name = f) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UMethod (name = A) diff --git a/plugins/uast-kotlin/testData/NonTrivialIdentifiers.refNames.txt b/plugins/uast-kotlin/testData/NonTrivialIdentifiers.refNames.txt new file mode 100644 index 00000000000..c97e29327e0 --- /dev/null +++ b/plugins/uast-kotlin/testData/NonTrivialIdentifiers.refNames.txt @@ -0,0 +1,7 @@ +Unit -> USimpleNameReferenceExpression (identifier = Unit) from KtNameReferenceExpression +A -> USimpleNameReferenceExpression (identifier = A) from KtNameReferenceExpression +a -> USimpleNameReferenceExpression (identifier = a) from KtNameReferenceExpression +A -> UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) from KtNameReferenceExpression +a -> USimpleNameReferenceExpression (identifier = a) from KtNameReferenceExpression +p -> UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) from KtNameReferenceExpression +A -> UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) from KtNameReferenceExpression diff --git a/plugins/uast-kotlin/testData/NonTrivialIdentifiers.render.txt b/plugins/uast-kotlin/testData/NonTrivialIdentifiers.render.txt new file mode 100644 index 00000000000..c87a219431a --- /dev/null +++ b/plugins/uast-kotlin/testData/NonTrivialIdentifiers.render.txt @@ -0,0 +1,20 @@ +public final class NonTrivialIdentifiersKt { + public static final fun main(@org.jetbrains.annotations.Nullable a: A) : void { + invoke() + var p: A = () + invoke({ + invoke({ + invoke() + }) + }) + } +} + +public final class A { + public final fun invoke() : void { + invoke() + } + public final fun invoke(@org.jetbrains.annotations.NotNull f: kotlin.jvm.functions.Function0) : void { + } + public fun A() = UastEmptyExpression +} diff --git a/plugins/uast-kotlin/tests/KotlinUastIdentifiersTest.kt b/plugins/uast-kotlin/tests/KotlinUastIdentifiersTest.kt index 4e2870f5240..378667cfabd 100644 --- a/plugins/uast-kotlin/tests/KotlinUastIdentifiersTest.kt +++ b/plugins/uast-kotlin/tests/KotlinUastIdentifiersTest.kt @@ -36,4 +36,7 @@ class KotlinUastIdentifiersTest : AbstractKotlinIdentifiersTest() { @Test fun testEnumValuesConstructors() = doTest("EnumValuesConstructors") + @Test + fun testNonTrivialIdentifiers() = doTest("NonTrivialIdentifiers") + } \ No newline at end of file diff --git a/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt b/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt index 549ed909334..70e9e95f944 100644 --- a/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt +++ b/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt @@ -147,6 +147,9 @@ class SimpleKotlinRenderLogTest : AbstractKotlinUastTest(), AbstractKotlinRender @Test fun testAnnotatedExpressions() = doTest("AnnotatedExpressions") + + @Test + fun testNonTrivialIdentifiers() = doTest("NonTrivialIdentifiers") } fun withForceUInjectionHostValue(call: () -> Unit) {