when finding usages of parameter of annotation class primary constructor, search also for light method generated from that parameter
#KT-9399 Fixed
This commit is contained in:
@@ -112,6 +112,13 @@ object LightClassUtil {
|
|||||||
return getPsiMethodWrapper(function)
|
return getPsiMethodWrapper(function)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the light method generated from the parameter of an annotation class.
|
||||||
|
*/
|
||||||
|
fun getLightClassMethod(parameter: KtParameter): PsiMethod? {
|
||||||
|
return getPsiMethodWrapper(parameter)
|
||||||
|
}
|
||||||
|
|
||||||
fun getLightClassMethods(function: KtFunction): List<PsiMethod> {
|
fun getLightClassMethods(function: KtFunction): List<PsiMethod> {
|
||||||
return getPsiMethodWrappers(function, true)
|
return getPsiMethodWrappers(function, true)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ fun KtDeclaration.toLightElements(): List<PsiNamedElement> =
|
|||||||
is KtParameter -> ArrayList<PsiNamedElement>().let { elements ->
|
is KtParameter -> ArrayList<PsiNamedElement>().let { elements ->
|
||||||
toPsiParameters().toCollection(elements)
|
toPsiParameters().toCollection(elements)
|
||||||
LightClassUtil.getLightClassPropertyMethods(this).toCollection(elements)
|
LightClassUtil.getLightClassPropertyMethods(this).toCollection(elements)
|
||||||
|
toAnnotationLightMethod()?.let { elements.add(it) }
|
||||||
|
|
||||||
elements
|
elements
|
||||||
}
|
}
|
||||||
@@ -96,6 +97,14 @@ fun KtParameter.toPsiParameters(): Collection<PsiParameter> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun KtParameter.toAnnotationLightMethod(): PsiMethod? {
|
||||||
|
val parent = ownerFunction as? KtPrimaryConstructor ?: return null
|
||||||
|
val containingClass = parent.getContainingClassOrObject()
|
||||||
|
if (!containingClass.isAnnotation()) return null
|
||||||
|
|
||||||
|
return LightClassUtil.getLightClassMethod(this)
|
||||||
|
}
|
||||||
|
|
||||||
fun KtTypeParameter.toPsiTypeParameters(): List<PsiTypeParameter> {
|
fun KtTypeParameter.toPsiTypeParameters(): List<PsiTypeParameter> {
|
||||||
val paramList = getNonStrictParentOfType<KtTypeParameterList>()
|
val paramList = getNonStrictParentOfType<KtTypeParameterList>()
|
||||||
if (paramList == null) return listOf()
|
if (paramList == null) return listOf()
|
||||||
|
|||||||
+1
@@ -273,6 +273,7 @@ class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, ReferencesSearc
|
|||||||
is KtParameter -> {
|
is KtParameter -> {
|
||||||
searchPropertyMethods(queryParameters, element)
|
searchPropertyMethods(queryParameters, element)
|
||||||
runReadAction {
|
runReadAction {
|
||||||
|
|
||||||
val componentFunctionDescriptor = element.dataClassComponentFunction()
|
val componentFunctionDescriptor = element.dataClassComponentFunction()
|
||||||
if (componentFunctionDescriptor != null) {
|
if (componentFunctionDescriptor != null) {
|
||||||
val containingClass = element.getStrictParentOfType<KtClassOrObject>()?.toLightClass()
|
val containingClass = element.getStrictParentOfType<KtClassOrObject>()?.toLightClass()
|
||||||
|
|||||||
Vendored
+4
@@ -0,0 +1,4 @@
|
|||||||
|
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtParameter
|
||||||
|
// OPTIONS: usages
|
||||||
|
|
||||||
|
annotation class KotlinAnnForJava(val <caret>p: String)
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
@KotlinAnnForJava(p = "a") public class JavaClassForKotlin {}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
Unclassified usage 1 @KotlinAnnForJava(p = "a") public class JavaClassForKotlin {}
|
||||||
@@ -804,6 +804,12 @@ public class FindUsagesTestGenerated extends AbstractFindUsagesTest {
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/findUsages/kotlin/findParameterUsages"), Pattern.compile("^(.+)\\.0\\.kt$"), true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/findUsages/kotlin/findParameterUsages"), Pattern.compile("^(.+)\\.0\\.kt$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kotlinAnnotationConstructorParameterUsages.0.kt")
|
||||||
|
public void testKotlinAnnotationConstructorParameterUsages() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findParameterUsages/kotlinAnnotationConstructorParameterUsages.0.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kotlinComponentFunctionParameterUsages.0.kt")
|
@TestMetadata("kotlinComponentFunctionParameterUsages.0.kt")
|
||||||
public void testKotlinComponentFunctionParameterUsages() throws Exception {
|
public void testKotlinComponentFunctionParameterUsages() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findParameterUsages/kotlinComponentFunctionParameterUsages.0.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findParameterUsages/kotlinComponentFunctionParameterUsages.0.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user