From 9412fe094be904b52b7365fb3ee86178f1271315 Mon Sep 17 00:00:00 2001 From: Ilya Muradyan Date: Tue, 18 May 2021 19:04:17 +0300 Subject: [PATCH] [REPL] Copy `findLabelAndCall` to `scripting-ide-services` to fix problems with embeddable artifact --- .../build.gradle.kts | 1 - .../kotlin/idea/util/findLabelAndCall.kt | 40 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 plugins/scripting/scripting-ide-services/src/org/jetbrains/kotlin/idea/util/findLabelAndCall.kt diff --git a/plugins/scripting/scripting-ide-services-test/build.gradle.kts b/plugins/scripting/scripting-ide-services-test/build.gradle.kts index 7a5e19fb50f..b238295d180 100644 --- a/plugins/scripting/scripting-ide-services-test/build.gradle.kts +++ b/plugins/scripting/scripting-ide-services-test/build.gradle.kts @@ -28,7 +28,6 @@ dependencies { testRuntimeOnly(project(":kotlin-compiler")) testRuntimeOnly(commonDep("org.jetbrains.intellij.deps", "trove4j")) testRuntimeOnly(project(":idea:ide-common")) { isTransitive = false } - testRuntimeOnly(project(":idea:idea-frontend-independent")) { isTransitive = false } embeddableTestRuntime(project(":kotlin-scripting-ide-services", configuration="runtimeElements")) embeddableTestRuntime(project(":kotlin-scripting-compiler-impl-embeddable", configuration="runtimeElements")) diff --git a/plugins/scripting/scripting-ide-services/src/org/jetbrains/kotlin/idea/util/findLabelAndCall.kt b/plugins/scripting/scripting-ide-services/src/org/jetbrains/kotlin/idea/util/findLabelAndCall.kt new file mode 100644 index 00000000000..6e4d8aef03f --- /dev/null +++ b/plugins/scripting/scripting-ide-services/src/org/jetbrains/kotlin/idea/util/findLabelAndCall.kt @@ -0,0 +1,40 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.util + +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.psi.* + +/** + * This extension method was copied from `idea:idea-frontend-independent` module because it's the only method that + * included in `idea:idea-frontend-independent` and needed for performing REPL completion + */ +@Suppress("unused") +fun KtFunctionLiteral.findLabelAndCall(): Pair { + val literalParent = (this.parent as KtLambdaExpression).parent + + fun KtValueArgument.callExpression(): KtCallExpression? { + val parent = parent + return (if (parent is KtValueArgumentList) parent else this).parent as? KtCallExpression + } + + when (literalParent) { + is KtLabeledExpression -> { + val callExpression = (literalParent.parent as? KtValueArgument)?.callExpression() + return Pair(literalParent.getLabelNameAsName(), callExpression) + } + + is KtValueArgument -> { + val callExpression = literalParent.callExpression() + val label = (callExpression?.calleeExpression as? KtSimpleNameExpression)?.getReferencedNameAsName() + return Pair(label, callExpression) + } + + else -> { + return Pair(null, null) + } + } +}