don't consider calls to methods with the same name as a property to be calls to accessors of that property

#KT-12813 Fixed
This commit is contained in:
Dmitry Jemerov
2016-07-14 14:04:03 +02:00
parent 14037f099c
commit 5380b63522
4 changed files with 29 additions and 1 deletions
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.load.java.getPropertyNamesCandidatesByAccessorName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.KtCallableDeclaration
import org.jetbrains.kotlin.psi.KtNamedFunction
import org.jetbrains.kotlin.psi.KtParameter
import org.jetbrains.kotlin.psi.KtProperty
import org.jetbrains.kotlin.utils.ifEmpty
@@ -50,7 +51,8 @@ class KotlinOverridingMethodReferenceSearcher : MethodUsagesSearcher() {
.restrictToKotlinSources()
if (searchScope === GlobalSearchScope.EMPTY_SCOPE) return@runReadActionInSmartMode
for (name in getPropertyNamesCandidatesByAccessorName(Name.identifier(method.name))) {
val nameCandidates = getPropertyNamesCandidatesByAccessorName(Name.identifier(method.name))
for (name in nameCandidates) {
p.optimizer.searchWord(
name.asString(),
searchScope,
@@ -93,6 +95,9 @@ class KotlinOverridingMethodReferenceSearcher : MethodUsagesSearcher() {
if (isWrongAccessorReference()) return true
lightMethods = lightMethods.filter { JvmAbi.isGetterName(it.name) == isGetter }
}
if (refElement is KtNamedFunction) {
lightMethods = lightMethods.filter { it.name == method.name }
}
return lightMethods.all { super.processInexactReference(ref, it, method, consumer) }
}
@@ -0,0 +1,16 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtProperty
// OPTIONS: usages
class P
interface C {
val <caret>p: P // set caret at "p" and try find usages
fun p(param: Any)
}
fun C.usageCorrect() {
println(p)
}
fun C.usageIncorrect() {
p("ok")
}
@@ -0,0 +1 @@
Value read 11 println(p)
@@ -1014,6 +1014,12 @@ public class FindUsagesTestGenerated extends AbstractFindUsagesTest {
doTest(fileName);
}
@TestMetadata("kotlinPropertySameNameAsMethodUsages.0.kt")
public void testKotlinPropertySameNameAsMethodUsages() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findPropertyUsages/kotlinPropertySameNameAsMethodUsages.0.kt");
doTest(fileName);
}
@TestMetadata("kotlinPropertyUsages.0.kt")
public void testKotlinPropertyUsages() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findPropertyUsages/kotlinPropertyUsages.0.kt");