[Analysis API FIR] fix containing declaration for value parameter

now it should also work for non-source declarations
This commit is contained in:
Ilya Kirillov
2022-11-18 18:04:33 +01:00
parent 7781ad67d4
commit f775778efa
6 changed files with 21 additions and 4 deletions
@@ -54,8 +54,7 @@ internal class KtFirSymbolContainingDeclarationProvider(
}
is KtValueParameterSymbol -> {
// todo that does not work for parameters not from source, corresponding info should be added to the fir tree
getParentSymbolByPsi()
firSymbolBuilder.callableBuilder.buildCallableSymbol(symbol.firSymbol.fir.containingFunctionSymbol)
}
is KtCallableSymbol -> {
@@ -152,6 +152,7 @@ internal fun KtAnalysisSession.compareCalls(call1: KtCall, call2: KtCall): Int {
context(KtAnalysisSession)
internal fun renderScopeWithParentDeclarations(scope: KtScope): String = prettyPrint {
fun KtSymbol.qualifiedNameString() = when (this) {
is KtConstructorSymbol -> "<constructor> ${containingClassIdIfNonLocal?.asString()}"
is KtClassLikeSymbol -> classIdIfNonLocal!!.asString()
is KtCallableSymbol -> callableIdIfNonLocal!!.toString()
else -> error("unknown symbol $this")
@@ -179,5 +180,17 @@ internal fun renderScopeWithParentDeclarations(scope: KtScope): String = prettyP
}
}
}
if (symbol is KtFunctionLikeSymbol && symbol.valueParameters.isNotEmpty()) {
appendLine()
withIndent {
printCollection(symbol.valueParameters, separator = "\n") { typeParameter ->
val containingDeclarationForValueParameter = typeParameter.getContainingSymbol()
append(typeParameter.render(renderingOptions))
append(" from ")
append(containingDeclarationForValueParameter?.qualifiedNameString())
}
}
}
}
}
@@ -4,4 +4,5 @@ fun y() fromClass BB
val c: Int fromClass BB
constructor(a: A<Int>) fromClass BB
constructor(a: A<Int>) fromClass BB
a: A<Int> from <constructor> BB
@@ -2,6 +2,7 @@ fun <T> foo() fromClass Y
T from /Y.foo
fun equals(other: Any?): Boolean fromClass kotlin/Any
other: Any? from kotlin/Any.equals
fun hashCode(): Int fromClass kotlin/Any
@@ -1,13 +1,16 @@
fun <S> foo1(t: Int): Int fromClass Y
S from /Y.foo1
t: Int from /Y.foo1
fun <Q> foo2(t: Int) fromClass Y
Q from /Y.foo2
t: Int from /Y.foo2
fun <U> foo3() fromClass X
U from /X.foo3
fun equals(other: Any?): Boolean fromClass kotlin/Any
other: Any? from kotlin/Any.equals
fun hashCode(): Int fromClass kotlin/Any
@@ -4,4 +4,4 @@ var prop: kotlin.Int
@GetAnnotation
get()
@SetAnnotation
set(@setparam:SetparamAnnotation value: kotlin.Int)
set(@SetparamAnnotation value: kotlin.Int)