From 0f0dfe725e86f0fc44e9cdb5008fddbe3187e578 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Mon, 15 Oct 2018 14:00:59 +0300 Subject: [PATCH] Refactoring: move KtExpression.unpackFunctionLiteral to utils file --- .../src/org/jetbrains/kotlin/psi/KtLambdaArgument.kt | 10 ---------- .../psi/src/org/jetbrains/kotlin/psi/ktElementUtils.kt | 10 ++++++++++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtLambdaArgument.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/KtLambdaArgument.kt index 1554d3692f0..b3405718fbc 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtLambdaArgument.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtLambdaArgument.kt @@ -23,14 +23,4 @@ class KtLambdaArgument(node: ASTNode) : KtValueArgument(node), LambdaArgument { override fun getLambdaExpression(): KtLambdaExpression? = getArgumentExpression()?.unpackFunctionLiteral() } -fun KtExpression.unpackFunctionLiteral(allowParentheses: Boolean = false): KtLambdaExpression? { - return when (this) { - is KtLambdaExpression -> this - is KtLabeledExpression -> baseExpression?.unpackFunctionLiteral(allowParentheses) - is KtAnnotatedExpression -> baseExpression?.unpackFunctionLiteral(allowParentheses) - is KtParenthesizedExpression -> if (allowParentheses) expression?.unpackFunctionLiteral(allowParentheses) else null - else -> null - } -} - diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/ktElementUtils.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/ktElementUtils.kt index 0a701a2b903..22ca111aab9 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/ktElementUtils.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/ktElementUtils.kt @@ -30,3 +30,13 @@ internal fun KtElement.deleteSemicolon() { val lastSiblingToDelete = PsiTreeUtil.skipSiblingsForward(sibling, PsiWhiteSpace::class.java)?.prevSibling ?: sibling parent.deleteChildRange(nextSibling, lastSiblingToDelete) } + +fun KtExpression.unpackFunctionLiteral(allowParentheses: Boolean = false): KtLambdaExpression? { + return when (this) { + is KtLambdaExpression -> this + is KtLabeledExpression -> baseExpression?.unpackFunctionLiteral(allowParentheses) + is KtAnnotatedExpression -> baseExpression?.unpackFunctionLiteral(allowParentheses) + is KtParenthesizedExpression -> if (allowParentheses) expression?.unpackFunctionLiteral(allowParentheses) else null + else -> null + } +} \ No newline at end of file