[Analysis API] fix exception on symbol restore when symbol cannot be seen from the use-site module

^KT-56763 fixed
This commit is contained in:
Ilya Kirillov
2023-02-17 15:11:47 +01:00
committed by Space Team
parent ee1b018c9a
commit 803c3b88ac
12 changed files with 373 additions and 0 deletions
@@ -22,6 +22,7 @@ public class KtPsiBasedSymbolPointer<S : KtSymbol> private constructor(
val psi = psiPointer.element ?: return null
val symbol: KtSymbol = with(analysisSession) {
if (!psi.canBeAnalysed()) return null
when (psi) {
is KtDeclaration -> psi.getSymbol()
is KtFile -> psi.getFileSymbol()
@@ -0,0 +1,9 @@
// MODULE: main
fun f<caret>oo(){}
// MODULE: restoreInContextOf
fun restoreInContextOf() {
<caret_restoreAt>
}
@@ -0,0 +1,5 @@
Inital from Sources of main:
fun foo()
Restored in Sources of restoreInContextOf:
<NOT RESTORED>
@@ -0,0 +1,31 @@
Inital from Sources of main:
KtFunctionSymbol:
annotationsList: []
callableIdIfNonLocal: /foo
contextReceivers: []
contractEffects: []
hasStableParameterNames: true
isBuiltinFunctionInvoke: false
isExtension: false
isExternal: false
isInfix: false
isInline: false
isOperator: false
isOverride: false
isStatic: false
isSuspend: false
modality: FINAL
name: foo
origin: SOURCE
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Unit
symbolKind: TOP_LEVEL
typeParameters: []
valueParameters: []
visibility: Public
Restored in Sources of restoreInContextOf:
<NOT RESTORED>
@@ -0,0 +1,9 @@
// MODULE: main
fun f<caret>oo(){}
// MODULE: restoreInContextOf(main)
fun restoreInContextOf() {
<caret_restoreAt>
}
@@ -0,0 +1,5 @@
Inital from Sources of main:
fun foo()
Restored in Sources of restoreInContextOf:
fun foo()
@@ -0,0 +1,57 @@
Inital from Sources of main:
KtFunctionSymbol:
annotationsList: []
callableIdIfNonLocal: /foo
contextReceivers: []
contractEffects: []
hasStableParameterNames: true
isBuiltinFunctionInvoke: false
isExtension: false
isExternal: false
isInfix: false
isInline: false
isOperator: false
isOverride: false
isStatic: false
isSuspend: false
modality: FINAL
name: foo
origin: SOURCE
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Unit
symbolKind: TOP_LEVEL
typeParameters: []
valueParameters: []
visibility: Public
Restored in Sources of restoreInContextOf:
KtFunctionSymbol:
annotationsList: []
callableIdIfNonLocal: /foo
contextReceivers: []
contractEffects: []
hasStableParameterNames: true
isBuiltinFunctionInvoke: false
isExtension: false
isExternal: false
isInfix: false
isInline: false
isOperator: false
isOverride: false
isStatic: false
isSuspend: false
modality: FINAL
name: foo
origin: SOURCE
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Unit
symbolKind: TOP_LEVEL
typeParameters: []
valueParameters: []
visibility: Public