Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix checking for annotations when rendering constructor keyword #3523

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dokka-subprojects/plugin-base/api/plugin-base.api
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,7 @@ public abstract interface class org/jetbrains/dokka/base/signatures/JvmSignature
public abstract fun annotationsBlockWithIgnored (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;Ljava/util/Set;Lorg/jetbrains/dokka/base/signatures/AtStrategy;Lkotlin/Pair;Ljava/lang/String;)V
public abstract fun annotationsInline (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;)V
public abstract fun annotationsInlineWithIgnored (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;Ljava/util/Set;Lorg/jetbrains/dokka/base/signatures/AtStrategy;Lkotlin/Pair;Ljava/lang/String;)V
public abstract fun isIgnored (Lorg/jetbrains/dokka/model/Annotations$Annotation;)Z
public abstract fun modifiers (Lorg/jetbrains/dokka/model/properties/WithExtraProperties;)Ljava/util/Map;
public abstract fun parametersBlock (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/DFunction;Lkotlin/jvm/functions/Function2;)V
public abstract fun plus (Ljava/util/Map;Ljava/util/Map;)Ljava/util/Map;
Expand Down Expand Up @@ -925,6 +926,7 @@ public final class org/jetbrains/dokka/base/signatures/KotlinSignatureProvider :
public fun annotationsBlockWithIgnored (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;Ljava/util/Set;Lorg/jetbrains/dokka/base/signatures/AtStrategy;Lkotlin/Pair;Ljava/lang/String;)V
public fun annotationsInline (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;)V
public fun annotationsInlineWithIgnored (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;Ljava/util/Set;Lorg/jetbrains/dokka/base/signatures/AtStrategy;Lkotlin/Pair;Ljava/lang/String;)V
public fun isIgnored (Lorg/jetbrains/dokka/model/Annotations$Annotation;)Z
public fun modifiers (Lorg/jetbrains/dokka/model/properties/WithExtraProperties;)Ljava/util/Map;
public fun parametersBlock (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/DFunction;Lkotlin/jvm/functions/Function2;)V
public fun plus (Ljava/util/Map;Ljava/util/Map;)Ljava/util/Map;
Expand All @@ -947,6 +949,7 @@ public final class org/jetbrains/dokka/base/signatures/KotlinSignatureUtils : or
public final fun getDri (Lorg/jetbrains/dokka/model/PrimitiveJavaType;)Lorg/jetbrains/dokka/links/DRI;
public final fun getDriOrNull (Lorg/jetbrains/dokka/model/Bound;)Lorg/jetbrains/dokka/links/DRI;
public final fun getDrisOfAllNestedBounds (Lorg/jetbrains/dokka/model/Projection;)Ljava/util/List;
public fun isIgnored (Lorg/jetbrains/dokka/model/Annotations$Annotation;)Z
public fun modifiers (Lorg/jetbrains/dokka/model/properties/WithExtraProperties;)Ljava/util/Map;
public fun parametersBlock (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/DFunction;Lkotlin/jvm/functions/Function2;)V
public fun plus (Ljava/util/Map;Ljava/util/Map;)Ljava/util/Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public interface JvmSignatureUtils {

public fun <T : Documentable> WithExtraProperties<T>.modifiers(): SourceSetDependent<Set<ExtraModifiers>>

public fun Annotations.Annotation.isIgnored(): Boolean

public fun Collection<ExtraModifiers>.toSignatureString(): String =
joinToString("") { it.name.toLowerCase() + " " }

Expand Down Expand Up @@ -71,7 +73,7 @@ public interface JvmSignatureUtils {
else -> null
}?.let {
it.entries.forEach {
it.value.filter { it !in ignored && it.mustBeDocumented }.takeIf { it.isNotEmpty() }?.let { annotations ->
it.value.filter { it.mustBeDocumented && it !in ignored }.takeIf { it.isNotEmpty() }?.let { annotations ->
group(sourceSets = setOf(it.key), styles = styles, kind = ContentKind.Annotations) {
annotations.forEach {
operation(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,11 @@ public class KotlinSignatureProvider(
if (c is WithConstructors) {
val pConstructor = c.constructors.singleOrNull { it.extra[PrimaryConstructorExtra] != null }
if (pConstructor?.sourceSets?.contains(sourceSet) == true) {
if (pConstructor.annotations().values.any { it.isNotEmpty() }) {
// `constructor` keyword should present only when there are annotations that should be rendered
val needConstructorKeyword = pConstructor.annotations().values.any { annotations ->
annotations.any { it.mustBeDocumented && !it.isIgnored() }
}
if (needConstructorKeyword) {
text(nbsp.toString())
annotationsInline(pConstructor)
keyword("constructor")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public object KotlinSignatureUtils : JvmSignatureUtils {
} ?: emptyMap()
}

override fun Annotations.Annotation.isIgnored(): Boolean = this in ignoredAnnotations

public val PrimitiveJavaType.dri: DRI get() = DRI("kotlin", name.capitalize())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,63 @@ class SignatureTest : BaseAbstractTest() {
}
}

@OnlyDescriptors("#3354")
@Test
fun `should not render parameterless constructor with annotation without mustBeDocumented annotation - for kotlin Any `() = testRender(
"""
|/src/main/kotlin/Any.kt
|package kotlin
|annotation class WasmPrimitiveConstructor
|open class Any @WasmPrimitiveConstructor constructor()
""".trimMargin(),
) {
renderedContent("root/kotlin/-any/index.html").firstSignature().matchIgnoringSpans(
"open class", A("Any")
)
}

@Test
fun `should not render parameterless constructor with annotation without mustBeDocumented annotation`() = testRender(
"""
|/src/main/kotlin/SomeClass.kt
|package example
|annotation class SomeAnnotation
|class SomeClass @SomeAnnotation constructor()
""".trimMargin(),
) {
renderedContent("root/example/-some-class/index.html").firstSignature().matchIgnoringSpans(
"class", A("SomeClass")
)
}

@Test
fun `should not render parameterless constructor with ignored annotation`() = testRender(
"""
|/src/main/kotlin/SomeClass.kt
|package example
|class SomeClass @Deprecated("reason") constructor()
""".trimMargin(),
) {
renderedContent("root/example/-some-class/index.html").firstSignature().matchIgnoringSpans(
"class", A("SomeClass")
)
}

@Test
fun `should render parameterless constructor with annotation with mustBeDocumented annotation`() = testRender(
"""
|/src/main/kotlin/SomeClass.kt
|package example
|@MustBeDocumented
|annotation class SomeAnnotation
|class SomeClass @SomeAnnotation constructor()
""".trimMargin(),
) {
renderedContent("root/example/-some-class/index.html").firstSignature().matchIgnoringSpans(
"class", A("SomeClass"), Span("@", A("SomeAnnotation")), "constructor"
)
}

private fun testRender(
query: String,
configuration: DokkaConfigurationImpl = this.configuration,
Expand Down
1 change: 1 addition & 0 deletions dokka-subprojects/plugin-javadoc/api/plugin-javadoc.api
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ public final class org/jetbrains/dokka/javadoc/signatures/JavadocSignatureProvid
public fun annotationsBlockWithIgnored (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;Ljava/util/Set;Lorg/jetbrains/dokka/base/signatures/AtStrategy;Lkotlin/Pair;Ljava/lang/String;)V
public fun annotationsInline (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;)V
public fun annotationsInlineWithIgnored (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;Ljava/util/Set;Lorg/jetbrains/dokka/base/signatures/AtStrategy;Lkotlin/Pair;Ljava/lang/String;)V
public fun isIgnored (Lorg/jetbrains/dokka/model/Annotations$Annotation;)Z
public fun modifiers (Lorg/jetbrains/dokka/model/properties/WithExtraProperties;)Ljava/util/Map;
public fun parametersBlock (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/DFunction;Lkotlin/jvm/functions/Function2;)V
public fun plus (Ljava/util/Map;Ljava/util/Map;)Ljava/util/Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public final class org/jetbrains/dokka/kotlinAsJava/signatures/JavaSignatureProv
public fun annotationsBlockWithIgnored (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;Ljava/util/Set;Lorg/jetbrains/dokka/base/signatures/AtStrategy;Lkotlin/Pair;Ljava/lang/String;)V
public fun annotationsInline (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;)V
public fun annotationsInlineWithIgnored (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;Ljava/util/Set;Lorg/jetbrains/dokka/base/signatures/AtStrategy;Lkotlin/Pair;Ljava/lang/String;)V
public fun isIgnored (Lorg/jetbrains/dokka/model/Annotations$Annotation;)Z
public fun modifiers (Lorg/jetbrains/dokka/model/properties/WithExtraProperties;)Ljava/util/Map;
public fun parametersBlock (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/DFunction;Lkotlin/jvm/functions/Function2;)V
public fun plus (Ljava/util/Map;Ljava/util/Map;)Ljava/util/Map;
Expand All @@ -51,6 +52,7 @@ public final class org/jetbrains/dokka/kotlinAsJava/signatures/JavaSignatureUtil
public fun annotationsBlockWithIgnored (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;Ljava/util/Set;Lorg/jetbrains/dokka/base/signatures/AtStrategy;Lkotlin/Pair;Ljava/lang/String;)V
public fun annotationsInline (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;)V
public fun annotationsInlineWithIgnored (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;Ljava/util/Set;Lorg/jetbrains/dokka/base/signatures/AtStrategy;Lkotlin/Pair;Ljava/lang/String;)V
public fun isIgnored (Lorg/jetbrains/dokka/model/Annotations$Annotation;)Z
public fun modifiers (Lorg/jetbrains/dokka/model/properties/WithExtraProperties;)Ljava/util/Map;
public fun parametersBlock (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/DFunction;Lkotlin/jvm/functions/Function2;)V
public fun plus (Ljava/util/Map;Ljava/util/Map;)Ljava/util/Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ public object JavaSignatureUtils : JvmSignatureUtils {
} ?: emptyMap()
}

override fun Annotations.Annotation.isIgnored(): Boolean = this in ignoredAnnotations

}
Loading