-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid generating documentation for symbols annotated with @InternalRe…
…venueCatAPI (#1958)
- Loading branch information
1 parent
3e74d49
commit d8b3f23
Showing
8 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
plugins { | ||
alias(libs.plugins.kotlin.jvm) | ||
} | ||
|
||
dependencies { | ||
compileOnly(libs.dokka.core) | ||
implementation(libs.dokka.base) | ||
|
||
testImplementation(libs.kotlin.test) | ||
testImplementation(libs.dokka.testApi) | ||
testImplementation(libs.dokka.baseTestUtils) | ||
} |
40 changes: 40 additions & 0 deletions
40
...c/main/kotlin/com/revenuecat/dokka/plugin/hideinternal/HideInternalRevenueCatAPIPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.revenuecat.dokka.plugin.hideinternal | ||
|
||
import org.jetbrains.dokka.base.DokkaBase | ||
import org.jetbrains.dokka.base.transformers.documentables.SuppressedByConditionDocumentableFilterTransformer | ||
import org.jetbrains.dokka.model.Annotations | ||
import org.jetbrains.dokka.model.Documentable | ||
import org.jetbrains.dokka.model.properties.WithExtraProperties | ||
import org.jetbrains.dokka.plugability.DokkaContext | ||
import org.jetbrains.dokka.plugability.DokkaPlugin | ||
import org.jetbrains.dokka.plugability.DokkaPluginApiPreview | ||
import org.jetbrains.dokka.plugability.PluginApiPreviewAcknowledgement | ||
|
||
class HideInternalRevenueCatAPIPlugin : DokkaPlugin() { | ||
|
||
val filterExtension by extending { | ||
plugin<DokkaBase>().preMergeDocumentableTransformer providing ::HideInternalRevenueCatAPITransformer | ||
} | ||
|
||
@OptIn(DokkaPluginApiPreview::class) | ||
override fun pluginApiPreviewAcknowledgement() = PluginApiPreviewAcknowledgement | ||
} | ||
|
||
class HideInternalRevenueCatAPITransformer( | ||
context: DokkaContext, | ||
) : SuppressedByConditionDocumentableFilterTransformer(context) { | ||
|
||
override fun shouldBeSuppressed(d: Documentable): Boolean { | ||
val annotations: List<Annotations.Annotation> = | ||
(d as? WithExtraProperties<*>) | ||
?.extra | ||
?.allOfType<Annotations>() | ||
?.flatMap { it.directAnnotations.values.flatten() } | ||
?: emptyList() | ||
|
||
return annotations.any { isInternalAnnotation(it) } | ||
} | ||
|
||
private fun isInternalAnnotation(annotation: Annotations.Annotation): Boolean = | ||
annotation.dri.packageName == "com.revenuecat.purchases" && annotation.dri.classNames == "InternalRevenueCatAPI" | ||
} |
1 change: 1 addition & 0 deletions
1
...internal/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
com.revenuecat.dokka.plugin.hideinternal.HideInternalRevenueCatAPIPlugin |
122 changes: 122 additions & 0 deletions
122
...st/kotlin/com/revenuecat/dokka/plugin/hideinternal/HideInternalRevenueCatAPIPluginTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package com.revenuecat.dokka.plugin.hideinternal | ||
|
||
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest | ||
import org.jetbrains.dokka.model.DClass | ||
import org.jetbrains.dokka.model.DObject | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class HideInternalRevenueCatAPIPluginTest: BaseAbstractTest() { | ||
|
||
@Test | ||
fun `Should hide annotated functions`() { | ||
val configuration = dokkaConfiguration { | ||
sourceSets { | ||
sourceSet { | ||
sourceRoots = listOf("src/main/kotlin/basic/Test.kt") | ||
} | ||
} | ||
} | ||
val hideInternalPlugin = HideInternalRevenueCatAPIPlugin() | ||
|
||
testInline( | ||
""" | ||
|/src/main/kotlin/basic/Test.kt | ||
|package com.revenuecat.purchases | ||
| | ||
|annotation class InternalRevenueCatAPI | ||
| | ||
|fun shouldBeVisible() {} | ||
| | ||
|@InternalRevenueCatAPI | ||
|fun shouldBeExcludedFromDocumentation() {} | ||
""".trimMargin(), | ||
configuration = configuration, | ||
pluginOverrides = listOf(hideInternalPlugin) | ||
) { | ||
preMergeDocumentablesTransformationStage = { modules -> | ||
val testModule = modules.single { it.name == "root" } | ||
val testPackage = testModule.packages.single { it.name == "com.revenuecat.purchases" } | ||
|
||
val packageFunctions = testPackage.functions | ||
assertEquals(expected = 1, actual = packageFunctions.size) | ||
assertEquals(expected = "shouldBeVisible", actual = packageFunctions[0].name) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun `Should hide annotated classes`() { | ||
val configuration = dokkaConfiguration { | ||
sourceSets { | ||
sourceSet { | ||
sourceRoots = listOf("src/main/kotlin/basic/Test.kt") | ||
} | ||
} | ||
} | ||
val hideInternalPlugin = HideInternalRevenueCatAPIPlugin() | ||
|
||
testInline( | ||
""" | ||
|/src/main/kotlin/basic/Test.kt | ||
|package com.revenuecat.purchases | ||
| | ||
|annotation class InternalRevenueCatAPI | ||
| | ||
|class ShouldBeVisible | ||
| | ||
|@InternalRevenueCatAPI | ||
|class ShouldBeExcludedFromDocumentation | ||
""".trimMargin(), | ||
configuration = configuration, | ||
pluginOverrides = listOf(hideInternalPlugin) | ||
) { | ||
preMergeDocumentablesTransformationStage = { modules -> | ||
val testModule = modules.single { it.name == "root" } | ||
val testPackage = testModule.packages.single { it.name == "com.revenuecat.purchases" } | ||
|
||
val packageClasses = testPackage.classlikes.filterIsInstance<DClass>() | ||
assertEquals(expected = 1, actual = packageClasses.size) | ||
assertEquals(expected = "ShouldBeVisible", actual = packageClasses[0].name) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun `Should hide annotated objects`() { | ||
val configuration = dokkaConfiguration { | ||
sourceSets { | ||
sourceSet { | ||
sourceRoots = listOf("src/main/kotlin/basic/Test.kt") | ||
} | ||
} | ||
} | ||
val hideInternalPlugin = HideInternalRevenueCatAPIPlugin() | ||
|
||
testInline( | ||
""" | ||
|/src/main/kotlin/basic/Test.kt | ||
|package com.revenuecat.purchases | ||
| | ||
|annotation class InternalRevenueCatAPI | ||
| | ||
|object ShouldBeVisible | ||
| | ||
|@InternalRevenueCatAPI | ||
|object ShouldBeExcludedFromDocumentation | ||
""".trimMargin(), | ||
configuration = configuration, | ||
pluginOverrides = listOf(hideInternalPlugin) | ||
) { | ||
preMergeDocumentablesTransformationStage = { modules -> | ||
val testModule = modules.single { it.name == "root" } | ||
val testPackage = testModule.packages.single { it.name == "com.revenuecat.purchases" } | ||
|
||
val packageObjects = testPackage.classlikes.filterIsInstance<DObject>() | ||
assertEquals(expected = 1, actual = packageObjects.size) | ||
assertEquals(expected = "ShouldBeVisible", actual = packageObjects[0].name) | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters