Move KtFunctionLiteral.findLabelAndCall from kotlin-ide.frontend-independent to compiler.psi
I want to be able to use this function in `:kotlin-scripting-ide-common` & `frontend-independent` This commit also allows to remove copy-pasted `findLabelAndCall` in `scripting-ide-services` module
This commit is contained in:
@@ -546,6 +546,32 @@ fun KtFunctionLiteral.getOrCreateParameterList(): KtParameterList {
|
||||
return newParameterList
|
||||
}
|
||||
|
||||
fun KtFunctionLiteral.findLabelAndCall(): Pair<Name?, KtCallExpression?> {
|
||||
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(
|
||||
|
||||
Reference in New Issue
Block a user