Skip to content

Commit 9594147

Browse files
committed
Find Usages checks that the signature of the method a property usage resolves to matches the signature of the method being searched
#KT-15291 Fixed
1 parent dbfe337 commit 9594147

File tree

5 files changed

+36
-1
lines changed

5 files changed

+36
-1
lines changed

idea/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinOverridingMethodReferenceSearcher.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import com.intellij.psi.impl.search.MethodUsagesSearcher
2222
import com.intellij.psi.search.GlobalSearchScope
2323
import com.intellij.psi.search.UsageSearchContext
2424
import com.intellij.psi.search.searches.MethodReferencesSearch
25+
import com.intellij.psi.util.MethodSignatureUtil
26+
import com.intellij.psi.util.TypeConversionUtil
2527
import com.intellij.util.Processor
2628
import org.jetbrains.kotlin.asJava.toLightMethods
2729
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
@@ -85,7 +87,19 @@ class KotlinOverridingMethodReferenceSearcher : MethodUsagesSearcher() {
8587

8688
if (refElement !is KtCallableDeclaration) {
8789
if (isWrongAccessorReference()) return true
88-
return super.processInexactReference(ref, refElement, method, consumer)
90+
if (refElement !is PsiMethod) return true
91+
92+
val refMethodClass = refElement.containingClass ?: return true
93+
val substitutor = TypeConversionUtil.getClassSubstitutor(myContainingClass, refMethodClass, PsiSubstitutor.EMPTY)
94+
if (substitutor != null) {
95+
val superSignature = method.getSignature(substitutor)
96+
val refSignature = refElement.getSignature(PsiSubstitutor.EMPTY)
97+
98+
if (MethodSignatureUtil.isSubsignature(superSignature, refSignature)) {
99+
return super.processInexactReference(ref, refElement, method, consumer)
100+
}
101+
}
102+
return true
89103
}
90104

91105
var lightMethods = refElement.toLightMethods()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// PSI_ELEMENT: com.intellij.psi.PsiMethod
2+
// OPTIONS: usages
3+
public class Bar {
4+
public String getValue() {
5+
return "value";
6+
}
7+
8+
public String <caret>getValue(String param) {
9+
return "value " + param;
10+
}
11+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fun main(args: Array<String>) {
2+
println(Bar().value)
3+
4+
}

idea/testData/findUsages/java/findJavaMethodUsages/MismatchedAccessor.results.txt

Whitespace-only changes.

idea/tests/org/jetbrains/kotlin/findUsages/FindUsagesTestGenerated.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,12 @@ public void testJavaInvoke() throws Exception {
16091609
doTest(fileName);
16101610
}
16111611

1612+
@TestMetadata("MismatchedAccessor.0.java")
1613+
public void testMismatchedAccessor() throws Exception {
1614+
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/java/findJavaMethodUsages/MismatchedAccessor.0.java");
1615+
doTest(fileName);
1616+
}
1617+
16121618
@TestMetadata("OverriddenMethodSyntheticAccessor.0.java")
16131619
public void testOverriddenMethodSyntheticAccessor() throws Exception {
16141620
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/java/findJavaMethodUsages/OverriddenMethodSyntheticAccessor.0.java");

0 commit comments

Comments
 (0)