/
firScopeUtils.kt
76 lines (68 loc) · 2.69 KB
/
firScopeUtils.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.analysis.api.fir.scopes
import org.jetbrains.kotlin.analysis.api.fir.KtSymbolByFirBuilder
import org.jetbrains.kotlin.analysis.api.signatures.KtCallableSignature
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KtClassifierSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KtConstructorSymbol
import org.jetbrains.kotlin.fir.scopes.FirScope
import org.jetbrains.kotlin.fir.scopes.processClassifiersByName
import org.jetbrains.kotlin.name.Name
internal fun FirScope.getCallableSymbols(
callableNames: Collection<Name>,
builder: KtSymbolByFirBuilder
): Sequence<KtCallableSymbol> = sequence {
callableNames.forEach { name ->
yieldList {
processFunctionsByName(name) { firSymbol ->
add(builder.functionLikeBuilder.buildFunctionSymbol(firSymbol))
}
}
yieldList {
processPropertiesByName(name) { firSymbol ->
add(builder.callableBuilder.buildCallableSymbol(firSymbol))
}
}
}
}
internal fun FirScope.getCallableSignatures(
callableNames: Collection<Name>,
builder: KtSymbolByFirBuilder
): Sequence<KtCallableSignature<*>> = sequence {
callableNames.forEach { name ->
yieldList {
processFunctionsByName(name) { firSymbol ->
add(builder.functionLikeBuilder.buildFunctionLikeSignature(firSymbol))
}
}
yieldList {
processPropertiesByName(name) { firSymbol ->
add(builder.variableLikeBuilder.buildVariableLikeSignature(firSymbol))
}
}
}
}
internal fun FirScope.getClassifierSymbols(classLikeNames: Collection<Name>, builder: KtSymbolByFirBuilder): Sequence<KtClassifierSymbol> =
sequence {
classLikeNames.forEach { name ->
yieldList {
processClassifiersByName(name) { firSymbol ->
add(builder.classifierBuilder.buildClassifierSymbol(firSymbol))
}
}
}
}
internal fun FirScope.getConstructors(builder: KtSymbolByFirBuilder): Sequence<KtConstructorSymbol> =
sequence {
yieldList {
processDeclaredConstructors { firSymbol ->
add(builder.functionLikeBuilder.buildConstructorSymbol(firSymbol))
}
}
}
private suspend inline fun <T> SequenceScope<T>.yieldList(listBuilder: MutableList<T>.() -> Unit) {
yieldAll(buildList(listBuilder))
}