[Analysis API] add KtTypeScope.getCallableSignatures/getClassifierSymbols overloads which accept a candidate name set

This is needed for the cases when a candidate name set is known
to avoid retrieving a set with all possible names when processing the scope.

Similar to KtScope.

^KT-58653
This commit is contained in:
Ilya Kirillov
2023-05-12 15:50:31 +02:00
committed by Space Team
parent ee1fd9f6e9
commit f8ddf204e2
3 changed files with 62 additions and 2 deletions
@@ -5,9 +5,11 @@
package org.jetbrains.kotlin.analysis.api.scopes
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
import org.jetbrains.kotlin.analysis.api.signatures.KtCallableSignature
import org.jetbrains.kotlin.analysis.api.symbols.KtClassifierSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KtConstructorSymbol
import org.jetbrains.kotlin.analysis.api.signatures.KtCallableSignature
import org.jetbrains.kotlin.name.Name
/**
* A scope inside which use-site type-parameters of callable declarations may be substituted. Such declarations are represented as [KtCallableSignature].
@@ -22,12 +24,49 @@ public interface KtTypeScope : KtScopeLike {
*/
public fun getCallableSignatures(nameFilter: KtScopeNameFilter = { true }): Sequence<KtCallableSignature<*>>
/**
* Return a sequence of [KtCallableSignature] which current scope contain if declaration, if declaration name present in [names]
*
* This implementation is more optimal than the one with `nameFilter` and should be used when the candidate name set is known.
*/
public fun getCallableSignatures(names: Collection<Name>): Sequence<KtCallableSignature<*>>
/**
* Return a sequence of [KtCallableSignature] which current scope contain if declaration, if declaration name present in [names]
*
* @see getCallableSignatures
*/
public fun getCallableSignatures(vararg names: Name): Sequence<KtCallableSignature<*>> = withValidityAssertion {
getCallableSignatures(names.toList())
}
/**
* Return a sequence of [KtClassifierSymbol] which current scope contain if classifier name matches [nameFilter]. The sequence includes:
* nested classes, inner classes, nested type aliases for the class scope, and top-level classes and top-level type aliases for file scope.
*
* This function needs to retrieve a set of all possible names before processing the scope.
* The overload with `names: Collection<Name>` should be used when the candidate name set is known.
*/
public fun getClassifierSymbols(nameFilter: KtScopeNameFilter = { true }): Sequence<KtClassifierSymbol>
/**
* Return a sequence of [KtClassifierSymbol] which current scope contains, if classifier name present in [names].
*
* The sequence includes: nested classes, inner classes, nested type aliases for the class scope,
* and top-level classes and top-level type aliases for file scope.
*
* This implementation is more optimal than the one with `nameFilter` and should be used when the candidate name set is known.
*/
public fun getClassifierSymbols(names: Collection<Name>): Sequence<KtClassifierSymbol>
/**
* Return a sequence of [KtClassifierSymbol] which current scope contains, if classifier name present in [names].
*
* @see getClassifierSymbols
*/
public fun getClassifierSymbols(vararg names: Name): Sequence<KtClassifierSymbol> =
getClassifierSymbols(names.toList())
/**
* Return a sequence of [KtConstructorSymbol] which current scope contain
*/