Refactoring: move KtExpression.unpackFunctionLiteral to utils file

This commit is contained in:
Nikolay Krasko
2018-10-15 14:00:59 +03:00
parent 7c49eeded7
commit 0f0dfe725e
2 changed files with 10 additions and 10 deletions
@@ -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
}
}
@@ -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
}
}