Navigation: add actual declarations as implementations (KT-16892)
This commit is contained in:
+25
-8
@@ -32,6 +32,8 @@ import org.jetbrains.kotlin.asJava.elements.KtLightMethod
|
||||
import org.jetbrains.kotlin.asJava.toLightClass
|
||||
import org.jetbrains.kotlin.asJava.unwrapped
|
||||
import org.jetbrains.kotlin.idea.caches.lightClasses.KtFakeLightClass
|
||||
import org.jetbrains.kotlin.idea.highlighter.markers.actualsForExpected
|
||||
import org.jetbrains.kotlin.idea.highlighter.markers.isExpectedOrExpectedClassMember
|
||||
import org.jetbrains.kotlin.idea.search.declarationsSearch.forEachImplementation
|
||||
import org.jetbrains.kotlin.idea.search.declarationsSearch.forEachOverridingMethod
|
||||
import org.jetbrains.kotlin.idea.search.declarationsSearch.toPossiblyFakeLightMethods
|
||||
@@ -47,8 +49,9 @@ class KotlinDefinitionsSearcher : QueryExecutor<PsiElement, DefinitionsScopedSea
|
||||
val scope = queryParameters.scope
|
||||
|
||||
return when (element) {
|
||||
is KtClass ->
|
||||
processClassImplementations(element, consumer)
|
||||
is KtClass -> {
|
||||
processClassImplementations(element, consumer) && processActualDeclarations(element, consumer)
|
||||
}
|
||||
|
||||
is KtLightClass -> {
|
||||
val useScope = runReadAction { element.useScope }
|
||||
@@ -58,14 +61,21 @@ class KotlinDefinitionsSearcher : QueryExecutor<PsiElement, DefinitionsScopedSea
|
||||
true
|
||||
}
|
||||
|
||||
is KtNamedFunction, is KtSecondaryConstructor ->
|
||||
processFunctionImplementations(element as KtFunction, scope, consumer)
|
||||
is KtNamedFunction, is KtSecondaryConstructor -> {
|
||||
processFunctionImplementations(element as KtFunction, scope, consumer) && processActualDeclarations(element, consumer)
|
||||
}
|
||||
|
||||
is KtProperty ->
|
||||
processPropertyImplementations(element, scope, consumer)
|
||||
is KtProperty -> {
|
||||
processPropertyImplementations(element, scope, consumer) && processActualDeclarations(element, consumer)
|
||||
}
|
||||
|
||||
is KtParameter ->
|
||||
if (isFieldParameter(element)) processPropertyImplementations(element, scope, consumer) else true
|
||||
is KtParameter -> {
|
||||
if (isFieldParameter(element)) {
|
||||
processPropertyImplementations(element, scope, consumer) && processActualDeclarations(element, consumer)
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
else -> true
|
||||
}
|
||||
@@ -128,6 +138,13 @@ class KotlinDefinitionsSearcher : QueryExecutor<PsiElement, DefinitionsScopedSea
|
||||
}
|
||||
}
|
||||
|
||||
private fun processActualDeclarations(declaration: KtDeclaration, consumer: Processor<PsiElement>): Boolean {
|
||||
return runReadAction {
|
||||
if (!declaration.isExpectedOrExpectedClassMember()) true
|
||||
else declaration.actualsForExpected().all(consumer::process)
|
||||
}
|
||||
}
|
||||
|
||||
fun processPropertyImplementationsMethods(accessors: Iterable<PsiMethod>, scope: SearchScope, consumer: Processor<PsiElement>): Boolean {
|
||||
return accessors.all { method ->
|
||||
method.forEachOverridingMethod(scope) { implementation ->
|
||||
|
||||
+1
@@ -9,4 +9,5 @@ class ExpectedChildChild : ExpectedChild()
|
||||
class SimpleChild : SimpleParent()
|
||||
|
||||
// REF: [common] (test).ExpectedChildChild
|
||||
// REF: [jvm] (test).ExpectedChild
|
||||
// REF: [jvm] (test).ExpectedChildChildJvm
|
||||
+1
@@ -17,4 +17,5 @@ class SimpleChild : SimpleParent() {
|
||||
}
|
||||
|
||||
// REF: [common] (in test.ExpectedChildChild).foo(Int)
|
||||
// REF: [jvm] (in test.ExpectedChild).foo(Int)
|
||||
// REF: [jvm] (in test.ExpectedChildChildJvm).foo(Int)
|
||||
+1
@@ -17,4 +17,5 @@ class SimpleChild : SimpleParent() {
|
||||
}
|
||||
|
||||
// REF: [common] (in test.ExpectedChildChild).bar
|
||||
// REF: [jvm] (in test.ExpectedChild).bar
|
||||
// REF: [jvm] (in test.ExpectedChildChildJvm).bar
|
||||
Reference in New Issue
Block a user