KTIJ-27050 [Analysis API] Refactor FirShorteningContext
Remove duplication from `findFirstClassifier*` functions
This commit is contained in:
+11
-13
@@ -264,25 +264,23 @@ private class FirShorteningContext(val analysisSession: KtFirAnalysisSession) {
|
||||
|
||||
class ClassifierCandidate(val scope: FirScope, val availableSymbol: AvailableSymbol<ClassId>)
|
||||
|
||||
fun findFirstClassifierInScopesByName(positionScopes: List<FirScope>, targetClassName: Name): AvailableSymbol<ClassId>? {
|
||||
for (scope in positionScopes) {
|
||||
val classifierSymbol = scope.findFirstClassifierByName(targetClassName) ?: continue
|
||||
val classifierLookupTag = classifierSymbol.toLookupTag() as? ConeClassLikeLookupTag ?: continue
|
||||
|
||||
return AvailableSymbol(classifierLookupTag.classId, ImportKind.fromScope(scope))
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
fun findFirstClassifierInScopesByName(positionScopes: List<FirScope>, targetClassName: Name): AvailableSymbol<ClassId>? =
|
||||
positionScopes.firstNotNullOfOrNull { scope -> findFirstClassifierSymbolByName(scope, targetClassName) }
|
||||
|
||||
fun findClassifiersInScopesByName(scopes: List<FirScope>, targetClassName: Name): List<ClassifierCandidate> =
|
||||
scopes.mapNotNull { scope ->
|
||||
val classifierSymbol = scope.findFirstClassifierByName(targetClassName) ?: return@mapNotNull null
|
||||
val classifierLookupTag = classifierSymbol.toLookupTag() as? ConeClassLikeLookupTag ?: return@mapNotNull null
|
||||
val classifierSymbol = findFirstClassifierSymbolByName(scope, targetClassName) ?: return@mapNotNull null
|
||||
|
||||
ClassifierCandidate(scope, AvailableSymbol(classifierLookupTag.classId, ImportKind.fromScope(scope)))
|
||||
ClassifierCandidate(scope, classifierSymbol)
|
||||
}
|
||||
|
||||
private fun findFirstClassifierSymbolByName(scope: FirScope, targetClassName: Name): AvailableSymbol<ClassId>? {
|
||||
val classifierSymbol = scope.findFirstClassifierByName(targetClassName) ?: return null
|
||||
val classifierLookupTag = classifierSymbol.toLookupTag() as? ConeClassLikeLookupTag ?: return null
|
||||
|
||||
return AvailableSymbol(classifierLookupTag.classId, ImportKind.fromScope(scope))
|
||||
}
|
||||
|
||||
fun findFunctionsInScopes(scopes: List<FirScope>, name: Name): List<AvailableSymbol<FirFunctionSymbol<*>>> {
|
||||
return scopes.flatMap { scope ->
|
||||
val importKind = ImportKind.fromScope(scope)
|
||||
|
||||
Reference in New Issue
Block a user