All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jetbrains.kotlin.fir.scopes.FirContainingNamesAwareScope.kt Maven / Gradle / Ivy

/*
 * Copyright 2010-2020 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.fir.scopes

import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol
import org.jetbrains.kotlin.name.Name

interface FirContainingNamesAwareScope {
    fun getCallableNames(): Set

    fun getClassifierNames(): Set
}

fun FirScope.getContainingCallableNamesIfPresent(): Set =
    if (this is FirContainingNamesAwareScope) getCallableNames() else emptySet()

fun FirScope.getContainingClassifierNamesIfPresent(): Set =
    if (this is FirContainingNamesAwareScope) getClassifierNames() else emptySet()

fun  S.processAllFunctions(processor: (FirFunctionSymbol<*>) -> Unit) where S : FirScope, S : FirContainingNamesAwareScope {
    for (name in getCallableNames()) {
        processFunctionsByName(name, processor)
    }
}

fun  S.processAllProperties(processor: (FirVariableSymbol<*>) -> Unit) where S : FirScope, S : FirContainingNamesAwareScope {
    for (name in getCallableNames()) {
        processPropertiesByName(name, processor)
    }
}

fun  S.collectAllFunctions(): Collection> where S : FirScope, S : FirContainingNamesAwareScope {
    return mutableListOf>().apply {
        processAllFunctions(this::add)
    }
}

fun  S.collectAllProperties(): Collection> where S : FirScope, S : FirContainingNamesAwareScope {
    return mutableListOf>().apply {
        processAllProperties(this::add)
    }
}