Rename: Make improvements for "by-convention" calls
- Convert between conventions call for 'get' and 'invoke' - Drop 'operator' when converting 'get'/'invoke' to something other than 'invoke'/'get' respectively #KT-12365 Fixed
This commit is contained in:
+17
-2
@@ -27,8 +27,7 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.KtArrayAccessExpression;
|
||||
import org.jetbrains.kotlin.psi.KtContainerNode;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions;
|
||||
@@ -98,6 +97,22 @@ public class KtArrayAccessReference extends KtSimpleReference<KtArrayAccessExpre
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiElement handleElementRename(@Nullable String newElementName) {
|
||||
KtArrayAccessExpression arrayAccessExpression = getExpression();
|
||||
if (OperatorNameConventions.INVOKE.asString().equals(newElementName)) {
|
||||
KtExpression callExpression = CreateByPatternKt.buildExpression(
|
||||
new KtPsiFactory(arrayAccessExpression.getProject()),
|
||||
true,
|
||||
pattern -> {
|
||||
pattern.appendExpression(arrayAccessExpression.getArrayExpression());
|
||||
pattern.appendFixedText("(");
|
||||
pattern.appendExpressions(arrayAccessExpression.getIndexExpressions(), ",");
|
||||
pattern.appendFixedText(")");
|
||||
return null;
|
||||
}
|
||||
);
|
||||
return arrayAccessExpression.replace(callExpression);
|
||||
}
|
||||
|
||||
return ReferenceUtilKt.renameImplicitConventionalCall(this, newElementName);
|
||||
}
|
||||
|
||||
|
||||
+15
-4
@@ -23,9 +23,7 @@ import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.Call
|
||||
import org.jetbrains.kotlin.psi.KtCallExpression
|
||||
import org.jetbrains.kotlin.psi.unpackFunctionLiteral
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getCall
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||
@@ -95,7 +93,20 @@ class KtInvokeFunctionReference(expression: KtCallExpression) : KtSimpleReferenc
|
||||
|
||||
override fun canRename(): Boolean = true
|
||||
|
||||
override fun handleElementRename(newElementName: String?): PsiElement? = renameImplicitConventionalCall(newElementName)
|
||||
override fun handleElementRename(newElementName: String?): PsiElement? {
|
||||
val callExpression = expression
|
||||
if (newElementName == OperatorNameConventions.GET.asString() && callExpression.typeArguments.isEmpty()) {
|
||||
val arrayAccessExpression = KtPsiFactory(callExpression).buildExpression {
|
||||
appendExpression(callExpression.calleeExpression)
|
||||
appendFixedText("[")
|
||||
appendExpressions(callExpression.valueArguments.map { it.getArgumentExpression() })
|
||||
appendFixedText("]")
|
||||
}
|
||||
return callExpression.replace(arrayAccessExpression)
|
||||
}
|
||||
|
||||
return renameImplicitConventionalCall(newElementName)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user