"Convert to 'also'" intention: Fix for call expression has this receiver #KT-26009 Fixed
This commit is contained in:
committed by
asedunov
parent
e1dd85429f
commit
be30761ec4
@@ -209,8 +209,10 @@ class ConvertScopeFunctionToParameter(counterpartName: String) : ConvertScopeFun
|
|||||||
if (dispatchReceiverTarget == lambdaDescriptor || extensionReceiverTarget == lambdaDescriptor) {
|
if (dispatchReceiverTarget == lambdaDescriptor || extensionReceiverTarget == lambdaDescriptor) {
|
||||||
val parent = expression.parent
|
val parent = expression.parent
|
||||||
if (parent is KtCallExpression && expression == parent.calleeExpression) {
|
if (parent is KtCallExpression && expression == parent.calleeExpression) {
|
||||||
replacements.add(parent) { element ->
|
if ((parent.parent as? KtQualifiedExpression)?.receiverExpression !is KtThisExpression) {
|
||||||
factory.createExpressionByPattern("$0.$1", parameterName, element)
|
replacements.add(parent) { element ->
|
||||||
|
factory.createExpressionByPattern("$0.$1", parameterName, element)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (parent is KtQualifiedExpression && parent.receiverExpression is KtThisExpression) {
|
} else if (parent is KtQualifiedExpression && parent.receiverExpression is KtThisExpression) {
|
||||||
// do nothing
|
// do nothing
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
// FIX: Convert to 'also'
|
||||||
|
|
||||||
|
val x = hashSetOf<String>().<caret>apply {
|
||||||
|
this.add("x")
|
||||||
|
}
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
// FIX: Convert to 'also'
|
||||||
|
|
||||||
|
val x = hashSetOf<String>().<caret>also {
|
||||||
|
it.add("x")
|
||||||
|
}
|
||||||
+5
@@ -5410,6 +5410,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
|||||||
runTest("idea/testData/inspectionsLocal/scopeFunctions/applyToAlso/method.kt");
|
runTest("idea/testData/inspectionsLocal/scopeFunctions/applyToAlso/method.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("methodWithThis.kt")
|
||||||
|
public void testMethodWithThis() throws Exception {
|
||||||
|
runTest("idea/testData/inspectionsLocal/scopeFunctions/applyToAlso/methodWithThis.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("outerLambda.kt")
|
@TestMetadata("outerLambda.kt")
|
||||||
public void testOuterLambda() throws Exception {
|
public void testOuterLambda() throws Exception {
|
||||||
runTest("idea/testData/inspectionsLocal/scopeFunctions/applyToAlso/outerLambda.kt");
|
runTest("idea/testData/inspectionsLocal/scopeFunctions/applyToAlso/outerLambda.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user