KT-3542 Can't navigate to property implementation
#KT-3542 Fixed
This commit is contained in:
@@ -21,6 +21,7 @@ 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.PsiCompiledElement;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.search.searches.ClassInheritorsSearch;
|
||||
@@ -30,6 +31,8 @@ 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;
|
||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
import org.jetbrains.jet.lang.psi.JetPropertyAccessor;
|
||||
|
||||
public class KotlinDefinitionsSearcher extends QueryExecutorBase<PsiElement, PsiElement> {
|
||||
@Override
|
||||
@@ -41,6 +44,10 @@ public class KotlinDefinitionsSearcher extends QueryExecutorBase<PsiElement, Psi
|
||||
if (queryParameters instanceof JetNamedFunction) {
|
||||
processFunctionImplementations((JetNamedFunction) queryParameters, consumer);
|
||||
}
|
||||
|
||||
if (queryParameters instanceof JetProperty) {
|
||||
processPropertyImplementations((JetProperty) queryParameters, consumer);
|
||||
}
|
||||
}
|
||||
|
||||
private static void processClassImplementations(final JetClass queryParameters, Processor<PsiElement> consumer) {
|
||||
@@ -67,4 +74,30 @@ public class KotlinDefinitionsSearcher extends QueryExecutorBase<PsiElement, Psi
|
||||
ContainerUtil.process(MethodImplementationsSearch.getMethodImplementations(psiMethod), consumer);
|
||||
}
|
||||
}
|
||||
|
||||
private static void processPropertyImplementations(@NotNull final JetProperty property, @NotNull Processor<PsiElement> consumer) {
|
||||
LightClassUtil.PropertyAccessorsPsiMethods accessorsPsiMethods = ApplicationManager.getApplication().runReadAction(
|
||||
new Computable<LightClassUtil.PropertyAccessorsPsiMethods>() {
|
||||
@Override
|
||||
public LightClassUtil.PropertyAccessorsPsiMethods compute() {
|
||||
return LightClassUtil.getLightClassPropertyMethods(property);
|
||||
}
|
||||
});
|
||||
|
||||
for (PsiMethod method : accessorsPsiMethods) {
|
||||
PsiMethod[] implementations = MethodImplementationsSearch.getMethodImplementations(method);
|
||||
for (PsiMethod implementation : implementations) {
|
||||
PsiElement mirrorElement = implementation instanceof PsiCompiledElement ? ((PsiCompiledElement) implementation).getMirror() : null;
|
||||
if (mirrorElement instanceof JetProperty) {
|
||||
consumer.process(mirrorElement);
|
||||
}
|
||||
else if (mirrorElement instanceof JetPropertyAccessor && mirrorElement.getParent() instanceof JetProperty) {
|
||||
consumer.process(mirrorElement.getParent());
|
||||
}
|
||||
else {
|
||||
consumer.process(implementation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package testing
|
||||
|
||||
open class Base {
|
||||
open var <caret>test = 12
|
||||
}
|
||||
|
||||
open class SubBase: Base() {
|
||||
override var test = 12
|
||||
}
|
||||
|
||||
class SubSubBase: SubBase() {
|
||||
override var test = 12
|
||||
}
|
||||
|
||||
|
||||
// REF: (testing.SubBase).test
|
||||
// REF: (testing.SubSubBase).test
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package testing.jj;
|
||||
|
||||
public class JavaBase extends testing.kt.KotlinBase {
|
||||
@Override
|
||||
public String getSome() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSome(String someValue) {
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package testing.kt
|
||||
|
||||
open class KotlinBase {
|
||||
open var <caret>some = "Test"
|
||||
}
|
||||
|
||||
// REF: (in testing.jj.JavaBase).getSome()
|
||||
// REF: (in testing.jj.JavaBase).setSome(String)
|
||||
@@ -39,6 +39,10 @@ public class JetGotoImplementationMultifileTest extends CodeInsightTestCase {
|
||||
doKotlinJavaTest();
|
||||
}
|
||||
|
||||
public void testImplementVarInJava() throws Exception {
|
||||
doKotlinJavaTest();
|
||||
}
|
||||
|
||||
private void doKotlinJavaTest() throws Exception {
|
||||
doMultifileTest(getTestName(false) + ".kt", getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
@@ -37,6 +37,10 @@ public class JetGotoImplementationTest extends LightCodeInsightTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testPropertyOverriddenNavigation() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
|
||||
Reference in New Issue
Block a user