KT-3503 Can't navigate to implementation of kotlin functions
#KT-3503 Fixed
This commit is contained in:
@@ -16,21 +16,24 @@
|
||||
|
||||
package org.jetbrains.jet.plugin.search;
|
||||
|
||||
import com.intellij.codeInsight.navigation.MethodImplementationsSearch;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.QueryExecutorBase;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.search.searches.ClassInheritorsSearch;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.Query;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.asJava.LightClassUtil;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
|
||||
public class KotlinDefinitionsSearcher extends QueryExecutorBase<PsiElement, PsiElement> {
|
||||
@Override
|
||||
public void processQuery(@NotNull final PsiElement queryParameters, @NotNull final Processor<PsiElement> consumer) {
|
||||
public void processQuery(@NotNull final PsiElement queryParameters, @NotNull Processor<PsiElement> consumer) {
|
||||
if (queryParameters instanceof JetClass) {
|
||||
PsiClass psiClass = ApplicationManager.getApplication().runReadAction(new Computable<PsiClass>() {
|
||||
@Override
|
||||
@@ -39,13 +42,20 @@ public class KotlinDefinitionsSearcher extends QueryExecutorBase<PsiElement, Psi
|
||||
}
|
||||
});
|
||||
if (psiClass != null) {
|
||||
Query<PsiClass> query = ClassInheritorsSearch.search(psiClass, true);
|
||||
query.forEach(new Processor<PsiClass>() {
|
||||
@Override
|
||||
public boolean process(PsiClass clazz) {
|
||||
return consumer.process(clazz);
|
||||
}
|
||||
});
|
||||
ContainerUtil.process(ClassInheritorsSearch.search(psiClass, true), consumer);
|
||||
}
|
||||
}
|
||||
|
||||
if (queryParameters instanceof JetNamedFunction) {
|
||||
PsiMethod psiMethod = ApplicationManager.getApplication().runReadAction(new Computable<PsiMethod>() {
|
||||
@Override
|
||||
public PsiMethod compute() {
|
||||
return LightClassUtil.getLightClassMethod((JetNamedFunction) queryParameters);
|
||||
}
|
||||
});
|
||||
|
||||
if (psiMethod != null) {
|
||||
ContainerUtil.process(MethodImplementationsSearch.getMethodImplementations(psiMethod), consumer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package testing
|
||||
|
||||
open class Base {
|
||||
open fun <caret>test() {
|
||||
}
|
||||
}
|
||||
|
||||
open class SubBase: Base() {
|
||||
override fun test() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class SubSubBase: SubBase() {
|
||||
override fun test() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// REF: (in testing.SubBase).test()
|
||||
// REF: (in testing.SubSubBase).test()
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package testing.jj;
|
||||
|
||||
public class JavaBase extends testing.kt.KotlinBase {
|
||||
@Override
|
||||
public void test() {
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package testing.kt
|
||||
|
||||
open class KotlinBase {
|
||||
open fun <caret>test() {}
|
||||
}
|
||||
|
||||
// REF: (in testing.jj.JavaBase).test()
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
public class BaseJava {
|
||||
public void testMethod() {
|
||||
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package testing.kt
|
||||
|
||||
class TestFromJava() : BaseJava() {
|
||||
override fun testMethod() {
|
||||
}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
BaseJava().testMethod<caret>()
|
||||
}
|
||||
|
||||
// REF: (in testing.kt.TestFromJava).testMethod()
|
||||
// REF: (in BaseJava).testMethod()
|
||||
@@ -23,6 +23,10 @@ import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
import java.io.File;
|
||||
|
||||
public class JetGotoImplementationMultifileTest extends CodeInsightTestCase {
|
||||
public void testImplementFunInJava() throws Exception {
|
||||
doKotlinJavaTest();
|
||||
}
|
||||
|
||||
public void testImplementKotlinClassInJava() throws Exception {
|
||||
doKotlinJavaTest();
|
||||
}
|
||||
@@ -31,6 +35,10 @@ public class JetGotoImplementationMultifileTest extends CodeInsightTestCase {
|
||||
doKotlinJavaTest();
|
||||
}
|
||||
|
||||
public void testImplementMethodInKotlin() throws Exception {
|
||||
doKotlinJavaTest();
|
||||
}
|
||||
|
||||
private void doKotlinJavaTest() throws Exception {
|
||||
doMultifileTest(getTestName(false) + ".kt", getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.jet.plugin.navigation;
|
||||
import com.intellij.codeInsight.navigation.GotoTargetHandler;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
|
||||
import java.io.File;
|
||||
@@ -32,6 +33,11 @@ public class JetGotoImplementationTest extends LightCodeInsightTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testFunctionOverrideNavigation() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return new File(PluginTestCaseBase.getTestDataPathBase(), "/navigation/implementations").getPath() +
|
||||
|
||||
Reference in New Issue
Block a user