diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt index 4d368fae6ee..e8ba59dbb81 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt @@ -546,6 +546,32 @@ fun KtFunctionLiteral.getOrCreateParameterList(): KtParameterList { return newParameterList } +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) + } + } +} + fun KtCallExpression.getOrCreateValueArgumentList(): KtValueArgumentList { valueArgumentList?.let { return it } return addAfter( diff --git a/plugins/scripting/scripting-ide-common/src/org/jetbrains/kotlin/idea/util/implicitReceiversUtils.kt b/plugins/scripting/scripting-ide-common/src/org/jetbrains/kotlin/idea/util/implicitReceiversUtils.kt index 9db1ab463f0..33abeb65578 100644 --- a/plugins/scripting/scripting-ide-common/src/org/jetbrains/kotlin/idea/util/implicitReceiversUtils.kt +++ b/plugins/scripting/scripting-ide-common/src/org/jetbrains/kotlin/idea/util/implicitReceiversUtils.kt @@ -11,6 +11,7 @@ import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.KtExpression import org.jetbrains.kotlin.psi.KtFunctionLiteral import org.jetbrains.kotlin.psi.KtPsiFactory +import org.jetbrains.kotlin.psi.psiUtil.findLabelAndCall import org.jetbrains.kotlin.renderer.render import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils import org.jetbrains.kotlin.resolve.DescriptorUtils 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 deleted file mode 100644 index 6e4d8aef03f..00000000000 --- a/plugins/scripting/scripting-ide-services/src/org/jetbrains/kotlin/idea/util/findLabelAndCall.kt +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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) - } - } -}