[FIR IDE] Properly support loop variables in KtFirSymbolProvider
This commit is contained in:
committed by
TeamCityServer
parent
58831eacca
commit
9113ccb8fc
+11
-3
@@ -31,7 +31,7 @@ public abstract class KtSymbolProvider : KtAnalysisSessionComponent() {
|
||||
else -> error("Cannot build symbol for ${psi::class}")
|
||||
}
|
||||
|
||||
public abstract fun getParameterSymbol(psi: KtParameter): KtValueParameterSymbol
|
||||
public abstract fun getParameterSymbol(psi: KtParameter): KtVariableLikeSymbol
|
||||
public abstract fun getFileSymbol(psi: KtFile): KtFileSymbol
|
||||
public abstract fun getFunctionLikeSymbol(psi: KtNamedFunction): KtFunctionLikeSymbol
|
||||
public abstract fun getConstructorSymbol(psi: KtConstructor<*>): KtConstructorSymbol
|
||||
@@ -60,12 +60,20 @@ public interface KtSymbolProviderMixIn : KtAnalysisSessionMixIn {
|
||||
analysisSession.symbolProvider.getSymbol(this)
|
||||
|
||||
/**
|
||||
* Creates [KtValueParameterSymbol] by [KtParameter]
|
||||
* Creates [KtVariableLikeSymbol] by [KtParameter].
|
||||
*
|
||||
* Unfortunately, [KtParameter] in PSI stands for many things, and not all of them are represented by a single type of symbol,
|
||||
* so this function does not work for all possible [KtParameter]s.
|
||||
*
|
||||
* If [KtParameter.isFunctionTypeParameter] is `true`, i.e., if the given [KtParameter] is used as a function type parameter,
|
||||
* it is not possible to create [KtValueParameterSymbol], hence an error will be raised.
|
||||
*
|
||||
* If [KtParameter.isLoopParameter] is `true`, i.e. if the given [KtParameter] is a loop variable in `for` expression, then the function
|
||||
* returns [KtLocalVariableSymbol].
|
||||
*
|
||||
* Otherwise, returns [KtValueParameterSymbol].
|
||||
*/
|
||||
public fun KtParameter.getParameterSymbol(): KtValueParameterSymbol =
|
||||
public fun KtParameter.getParameterSymbol(): KtVariableLikeSymbol =
|
||||
analysisSession.symbolProvider.getParameterSymbol(this)
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fun usage() {
|
||||
for (loopVariable in 1..10) {}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
KtFirLocalVariableSymbol:
|
||||
annotatedType: [] kotlin/Int
|
||||
callableIdIfNonLocal: null
|
||||
isExtension: false
|
||||
isVal: true
|
||||
name: loopVariable
|
||||
origin: SOURCE
|
||||
receiverType: null
|
||||
symbolKind: LOCAL
|
||||
deprecationStatus: null
|
||||
|
||||
KtFirFunctionSymbol:
|
||||
annotatedType: [] kotlin/Unit
|
||||
annotationClassIds: []
|
||||
annotations: []
|
||||
callableIdIfNonLocal: /usage
|
||||
dispatchType: null
|
||||
hasStableParameterNames: true
|
||||
isExtension: false
|
||||
isExternal: false
|
||||
isInfix: false
|
||||
isInline: false
|
||||
isOperator: false
|
||||
isOverride: false
|
||||
isStatic: false
|
||||
isSuspend: false
|
||||
modality: FINAL
|
||||
name: usage
|
||||
origin: SOURCE
|
||||
receiverType: null
|
||||
symbolKind: TOP_LEVEL
|
||||
typeParameters: []
|
||||
valueParameters: []
|
||||
visibility: Public
|
||||
deprecationStatus: null
|
||||
Reference in New Issue
Block a user