From 973d63bc2d4f5ac912e7c78f019c6689b3acbdc3 Mon Sep 17 00:00:00 2001 From: Andrzej Ratajczak Date: Thu, 25 Jun 2020 14:22:28 +0200 Subject: Fixed requested changes --- .../src/main/kotlin/signatures/JvmSignatureUtils.kt | 2 +- .../main/kotlin/signatures/KotlinSignatureProvider.kt | 15 +++++++-------- .../main/kotlin/signatures/KotlinSignatureUtils.kt | 2 +- .../DefaultDescriptorToDocumentableTranslator.kt | 19 +++++++++---------- .../psi/DefaultPsiToDocumentableTranslator.kt | 6 +++--- 5 files changed, 21 insertions(+), 23 deletions(-) (limited to 'plugins/base/src/main') diff --git a/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt b/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt index 40f7dfda..8dbe7b12 100644 --- a/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt +++ b/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt @@ -130,7 +130,7 @@ interface JvmSignatureUtils { } } - fun WithExtraProperties.stylesForDeprecated(sourceSetData: SourceSetData): Set = + fun WithExtraProperties.stylesIfDeprecated(sourceSetData: SourceSetData): Set = if (extra[Annotations]?.content?.get(sourceSetData)?.any { it.dri == DRI("kotlin", "Deprecated") || it.dri == DRI("java.lang", "Deprecated") diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt index eee44644..3e92b902 100644 --- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt +++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt @@ -7,7 +7,6 @@ import org.jetbrains.dokka.links.* import org.jetbrains.dokka.model.* import org.jetbrains.dokka.model.Nullable import org.jetbrains.dokka.model.TypeConstructor -import org.jetbrains.dokka.model.properties.PropertyContainer import org.jetbrains.dokka.model.properties.WithExtraProperties import org.jetbrains.dokka.pages.ContentKind import org.jetbrains.dokka.pages.ContentNode @@ -60,7 +59,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog contentBuilder.contentFor( e, ContentKind.Symbol, - setOf(TextStyle.Monospace, TextStyle.Block) + e.stylesForDeprecated(it), + setOf(TextStyle.Monospace, TextStyle.Block) + e.stylesIfDeprecated(it), sourceSets = setOf(it) ) { group(styles = setOf(TextStyle.Block)) { @@ -78,7 +77,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog contentBuilder.contentFor( c, ContentKind.Symbol, - setOf(TextStyle.Monospace) + ((c as? WithExtraProperties)?.stylesForDeprecated(sourceSet) + setOf(TextStyle.Monospace) + ((c as? WithExtraProperties)?.stylesIfDeprecated(sourceSet) ?: emptySet()), sourceSets = setOf(sourceSet) ) { @@ -102,7 +101,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog contentBuilder.contentFor( c, ContentKind.Symbol, - setOf(TextStyle.Monospace) + ((c as? WithExtraProperties)?.stylesForDeprecated(sourceSet) + setOf(TextStyle.Monospace) + ((c as? WithExtraProperties)?.stylesIfDeprecated(sourceSet) ?: emptySet()), sourceSets = setOf(sourceSet) ) { @@ -187,7 +186,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog private fun propertySignature(p: DProperty) = p.sourceSets.map { - contentBuilder.contentFor(p, ContentKind.Symbol, setOf(TextStyle.Monospace) + p.stylesForDeprecated(it), sourceSets = setOf(it)) { + contentBuilder.contentFor(p, ContentKind.Symbol, setOf(TextStyle.Monospace) + p.stylesIfDeprecated(it), sourceSets = setOf(it)) { annotationsBlock(p) text(p.visibility[it].takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "") text( @@ -212,7 +211,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog private fun functionSignature(f: DFunction) = f.sourceSets.map { - contentBuilder.contentFor(f, ContentKind.Symbol, setOf(TextStyle.Monospace) + f.stylesForDeprecated(it), sourceSets = setOf(it)) { + contentBuilder.contentFor(f, ContentKind.Symbol, setOf(TextStyle.Monospace) + f.stylesIfDeprecated(it), sourceSets = setOf(it)) { annotationsBlock(f) text(f.visibility[it]?.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "") text(f.modifier[it]?.takeIf { it !in ignoredModifiers }?.let { @@ -254,7 +253,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog private fun signature(t: DTypeAlias) = t.sourceSets.map { - contentBuilder.contentFor(t, styles = t.stylesForDeprecated(it), sourceSets = setOf(it)) { + contentBuilder.contentFor(t, styles = t.stylesIfDeprecated(it), sourceSets = setOf(it)) { t.underlyingType.entries.groupBy({ it.value }, { it.key }).map { (type, platforms) -> +contentBuilder.contentFor( t, @@ -275,7 +274,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog private fun signature(t: DTypeParameter) = t.sourceSets.map { - contentBuilder.contentFor(t, styles = t.stylesForDeprecated(it), sourceSets = setOf(it)) { + contentBuilder.contentFor(t, styles = t.stylesIfDeprecated(it), sourceSets = setOf(it)) { link(t.name, t.dri.withTargetToDeclaration()) list(t.bounds, prefix = " : ") { signatureForProjection(it) diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt index 5e35c240..4fcb9761 100644 --- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt +++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt @@ -10,7 +10,7 @@ object KotlinSignatureUtils : JvmSignatureUtils { private val strategy = OnlyOnce private val listBrackets = Pair('[', ']') private val classExtension = "::class" - val ignoredAnnotations = setOf( + private val ignoredAnnotations = setOf( Annotations.Annotation(DRI("kotlin", "SinceKotlin"), emptyMap()), Annotations.Annotation(DRI("kotlin", "Deprecated"), emptyMap()) ) diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index ad872e2a..49d8ae0f 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -696,16 +696,15 @@ private class DokkaDescriptorVisitor( else -> StringValue(toString()) } - private fun AnnotationDescriptor.toAnnotation(): Annotations.Annotation? = - DRI.from(annotationClass as DeclarationDescriptor).let { - Annotations.Annotation( - it, - allValueArguments.map { it.key.asString() to it.value.toValue() }.filter { - it.second != null - }.toMap() as Map, - annotationClass!!.annotations.hasAnnotation(FqName("kotlin.annotation.MustBeDocumented")) - ) - } + private fun AnnotationDescriptor.toAnnotation(): Annotations.Annotation { + return Annotations.Annotation( + DRI.from(annotationClass as DeclarationDescriptor), + allValueArguments.map { it.key.asString() to it.value.toValue() }.filter { + it.second != null + }.toMap() as Map, + annotationClass!!.annotations.hasAnnotation(FqName("kotlin.annotation.MustBeDocumented")) + ) + } private fun PropertyDescriptor.getAnnotationsWithBackingField(): List = getAnnotations() + (backingField?.getAnnotations() ?: emptyList()) diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt index f3102b2d..a5117b09 100644 --- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt @@ -429,12 +429,12 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { else -> StringValue(text ?: "") } - private fun PsiAnnotation.toAnnotation() = psiReference?.let { + private fun PsiAnnotation.toAnnotation() = psiReference?.let { psiElement -> Annotations.Annotation( - DRI.from(it), + DRI.from(psiElement), attributes.filter { it !is KtLightAbstractAnnotation }.mapNotNull { it.attributeName to it.toValue() } .toMap(), - (it as PsiClass).annotations.any { + (psiElement as PsiClass).annotations.any { hasQualifiedName("java.lang.annotation.Documented") } ) -- cgit