FIR IDE: change destructing declaration reference behaviour to match FE1.0 plugin behaviour
This commit is contained in:
+4
@@ -20,6 +20,10 @@ abstract class KtDestructuringDeclarationReference(
|
|||||||
|
|
||||||
abstract override fun canRename(): Boolean
|
abstract override fun canRename(): Boolean
|
||||||
|
|
||||||
|
override fun resolve() = multiResolve(false).asSequence()
|
||||||
|
.map { it.element }
|
||||||
|
.first { it is KtDestructuringDeclarationEntry }
|
||||||
|
|
||||||
override fun handleElementRename(newElementName: String): PsiElement? {
|
override fun handleElementRename(newElementName: String): PsiElement? {
|
||||||
if (canRename()) return expression
|
if (canRename()) return expression
|
||||||
throw IncorrectOperationException()
|
throw IncorrectOperationException()
|
||||||
|
|||||||
+8
-5
@@ -19,10 +19,7 @@ import org.jetbrains.kotlin.idea.frontend.api.fir.utils.firRef
|
|||||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.*
|
import org.jetbrains.kotlin.idea.frontend.api.symbols.*
|
||||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolKind
|
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolKind
|
||||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithKind
|
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithKind
|
||||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.KtElement
|
|
||||||
import org.jetbrains.kotlin.psi.KtObjectLiteralExpression
|
|
||||||
import org.jetbrains.kotlin.psi.KtPrimaryConstructor
|
|
||||||
|
|
||||||
internal class KtFirSymbolContainingDeclarationProvider(
|
internal class KtFirSymbolContainingDeclarationProvider(
|
||||||
override val analysisSession: KtFirAnalysisSession,
|
override val analysisSession: KtFirAnalysisSession,
|
||||||
@@ -81,13 +78,19 @@ internal class KtFirSymbolContainingDeclarationProvider(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return when (symbol.origin) {
|
return when (symbol.origin) {
|
||||||
KtSymbolOrigin.SOURCE -> thisSource.parentOfType()
|
KtSymbolOrigin.SOURCE -> thisSource.getContainingKtDeclaration()
|
||||||
?: error("Containing declaration should present for non-toplevel declaration")
|
?: error("Containing declaration should present for non-toplevel declaration")
|
||||||
KtSymbolOrigin.SOURCE_MEMBER_GENERATED -> thisSource as KtDeclaration
|
KtSymbolOrigin.SOURCE_MEMBER_GENERATED -> thisSource as KtDeclaration
|
||||||
else -> error("Unsupported declaration origin ${symbol.origin}")
|
else -> error("Unsupported declaration origin ${symbol.origin}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun PsiElement.getContainingKtDeclaration(): KtDeclaration? =
|
||||||
|
when (val container = this.parentOfType<KtDeclaration>()) {
|
||||||
|
is KtDestructuringDeclaration -> container.parentOfType()
|
||||||
|
else -> container
|
||||||
|
}
|
||||||
|
|
||||||
private fun getContainingDeclarationForLibrarySymbol(symbol: KtSymbolWithKind): KtSymbolWithKind = with(analysisSession) {
|
private fun getContainingDeclarationForLibrarySymbol(symbol: KtSymbolWithKind): KtSymbolWithKind = with(analysisSession) {
|
||||||
require(symbol.origin == KtSymbolOrigin.LIBRARY || symbol.origin == KtSymbolOrigin.JAVA)
|
require(symbol.origin == KtSymbolOrigin.LIBRARY || symbol.origin == KtSymbolOrigin.JAVA)
|
||||||
check(symbol.symbolKind == KtSymbolKind.MEMBER)
|
check(symbol.symbolKind == KtSymbolKind.MEMBER)
|
||||||
|
|||||||
+9
-2
@@ -23,7 +23,14 @@ class KtFirDestructuringDeclarationReference(
|
|||||||
override fun KtAnalysisSession.resolveToSymbols(): Collection<KtSymbol> {
|
override fun KtAnalysisSession.resolveToSymbols(): Collection<KtSymbol> {
|
||||||
check(this is KtFirAnalysisSession)
|
check(this is KtFirAnalysisSession)
|
||||||
val fir = expression.getOrBuildFirSafe<FirProperty>(firResolveState) ?: return emptyList()
|
val fir = expression.getOrBuildFirSafe<FirProperty>(firResolveState) ?: return emptyList()
|
||||||
val componentFunctionSymbol = (fir.initializer as? FirComponentCall)?.getCalleeSymbol() ?: return emptyList()
|
return listOfNotNull(
|
||||||
return listOfNotNull(componentFunctionSymbol.fir.buildSymbol(firSymbolBuilder))
|
fir.buildSymbol(firSymbolBuilder),
|
||||||
|
getComponentNSymbol(fir)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun KtFirAnalysisSession.getComponentNSymbol(fir: FirProperty): KtSymbol? {
|
||||||
|
val componentFunctionSymbol = (fir.initializer as? FirComponentCall)?.getCalleeSymbol() ?: return null
|
||||||
|
return componentFunctionSymbol.fir.buildSymbol(firSymbolBuilder)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -1,2 +1,3 @@
|
|||||||
Resolved to:
|
Resolved to:
|
||||||
0: (in a) operator fun a.A.component2(): kotlin.Int
|
0: (in <local>: main) val b: kotlin.Int
|
||||||
|
1: (in a) operator fun a.A.component2(): kotlin.Int
|
||||||
+2
-1
@@ -1,2 +1,3 @@
|
|||||||
Resolved to:
|
Resolved to:
|
||||||
0: (in a.MyPair) operator fun component2(): kotlin.Int
|
0: (in <local>: main) val b: kotlin.Int
|
||||||
|
1: (in a.MyPair) operator fun component2(): kotlin.Int
|
||||||
Reference in New Issue
Block a user