KtArrayAccessReference: remove redundant functions

This commit is contained in:
Dmitry Gridin
2021-06-28 20:25:16 +07:00
parent 4b7fa44e80
commit 274bae1d05
@@ -5,14 +5,12 @@
package org.jetbrains.kotlin.idea.references
import com.google.common.collect.Lists
import com.intellij.psi.MultiRangeReference
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.lexer.KtToken
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getPossiblyQualifiedCallExpression
import org.jetbrains.kotlin.psi.KtArrayAccessExpression
import org.jetbrains.kotlin.util.OperatorNameConventions
abstract class KtArrayAccessReference(
@@ -30,39 +28,9 @@ abstract class KtArrayAccessReference(
override fun canRename() = true
override fun handleElementRename(newElementName: String): PsiElement? {
val arrayAccessExpression = expression
if (OperatorNameConventions.INVOKE.asString() == newElementName) {
val replacement = KtPsiFactory(arrayAccessExpression.project).buildExpression {
val arrayExpression = arrayAccessExpression.arrayExpression
if (arrayExpression is KtQualifiedExpression) {
appendExpression(arrayExpression.receiverExpression)
appendFixedText(arrayExpression.operationSign.value)
appendExpression(arrayExpression.selectorExpression)
} else {
appendExpression(arrayExpression)
}
appendFixedText("(")
appendExpressions(arrayAccessExpression.indexExpressions, ",")
appendFixedText(")")
}
val fullCallExpression = arrayAccessExpression.replace(replacement) as KtExpression
val callExpression = fullCallExpression.getPossiblyQualifiedCallExpression()
if (callExpression != null && canMoveLambdaOutsideParentheses(callExpression)) {
moveFunctionLiteralOutsideParentheses(callExpression)
}
return fullCallExpression
}
return doRenameImplicitConventionalCall(newElementName)
}
protected abstract fun moveFunctionLiteralOutsideParentheses(callExpression: KtCallExpression)
protected abstract fun canMoveLambdaOutsideParentheses(callExpression: KtCallExpression): Boolean
protected abstract fun doRenameImplicitConventionalCall(newName: String?): KtExpression
abstract override fun handleElementRename(newElementName: String): PsiElement?
companion object {
private val NAMES = Lists.newArrayList(OperatorNameConventions.GET, OperatorNameConventions.SET)
private val NAMES = listOf(OperatorNameConventions.GET, OperatorNameConventions.SET)
}
}