Refactoring: move KtExpression.unpackFunctionLiteral to utils file
This commit is contained in:
@@ -23,14 +23,4 @@ class KtLambdaArgument(node: ASTNode) : KtValueArgument(node), LambdaArgument {
|
|||||||
override fun getLambdaExpression(): KtLambdaExpression? = getArgumentExpression()?.unpackFunctionLiteral()
|
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
|
val lastSiblingToDelete = PsiTreeUtil.skipSiblingsForward(sibling, PsiWhiteSpace::class.java)?.prevSibling ?: sibling
|
||||||
parent.deleteChildRange(nextSibling, lastSiblingToDelete)
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user