Implement extension of method usages search to cover usages of overriding functions in Kotlin
This commit is contained in:
@@ -296,6 +296,7 @@
|
||||
<directClassInheritorsSearch implementation="org.jetbrains.jet.plugin.search.KotlinDirectInheritorsSearcher"/>
|
||||
<definitionsScopedSearch implementation="org.jetbrains.jet.plugin.search.KotlinDefinitionsSearcher"/>
|
||||
<annotatedElementsSearch implementation="org.jetbrains.jet.plugin.search.KotlinAnnotatedElementsSearcher"/>
|
||||
<methodReferencesSearch implementation="org.jetbrains.jet.plugin.search.KotlinLightMethodUsagesSearcher"/>
|
||||
|
||||
<exceptionFilter implementation="org.jetbrains.jet.plugin.filters.JetExceptionFilterFactory" order="first"/>
|
||||
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package org.jetbrains.jet.plugin.search;
|
||||
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.psi.impl.search.MethodTextOccurrenceProcessor;
|
||||
import com.intellij.util.Processor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.asJava.LightClassUtil;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
|
||||
public class KotlinLightMethodTextOccurrenceProcessor extends MethodTextOccurrenceProcessor {
|
||||
public KotlinLightMethodTextOccurrenceProcessor(@NotNull PsiClass aClass, boolean strictSignatureSearch, PsiMethod... methods) {
|
||||
super(aClass, strictSignatureSearch, methods);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean processInexactReference(
|
||||
PsiReference ref, PsiElement refElement, PsiMethod method, Processor<PsiReference> consumer
|
||||
) {
|
||||
if (refElement instanceof JetNamedFunction) {
|
||||
PsiMethod lightMethod = LightClassUtil.getLightClassMethod((JetNamedFunction) refElement);
|
||||
if (lightMethod != null) return super.processInexactReference(ref, lightMethod, method, consumer);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.jetbrains.jet.plugin.search;
|
||||
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.impl.search.MethodTextOccurrenceProcessor;
|
||||
import com.intellij.psi.impl.search.MethodUsagesSearcher;
|
||||
|
||||
public class KotlinLightMethodUsagesSearcher extends MethodUsagesSearcher {
|
||||
@Override
|
||||
protected MethodTextOccurrenceProcessor getTextOccurrenceProcessor(
|
||||
PsiMethod[] methods, PsiClass aClass, boolean strictSignatureSearch
|
||||
) {
|
||||
return new KotlinLightMethodTextOccurrenceProcessor(aClass, strictSignatureSearch, methods);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,10 @@
|
||||
// OPTIONS: usages
|
||||
package testing;
|
||||
|
||||
public class Server() {
|
||||
public fun <caret>processRequest() = "foo"
|
||||
public open class Server() {
|
||||
public open fun <caret>processRequest() = "foo"
|
||||
}
|
||||
|
||||
public class ServerEx(): Server() {
|
||||
public override fun processRequest() = "foofoo"
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import testing.*;
|
||||
|
||||
class Client {
|
||||
public void foo() {
|
||||
Server server = new Server();
|
||||
server.processRequest();
|
||||
new Server().processRequest();
|
||||
new ServerEx().processRequest();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
Unclassified usage (6: 16) server.processRequest();
|
||||
Unclassified usage (5: 22) new Server().processRequest();
|
||||
Unclassified usage (6: 24) new ServerEx().processRequest();
|
||||
@@ -2,5 +2,11 @@
|
||||
// OPTIONS: usages
|
||||
package server;
|
||||
|
||||
fun <caret>processRequest() = "foo"
|
||||
public open class Server() {
|
||||
open fun <caret>processRequest() = "foo"
|
||||
}
|
||||
|
||||
public class ServerEx(): Server() {
|
||||
override fun processRequest() = "foofoo"
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
package client
|
||||
|
||||
import server.processRequest
|
||||
import server.*;
|
||||
|
||||
class Client {
|
||||
val methodRef = ::processRequest()
|
||||
|
||||
fun doProcessRequest() {
|
||||
println("Process...")
|
||||
processRequest()
|
||||
public fun foo() {
|
||||
Server().processRequest()
|
||||
ServerEx().processRequest()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
Callable reference (6: 23) val methodRef = ::processRequest()
|
||||
Function call (10: 9) processRequest()
|
||||
Import directive (3: 15) import server.processRequest
|
||||
Function call (5: 18) Server().processRequest()
|
||||
Function call (6: 20) ServerEx().processRequest()
|
||||
@@ -3,4 +3,5 @@ Function call (11: 7) x.foo(1, 2)
|
||||
Function call (25: 5) foo(t)
|
||||
Function call (30: 7) a.foo(1, "")
|
||||
Function call (35: 9) foo(t)
|
||||
Function call (39: 5) foo(s)
|
||||
Function call (3: 18) super<A>.foo(t)
|
||||
@@ -0,0 +1,6 @@
|
||||
// PSI_ELEMENT: org.jetbrains.jet.lang.psi.JetNamedFunction
|
||||
// OPTIONS: usages
|
||||
package server;
|
||||
|
||||
fun <caret>processRequest() = "foo"
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package client
|
||||
|
||||
import server.processRequest
|
||||
|
||||
class Client {
|
||||
val methodRef = ::processRequest()
|
||||
|
||||
fun doProcessRequest() {
|
||||
println("Process...")
|
||||
processRequest()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
Callable reference (6: 23) val methodRef = ::processRequest()
|
||||
Function call (10: 9) processRequest()
|
||||
Import directive (3: 15) import server.processRequest
|
||||
@@ -191,6 +191,11 @@ public class JetFindUsagesTest extends AbstractJetFindUsagesTest {
|
||||
doTest("idea/testData/findUsages/findMethodUsages/kotlinOverloadAndExtensionUsages.0.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kotlinTopLevelMethodUsages.0.kt")
|
||||
public void testKotlinTopLevelMethodUsages() throws Exception {
|
||||
doTest("idea/testData/findUsages/findMethodUsages/kotlinTopLevelMethodUsages.0.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/findUsages/findObjectUsages")
|
||||
|
||||
Reference in New Issue
Block a user