From 071269b3c6e786f487f660c34f2a465c5e1aa851 Mon Sep 17 00:00:00 2001 From: Dmitrii Gridin Date: Wed, 25 Jan 2023 12:54:36 +0100 Subject: [PATCH] [SLC] introduce CompositeAnnotationsProvider ^KT-56046 --- .../CompositeAnnotationsProvider.kt | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/annotations/CompositeAnnotationsProvider.kt diff --git a/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/annotations/CompositeAnnotationsProvider.kt b/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/annotations/CompositeAnnotationsProvider.kt new file mode 100644 index 00000000000..10842f4eea4 --- /dev/null +++ b/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/annotations/CompositeAnnotationsProvider.kt @@ -0,0 +1,34 @@ +/* + * 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.light.classes.symbol.annotations + +import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication +import org.jetbrains.kotlin.name.ClassId + +internal class CompositeAnnotationsProvider(val providers: Collection) : AnnotationsProvider { + override fun classIds(): Collection = buildList { + for (provider in providers) { + addAll(provider.classIds()) + } + } + + override fun get(classId: ClassId): Collection = buildList { + for (provider in providers) { + addAll(provider[classId]) + } + } + + override fun contains(classId: ClassId): Boolean = providers.any { classId in it } + + override fun isTheSameAs(other: Any?): Boolean = other === this || + other is CompositeAnnotationsProvider && + other.providers.size == providers.size && + other.providers.zip(providers).all { (another, myProvider) -> + myProvider.isTheSameAs(another) + } + + override fun ownerClassId(): ClassId? = null +}