From efc39c613745d7525ce8a9561fec15bd8a959df6 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Wed, 28 Nov 2018 16:19:37 +0300 Subject: [PATCH] Minor. Reformat KtLightModifierList.kt and make function private --- .../asJava/elements/KtLightModifierList.kt | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/elements/KtLightModifierList.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/elements/KtLightModifierList.kt index 282b7411bb2..57d751f9bb5 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/elements/KtLightModifierList.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/elements/KtLightModifierList.kt @@ -35,8 +35,9 @@ import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.jvm.annotations.JVM_DEFAULT_FQ_NAME import org.jetbrains.kotlin.resolve.source.getPsi -abstract class KtLightModifierList>(protected val owner: T) - : KtLightElementBase(owner), PsiModifierList, KtLightElement { +abstract class KtLightModifierList>( + protected val owner: T +) : KtLightElementBase(owner), PsiModifierList, KtLightElement { override val clsDelegate by lazyPub { owner.clsDelegate.modifierList!! } private val _annotations by lazyPub { computeAnnotations() } @@ -57,13 +58,13 @@ abstract class KtLightModifierList && owner == another.owner + another is KtLightModifierList<*> && owner == another.owner override fun isWritable() = false override fun toString() = "Light modifier list of $owner" - protected open fun computeAnnotations(): List { + private fun computeAnnotations(): List { val annotationsForEntries = lightAnnotationsForEntries(this) val modifierListOwner = parent if (modifierListOwner is KtLightClassForSourceDeclaration && modifierListOwner.isAnnotationType) { @@ -74,7 +75,8 @@ abstract class KtLightModifierList && modifierListOwner !is KtLightFieldImpl.KtLightEnumConstant) - || modifierListOwner is LightParameter) { + || modifierListOwner is LightParameter + ) { return annotationsForEntries + listOf(KtLightNullabilityAnnotation(modifierListOwner as KtLightElement<*, PsiModifierListOwner>, this)) } @@ -84,7 +86,7 @@ abstract class KtLightModifierList, private val modifiers: Set + owner: KtLightElement, private val modifiers: Set ) : KtLightModifierList>(owner) { override fun hasModifierProperty(name: String) = name in modifiers @@ -105,21 +107,20 @@ private fun lightAnnotationsForEntries(lightModifierList: KtLightModifierList<*> } return getAnnotationDescriptors(annotatedKtDeclaration, lightModifierListOwner) - .mapNotNull { descriptor -> - val fqName = descriptor.fqName?.asString() ?: return@mapNotNull null - val entry = descriptor.source.getPsi() as? KtAnnotationEntry ?: return@mapNotNull null - Pair(fqName, entry) - } - .groupBy({ it.first }) { it.second } - .flatMap { - (fqName, entries) -> - entries.mapIndexed { index, entry -> - KtLightAnnotationForSourceEntry(fqName, entry, lightModifierList) { - lightModifierList.clsDelegate.annotations.filter { it.qualifiedName == fqName }.getOrNull(index) + .mapNotNull { descriptor -> + val fqName = descriptor.fqName?.asString() ?: return@mapNotNull null + val entry = descriptor.source.getPsi() as? KtAnnotationEntry ?: return@mapNotNull null + Pair(fqName, entry) + } + .groupBy({ it.first }) { it.second } + .flatMap { (fqName, entries) -> + entries.mapIndexed { index, entry -> + KtLightAnnotationForSourceEntry(fqName, entry, lightModifierList) { + lightModifierList.clsDelegate.annotations.filter { it.qualifiedName == fqName }.getOrNull(index) ?: KtLightNonExistentAnnotation(lightModifierList) - } } } + } } fun isFromSources(lightElement: KtLightElement<*, *>): Boolean { @@ -139,8 +140,7 @@ private fun getAnnotationDescriptors(declaration: KtAnnotated, annotatedLightEle context[BindingContext.VALUE_PARAMETER, declaration] else context[BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, declaration] - } - else { + } else { context[BindingContext.DECLARATION_TO_DESCRIPTOR, declaration] }