Fix search usages for invoke() extension operator (KT-18269)
#KT-18269 Fixed
This commit is contained in:
+12
-2
@@ -27,8 +27,11 @@ import org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinReferencesSearchOpt
|
|||||||
import org.jetbrains.kotlin.psi.KtCallExpression
|
import org.jetbrains.kotlin.psi.KtCallExpression
|
||||||
import org.jetbrains.kotlin.psi.KtElement
|
import org.jetbrains.kotlin.psi.KtElement
|
||||||
import org.jetbrains.kotlin.psi.KtExpression
|
import org.jetbrains.kotlin.psi.KtExpression
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.isExtensionDeclaration
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
|
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
|
||||||
import org.jetbrains.uast.*
|
import org.jetbrains.uast.UMethod
|
||||||
|
import org.jetbrains.uast.UastContext
|
||||||
|
import org.jetbrains.uast.convertOpt
|
||||||
|
|
||||||
class InvokeOperatorReferenceSearcher(
|
class InvokeOperatorReferenceSearcher(
|
||||||
targetFunction: PsiElement,
|
targetFunction: PsiElement,
|
||||||
@@ -44,7 +47,14 @@ class InvokeOperatorReferenceSearcher(
|
|||||||
val uMethod = uastContext.convertOpt<UMethod>(targetDeclaration, null)
|
val uMethod = uastContext.convertOpt<UMethod>(targetDeclaration, null)
|
||||||
val uastParameters = uMethod?.uastParameters
|
val uastParameters = uMethod?.uastParameters
|
||||||
|
|
||||||
callArgumentsSize = if (uastParameters != null && uastParameters.none { it.uastInitializer != null }) uastParameters.size else null
|
val isStableNumberOfArguments = uastParameters != null && uastParameters.none { it.uastInitializer != null }
|
||||||
|
callArgumentsSize = if (isStableNumberOfArguments) {
|
||||||
|
val numberOfArguments = uastParameters!!.size
|
||||||
|
when {
|
||||||
|
targetFunction.isExtensionDeclaration() -> numberOfArguments - 1
|
||||||
|
else -> numberOfArguments
|
||||||
|
}
|
||||||
|
} else null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun processPossibleReceiverExpression(expression: KtExpression) {
|
override fun processPossibleReceiverExpression(expression: KtExpression) {
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtNamedFunction
|
||||||
|
// OPTIONS: usages
|
||||||
|
package pack
|
||||||
|
|
||||||
|
class P
|
||||||
|
operator fun P.<caret>invoke() = 1
|
||||||
|
|
||||||
|
fun f(p: P) {
|
||||||
|
p()
|
||||||
|
p.invoke()
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
Resolved p()
|
||||||
|
Searched references to pack.P
|
||||||
|
Searched references to parameter p of pack.f(p: P) in non-Java files
|
||||||
|
Used plain search of pack.invoke() in LocalSearchScope:
|
||||||
|
CLASS:P
|
||||||
|
FUN:invoke
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
Function call 10 p.invoke()
|
||||||
|
Implicit 'invoke' 9 p()
|
||||||
@@ -133,6 +133,12 @@ public class FindUsagesTestGenerated extends AbstractFindUsagesTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("invokeExtension.0.kt")
|
||||||
|
public void testInvokeExtension() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/conventions/invokeExtension.0.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("plus.0.kt")
|
@TestMetadata("plus.0.kt")
|
||||||
public void testPlus() throws Exception {
|
public void testPlus() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/conventions/plus.0.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/conventions/plus.0.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user