From fe3f7feae446bc4345c2842d5e4629d98b7e1e33 Mon Sep 17 00:00:00 2001 From: Marco Pennekamp Date: Thu, 4 May 2023 21:32:35 +0200 Subject: [PATCH] [AA] KT-58257 Introduce `KotlinModuleDependentsProvider` - Event-based session invalidation requires knowledge about the dependents of a `KtModule`. This is because, when the session for a module is invalidated, all sessions for modules which depend on that module, directly or indirectly, must also be invalidated. - Note that the approach with modification trackers relied on module dependencies. Events have an opposite flow of information compared to modification trackers: Modification trackers request whether a change occurred, while events publish that a change occurred. Thus, the modules which need to be incorporated into the invalidation dynamic are also flipped: dependents instead of dependencies. - `KotlinModuleDependentsProvider` is designed to work generally. It can be used for purposes beyond session invalidation. --- .../KotlinModuleDependentsProvider.kt | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 analysis/project-structure/src/org/jetbrains/kotlin/analysis/project/structure/KotlinModuleDependentsProvider.kt diff --git a/analysis/project-structure/src/org/jetbrains/kotlin/analysis/project/structure/KotlinModuleDependentsProvider.kt b/analysis/project-structure/src/org/jetbrains/kotlin/analysis/project/structure/KotlinModuleDependentsProvider.kt new file mode 100644 index 00000000000..828658ad42e --- /dev/null +++ b/analysis/project-structure/src/org/jetbrains/kotlin/analysis/project/structure/KotlinModuleDependentsProvider.kt @@ -0,0 +1,31 @@ +/* + * 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.project.structure + +import com.intellij.openapi.project.Project + +/** + * [KotlinModuleDependentsProvider] provides dependents for a [KtModule], which are modules that depend on the [KtModule]. + * + * Implementations of this provider should ensure that results are provided in reasonable time, for example by caching results, as its + * functions may be called frequently. + */ +public abstract class KotlinModuleDependentsProvider { + /** + * Returns all direct dependents of [module], excluding [module] if it depends on itself. + */ + public abstract fun getDirectDependents(module: KtModule): Set + + /** + * Returns all direct and indirect dependents of [module], excluding [module] if it depends on itself. + */ + public abstract fun getTransitiveDependents(module: KtModule): Set + + public companion object { + public fun getInstance(project: Project): KotlinModuleDependentsProvider = + project.getService(KotlinModuleDependentsProvider::class.java) + } +}