mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-04-18 00:21:29 +00:00
Fix parameter handling in "Move suspicious reference into parentheses"
Related to KT-21743
This commit is contained in:
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.builtins.isBuiltinFunctionalTypeOrSubtype
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
|
||||
import org.jetbrains.kotlin.idea.intentions.ConvertLambdaToReferenceIntention
|
||||
import org.jetbrains.kotlin.idea.intentions.getCallableDescriptor
|
||||
import org.jetbrains.kotlin.psi.KtCallableReferenceExpression
|
||||
@@ -67,12 +68,16 @@ class MoveSuspiciousCallableReferenceIntoParenthesesInspection : AbstractKotlinI
|
||||
""
|
||||
} else {
|
||||
val descriptor = receiverExpression.getCallableDescriptor()
|
||||
if (descriptor == null || descriptor is ValueParameterDescriptor)
|
||||
val literal = element.functionLiteral
|
||||
if (descriptor == null ||
|
||||
descriptor is ValueParameterDescriptor && descriptor.containingDeclaration == literal.resolveToDescriptorIfAny()
|
||||
) {
|
||||
callableReference.resolveToCall(BodyResolveMode.FULL)
|
||||
?.let { it.extensionReceiver ?: it.dispatchReceiver }
|
||||
?.let { "${it.type}" } ?: ""
|
||||
else
|
||||
} else {
|
||||
receiverExpression.text
|
||||
}
|
||||
}
|
||||
return "$receiver::${callableReference.text}"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// FIX: Move suspicious callable reference into parentheses '()'
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(bar: Int) {
|
||||
listOf(1,2,3).map {<caret> bar::plus }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// FIX: Move suspicious callable reference into parentheses '()'
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(bar: Int) {
|
||||
listOf(1,2,3).map(bar::plus)
|
||||
}
|
||||
@@ -2361,6 +2361,12 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("parameterOuter.kt")
|
||||
public void testParameterOuter() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/moveSuspiciousCallableReferenceIntoParentheses/parameterOuter.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("variableReceiver.kt")
|
||||
public void testVariableReceiver() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/moveSuspiciousCallableReferenceIntoParentheses/variableReceiver.kt");
|
||||
|
||||
Reference in New Issue
Block a user