mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] Check whether the reference will be resolvable before rebinding
#KTIJ-30757 Fixed GitOrigin-RevId: 32b013795e0933a5f648e3bcbf00feb1b9b886ea
This commit is contained in:
committed by
intellij-monorepo-bot
parent
41d84ed20f
commit
ab9cb4af64
+6
@@ -0,0 +1,6 @@
|
||||
package bar
|
||||
|
||||
class A {
|
||||
val a: A = A()
|
||||
val b: B = B()
|
||||
}
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
package b
|
||||
|
||||
fun refer(enumContainer: a.EnumContainer) {
|
||||
enumContainer.foo()
|
||||
}
|
||||
+1
-1
@@ -4,5 +4,5 @@
|
||||
"targetDirectory": "B/src/b",
|
||||
"withRuntime": "true",
|
||||
"enabledInK1": "true",
|
||||
"enabledInK2": "false"
|
||||
"enabledInK2": "true"
|
||||
}
|
||||
|
||||
+4
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.idea.references.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.contains
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElementOrCallableRef
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isExtensionDeclaration
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isTopLevelKtOrJavaMember
|
||||
@@ -90,6 +91,9 @@ internal class K2ReferenceMutateService : KtReferenceMutateServiceBase() {
|
||||
val expression = simpleNameReference.expression
|
||||
if (targetElement != null) { // if we are already referencing the target, there is no need to call bindToElement
|
||||
if (simpleNameReference.isReferenceTo(targetElement)) return expression
|
||||
|
||||
// if reference will be unresolvable, don't retarget
|
||||
if (!simpleNameReference.element.resolveScope.contains(targetElement)) return expression
|
||||
} else {
|
||||
// Here we assume that the passed fqName uniquely identifies the new target element
|
||||
val oldTarget = simpleNameReference.resolve()
|
||||
|
||||
Reference in New Issue
Block a user