[FIR] Refactoring: Move set utility functions to setUtils.kt
This commit is contained in:
committed by
Space Team
parent
8d2bf8828c
commit
38ebe60e9f
-19
@@ -1,19 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2023 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.utils.collections
|
||||
|
||||
/**
|
||||
* Maps all elements of this non-empty collection with the given [transform] function to a new mutable set, or returns [emptySet] if this
|
||||
* collection is empty.
|
||||
*
|
||||
* [mapToSetOrEmpty] should be preferred over `collection.mapTo(mutableSetOf()) { ... }` when `collection` may be empty and the resulting
|
||||
* set may be cached, because [mapToSetOrEmpty] saves memory by avoiding the creation of an empty mutable set.
|
||||
*/
|
||||
public inline fun <T, R> Collection<T>.mapToSetOrEmpty(transform: (T) -> R): Set<R> =
|
||||
if (isNotEmpty()) mapTo(mutableSetOf(), transform) else emptySet()
|
||||
|
||||
public inline fun <T> Collection<T>.filterToSetOrEmpty(predicate: (T) -> Boolean): Set<T> =
|
||||
filterTo(mutableSetOf(), predicate).ifEmpty { emptySet() }
|
||||
+1
-2
@@ -6,8 +6,6 @@
|
||||
package org.jetbrains.kotlin.analysis.low.level.api.fir.util
|
||||
|
||||
import org.jetbrains.kotlin.analysis.providers.KotlinDeclarationProvider
|
||||
import org.jetbrains.kotlin.analysis.utils.collections.filterToSetOrEmpty
|
||||
import org.jetbrains.kotlin.analysis.utils.collections.mapToSetOrEmpty
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolNamesProvider
|
||||
@@ -15,6 +13,7 @@ import org.jetbrains.kotlin.fir.resolve.providers.FirDelegatingCachedSymbolNames
|
||||
import org.jetbrains.kotlin.fir.resolve.providers.FirCachedSymbolNamesProvider
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.utils.filterToSetOrEmpty
|
||||
|
||||
/**
|
||||
* A [FirSymbolNamesProvider] that fetches top-level names from a Kotlin [declarationProvider].
|
||||
|
||||
Reference in New Issue
Block a user