mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] k2: rename: move lambda outside of parentheses when possible
GitOrigin-RevId: dafae17d7a54aa67625df440fa8111bef11486cc
This commit is contained in:
committed by
intellij-monorepo-bot
parent
5b5d79bfab
commit
9b0548f1ba
+2
-11
@@ -17,8 +17,6 @@ import org.jetbrains.kotlin.idea.codeInsight.shorten.addDelayedImportRequest
|
||||
import org.jetbrains.kotlin.idea.codeInsight.shorten.addToShorteningWaitSet
|
||||
import org.jetbrains.kotlin.idea.core.ShortenReferences
|
||||
import org.jetbrains.kotlin.idea.core.canMoveLambdaOutsideParentheses
|
||||
import org.jetbrains.kotlin.idea.refactoring.intentions.OperatorToFunctionConverter
|
||||
import org.jetbrains.kotlin.idea.refactoring.moveFunctionLiteralOutsideParentheses
|
||||
import org.jetbrains.kotlin.idea.references.KtReference
|
||||
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
|
||||
import org.jetbrains.kotlin.idea.references.KtSimpleReference
|
||||
@@ -188,14 +186,7 @@ class K1ReferenceMutateService : KtReferenceMutateServiceBase() {
|
||||
return selector as KtNameReferenceExpression
|
||||
}
|
||||
|
||||
override fun replaceWithImplicitInvokeInvocation(newExpression: KtDotQualifiedExpression): KtExpression? {
|
||||
val canMoveLambda = newExpression.getPossiblyQualifiedCallExpression()?.canMoveLambdaOutsideParentheses() == true
|
||||
return OperatorToFunctionConverter.replaceExplicitInvokeCallWithImplicit(newExpression)?.let { newQualifiedExpression ->
|
||||
newQualifiedExpression.getPossiblyQualifiedCallExpression()
|
||||
?.takeIf { canMoveLambda }
|
||||
?.let(KtCallExpression::moveFunctionLiteralOutsideParentheses)
|
||||
|
||||
newQualifiedExpression
|
||||
}
|
||||
override fun canMoveLambdaOutsideParentheses(newExpression: KtDotQualifiedExpression): Boolean {
|
||||
return newExpression.getPossiblyQualifiedCallExpression()?.canMoveLambdaOutsideParentheses() == true
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -4,5 +4,5 @@
|
||||
"oldName": "get",
|
||||
"newName": "invoke",
|
||||
"mainFile": "main.kt",
|
||||
"enabledInK2": "false"
|
||||
"enabledInK2": "true"
|
||||
}
|
||||
+13
-1
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.idea.base.psi.replaced
|
||||
import org.jetbrains.kotlin.idea.base.psi.unquoteKotlinIdentifier
|
||||
import org.jetbrains.kotlin.idea.kdoc.KDocElementFactory
|
||||
import org.jetbrains.kotlin.idea.refactoring.intentions.OperatorToFunctionConverter
|
||||
import org.jetbrains.kotlin.idea.refactoring.moveFunctionLiteralOutsideParentheses
|
||||
import org.jetbrains.kotlin.idea.references.*
|
||||
import org.jetbrains.kotlin.lexer.KtSingleValueToken
|
||||
import org.jetbrains.kotlin.lexer.KtToken
|
||||
@@ -252,7 +253,18 @@ abstract class KtReferenceMutateServiceBase : KtReferenceMutateService {
|
||||
private fun convertOperatorToFunctionCall(opExpression: KtOperationExpression): Pair<KtExpression, KtSimpleNameExpression> =
|
||||
OperatorToFunctionConverter.convert(opExpression)
|
||||
|
||||
protected abstract fun replaceWithImplicitInvokeInvocation(newExpression: KtDotQualifiedExpression): KtExpression?
|
||||
protected abstract fun canMoveLambdaOutsideParentheses(newExpression: KtDotQualifiedExpression): Boolean
|
||||
|
||||
protected fun replaceWithImplicitInvokeInvocation(newExpression: KtDotQualifiedExpression): KtExpression? {
|
||||
val canMoveLambda = canMoveLambdaOutsideParentheses(newExpression)
|
||||
return OperatorToFunctionConverter.replaceExplicitInvokeCallWithImplicit(newExpression)?.let { newQualifiedExpression ->
|
||||
newQualifiedExpression.getPossiblyQualifiedCallExpression()
|
||||
?.takeIf { canMoveLambda }
|
||||
?.let(KtCallExpression::moveFunctionLiteralOutsideParentheses)
|
||||
|
||||
newQualifiedExpression
|
||||
}
|
||||
}
|
||||
|
||||
private fun AbstractKtReference<out KtExpression>.renameImplicitConventionalCall(newName: String): KtExpression {
|
||||
val (newExpression, newNameElement) = OperatorToFunctionConverter.convert(expression)
|
||||
|
||||
+5
-3
@@ -19,7 +19,6 @@ import org.jetbrains.kotlin.idea.base.codeInsight.KotlinOptimizeImportsFacility
|
||||
import org.jetbrains.kotlin.idea.base.psi.kotlinFqName
|
||||
import org.jetbrains.kotlin.idea.base.psi.replaced
|
||||
import org.jetbrains.kotlin.idea.kdoc.KDocElementFactory
|
||||
import org.jetbrains.kotlin.idea.refactoring.intentions.OperatorToFunctionConverter
|
||||
import org.jetbrains.kotlin.idea.refactoring.rename.KtReferenceMutateServiceBase
|
||||
import org.jetbrains.kotlin.idea.references.KDocReference
|
||||
import org.jetbrains.kotlin.idea.references.KtReference
|
||||
@@ -27,7 +26,9 @@ import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
|
||||
import org.jetbrains.kotlin.idea.references.KtSimpleReference
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getPossiblyQualifiedCallExpression
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElement
|
||||
|
||||
/**
|
||||
* At the moment, this implementation of [org.jetbrains.kotlin.idea.references.KtReferenceMutateService] is not able to do some of the
|
||||
* required operations. It is OK and on purpose - this functionality will be added later.
|
||||
@@ -186,8 +187,9 @@ internal class K2ReferenceMutateService : KtReferenceMutateServiceBase() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun replaceWithImplicitInvokeInvocation(newExpression: KtDotQualifiedExpression): KtExpression? =
|
||||
OperatorToFunctionConverter.replaceExplicitInvokeCallWithImplicit(newExpression)
|
||||
override fun canMoveLambdaOutsideParentheses(newExpression: KtDotQualifiedExpression): Boolean {
|
||||
return newExpression.getPossiblyQualifiedCallExpression()?.canMoveLambdaOutsideParentheses() == true
|
||||
}
|
||||
|
||||
private fun operationNotSupportedInK2Error(): Nothing {
|
||||
throw IncorrectOperationException("K2 plugin does not yet support this operation")
|
||||
|
||||
Reference in New Issue
Block a user