[Analysis API] Fix 'getContainingDeclaration()' for foreign values

Foreign values (such as '_DebugLabel' properties contributed by the
debugger) don't have a parent (or a valid source element in general).

^KTIJ-27382 Fixed
This commit is contained in:
Yan Zhulanow
2024-02-01 00:48:24 +09:00
committed by Space Team
parent 88a85b8936
commit 2dd16e1179
3 changed files with 21 additions and 15 deletions
@@ -189,7 +189,7 @@ private class CodeFragmentCapturedValueVisitor(
if (symbol.isLocal) {
val isCrossingInlineBounds = isCrossingInlineBounds(element, symbol)
val capturedValue = when {
symbol.fir.foreignValueMarker == true -> CodeFragmentCapturedValue.ForeignValue(symbol.name, isCrossingInlineBounds)
symbol.isForeignValue -> CodeFragmentCapturedValue.ForeignValue(symbol.name, isCrossingInlineBounds)
symbol.hasDelegate -> CodeFragmentCapturedValue.LocalDelegate(symbol.name, symbol.isMutated, isCrossingInlineBounds)
else -> CodeFragmentCapturedValue.Local(symbol.name, symbol.isMutated, isCrossingInlineBounds)
}
@@ -37,7 +37,10 @@ val FirSession.codeFragmentScopeProvider: CodeFragmentScopeProvider by FirSessio
private object ForeignValueMarkerDataKey : FirDeclarationDataKey()
var FirProperty.foreignValueMarker: Boolean? by FirDeclarationDataRegistry.data(ForeignValueMarkerDataKey)
private var FirProperty.foreignValueMarker: Boolean? by FirDeclarationDataRegistry.data(ForeignValueMarkerDataKey)
val FirPropertySymbol.isForeignValue: Boolean
get() = fir.foreignValueMarker == true
class CodeFragmentScopeProvider(private val session: FirSession) : FirSessionComponent {
private val foreignValueProvider = ForeignValueProviderService.getInstance()