Changes on code review
This commit is contained in:
+3
-4
@@ -29,20 +29,19 @@ import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForSelector
|
||||
|
||||
class InvokeOnExtensionFunctionWithExplicitReceiverFix(qualifiedExpression: KtDotQualifiedExpression) : KotlinQuickFixAction<KtDotQualifiedExpression>(qualifiedExpression), CleanupFix {
|
||||
override fun getFamilyName() = "Fix extension function value call"
|
||||
override fun getFamilyName() = "Surround callee with parenthesis"
|
||||
override fun getText() = familyName
|
||||
|
||||
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
||||
val callExpression = element.selectorExpression as KtCallExpression
|
||||
val pattern = if (element is KtSafeQualifiedExpression)"($0?.$1)" else "($0.$1)"
|
||||
val newCallee = KtPsiFactory(file).createExpressionByPattern(pattern, element.receiverExpression, callExpression.calleeExpression!!)
|
||||
val newCallee = KtPsiFactory(file).createExpressionByPattern("($0.$1)", element.receiverExpression, callExpression.calleeExpression!!)
|
||||
val newCallExpression = element.replaced(callExpression)
|
||||
newCallExpression.calleeExpression!!.replace(newCallee)
|
||||
}
|
||||
|
||||
companion object : KotlinSingleIntentionActionFactory() {
|
||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
||||
val callee = Errors.INVOKE_ON_EXTENSION_FUNCTION_WITH_EXPLICIT_DISPATCH_RECEIVER.cast(diagnostic).a as? KtNameReferenceExpression ?: return null
|
||||
val callee = Errors.INVOKE_ON_EXTENSION_FUNCTION_WITH_EXPLICIT_DISPATCH_RECEIVER.cast(diagnostic).psiElement as? KtNameReferenceExpression ?: return null
|
||||
val callExpression = callee.parent as? KtCallExpression ?: return null
|
||||
val qualifiedExpression = callExpression.getQualifiedExpressionForSelector() as? KtDotQualifiedExpression ?: return null
|
||||
return InvokeOnExtensionFunctionWithExplicitReceiverFix(qualifiedExpression)
|
||||
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
// "Surround callee with parenthesis" "true"
|
||||
|
||||
class A {
|
||||
val foo: B.(String, Int) -> Unit get() = null!!
|
||||
}
|
||||
|
||||
class B {
|
||||
fun getA() = A()
|
||||
}
|
||||
|
||||
|
||||
fun test(b: B) {
|
||||
with(b) {
|
||||
b.getA().<caret>foo("", 1)
|
||||
}
|
||||
}
|
||||
|
||||
public inline fun <T, R> with(receiver: T, f: T.() -> R): R = receiver.f()
|
||||
idea/testData/quickfix/migration/invokeOnExtensionFunctionWithExplicitReceiverFix/notSimple.kt.after
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
// "Surround callee with parenthesis" "true"
|
||||
|
||||
class A {
|
||||
val foo: B.(String, Int) -> Unit get() = null!!
|
||||
}
|
||||
|
||||
class B {
|
||||
fun getA() = A()
|
||||
}
|
||||
|
||||
|
||||
fun test(b: B) {
|
||||
with(b) {
|
||||
(b.getA().foo)("", 1)
|
||||
}
|
||||
}
|
||||
|
||||
public inline fun <T, R> with(receiver: T, f: T.() -> R): R = receiver.f()
|
||||
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Fix extension function value call" "true"
|
||||
// "Surround callee with parenthesis" "true"
|
||||
|
||||
class A {
|
||||
val foo: B.() -> Unit get() = null!!
|
||||
|
||||
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Fix extension function value call" "true"
|
||||
// "Surround callee with parenthesis" "true"
|
||||
|
||||
class A {
|
||||
val foo: B.() -> Unit get() = null!!
|
||||
|
||||
@@ -4369,6 +4369,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/migration/invokeOnExtensionFunctionWithExplicitReceiverFix"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("notSimple.kt")
|
||||
public void testNotSimple() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/migration/invokeOnExtensionFunctionWithExplicitReceiverFix/notSimple.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/migration/invokeOnExtensionFunctionWithExplicitReceiverFix/simple.kt");
|
||||
|
||||
Reference in New Issue
Block a user