correcty find Java usages of static methods generated for companion object members annotated as jvmStatic
#KT-8902 Fixed
This commit is contained in:
+26
@@ -38,6 +38,8 @@ import org.jetbrains.kotlin.idea.stubindex.JetSourceFilterScope
|
||||
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil
|
||||
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parents
|
||||
|
||||
public class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, ReferencesSearch.SearchParameters>() {
|
||||
|
||||
@@ -136,6 +138,19 @@ public class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, Referenc
|
||||
}
|
||||
}
|
||||
|
||||
private fun findStaticMethodFromCompanionObject(function: JetFunction): PsiMethod? {
|
||||
val originObject = function.parents
|
||||
.dropWhile { it is JetClassBody }
|
||||
.firstOrNull() as? JetObjectDeclaration ?: return null
|
||||
if (originObject.isCompanion()) {
|
||||
val originClass = originObject.getStrictParentOfType<JetClass>()
|
||||
val originLightClass = LightClassUtil.getPsiClass(originClass)
|
||||
val allMethods = originLightClass?.allMethods
|
||||
return allMethods?.find { it is KotlinLightMethod && it.getOrigin() == function }
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private fun searchLightElements(queryParameters: ReferencesSearch.SearchParameters, element: PsiElement) {
|
||||
when (element) {
|
||||
is JetClassOrObject -> processJetClassOrObject(element, queryParameters)
|
||||
@@ -146,6 +161,11 @@ public class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, Referenc
|
||||
val method = runReadAction { LightClassUtil.getLightClassMethod(function) }
|
||||
searchNamedElement(queryParameters, method)
|
||||
}
|
||||
|
||||
val staticFromCompanionObject = findStaticMethodFromCompanionObject(element)
|
||||
if (staticFromCompanionObject != null) {
|
||||
searchNamedElement(queryParameters, staticFromCompanionObject)
|
||||
}
|
||||
}
|
||||
is JetProperty -> {
|
||||
val propertyMethods = runReadAction { LightClassUtil.getLightClassPropertyMethods(element) }
|
||||
@@ -160,6 +180,12 @@ public class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, Referenc
|
||||
else if (declaration is JetPropertyAccessor) {
|
||||
searchNamedElement(queryParameters, PsiTreeUtil.getParentOfType<JetProperty>(declaration, javaClass<JetProperty>()))
|
||||
}
|
||||
else if (declaration is JetFunction) {
|
||||
val staticFromCompanionObject = findStaticMethodFromCompanionObject(declaration)
|
||||
if (staticFromCompanionObject != null) {
|
||||
searchNamedElement(queryParameters, staticFromCompanionObject)
|
||||
}
|
||||
}
|
||||
}
|
||||
is KotlinLightParameter -> {
|
||||
val componentFunctionDescriptor = element.getOrigin()?.dataClassComponentFunction()
|
||||
|
||||
Reference in New Issue
Block a user