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
This commit is contained in:
Dmitry Jemerov
2017-01-31 19:33:58 +01:00
parent dbfe3370aa
commit 9594147c55
5 changed files with 36 additions and 1 deletions
@@ -22,6 +22,8 @@ import com.intellij.psi.impl.search.MethodUsagesSearcher
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.search.UsageSearchContext
import com.intellij.psi.search.searches.MethodReferencesSearch
import com.intellij.psi.util.MethodSignatureUtil
import com.intellij.psi.util.TypeConversionUtil
import com.intellij.util.Processor
import org.jetbrains.kotlin.asJava.toLightMethods
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
@@ -85,7 +87,19 @@ class KotlinOverridingMethodReferenceSearcher : MethodUsagesSearcher() {
if (refElement !is KtCallableDeclaration) {
if (isWrongAccessorReference()) return true
return super.processInexactReference(ref, refElement, method, consumer)
if (refElement !is PsiMethod) return true
val refMethodClass = refElement.containingClass ?: return true
val substitutor = TypeConversionUtil.getClassSubstitutor(myContainingClass, refMethodClass, PsiSubstitutor.EMPTY)
if (substitutor != null) {
val superSignature = method.getSignature(substitutor)
val refSignature = refElement.getSignature(PsiSubstitutor.EMPTY)
if (MethodSignatureUtil.isSubsignature(superSignature, refSignature)) {
return super.processInexactReference(ref, refElement, method, consumer)
}
}
return true
}
var lightMethods = refElement.toLightMethods()
@@ -0,0 +1,11 @@
// PSI_ELEMENT: com.intellij.psi.PsiMethod
// OPTIONS: usages
public class Bar {
public String getValue() {
return "value";
}
public String <caret>getValue(String param) {
return "value " + param;
}
}
@@ -0,0 +1,4 @@
fun main(args: Array<String>) {
println(Bar().value)
}
@@ -1609,6 +1609,12 @@ public class FindUsagesTestGenerated extends AbstractFindUsagesTest {
doTest(fileName);
}
@TestMetadata("MismatchedAccessor.0.java")
public void testMismatchedAccessor() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/java/findJavaMethodUsages/MismatchedAccessor.0.java");
doTest(fileName);
}
@TestMetadata("OverriddenMethodSyntheticAccessor.0.java")
public void testOverriddenMethodSyntheticAccessor() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/java/findJavaMethodUsages/OverriddenMethodSyntheticAccessor.0.java");