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:
+6
-1
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.load.java.JvmAbi
|
|||||||
import org.jetbrains.kotlin.load.java.getPropertyNamesCandidatesByAccessorName
|
import org.jetbrains.kotlin.load.java.getPropertyNamesCandidatesByAccessorName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.psi.KtCallableDeclaration
|
import org.jetbrains.kotlin.psi.KtCallableDeclaration
|
||||||
|
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||||
import org.jetbrains.kotlin.psi.KtParameter
|
import org.jetbrains.kotlin.psi.KtParameter
|
||||||
import org.jetbrains.kotlin.psi.KtProperty
|
import org.jetbrains.kotlin.psi.KtProperty
|
||||||
import org.jetbrains.kotlin.utils.ifEmpty
|
import org.jetbrains.kotlin.utils.ifEmpty
|
||||||
@@ -50,7 +51,8 @@ class KotlinOverridingMethodReferenceSearcher : MethodUsagesSearcher() {
|
|||||||
.restrictToKotlinSources()
|
.restrictToKotlinSources()
|
||||||
if (searchScope === GlobalSearchScope.EMPTY_SCOPE) return@runReadActionInSmartMode
|
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(
|
p.optimizer.searchWord(
|
||||||
name.asString(),
|
name.asString(),
|
||||||
searchScope,
|
searchScope,
|
||||||
@@ -93,6 +95,9 @@ class KotlinOverridingMethodReferenceSearcher : MethodUsagesSearcher() {
|
|||||||
if (isWrongAccessorReference()) return true
|
if (isWrongAccessorReference()) return true
|
||||||
lightMethods = lightMethods.filter { JvmAbi.isGetterName(it.name) == isGetter }
|
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) }
|
return lightMethods.all { super.processInexactReference(ref, it, method, consumer) }
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+16
@@ -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")
|
||||||
|
}
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
Value read 11 println(p)
|
||||||
@@ -1014,6 +1014,12 @@ public class FindUsagesTestGenerated extends AbstractFindUsagesTest {
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("kotlinPropertyUsages.0.kt")
|
||||||
public void testKotlinPropertyUsages() throws Exception {
|
public void testKotlinPropertyUsages() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findPropertyUsages/kotlinPropertyUsages.0.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findPropertyUsages/kotlinPropertyUsages.0.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user