-
Notifications
You must be signed in to change notification settings - Fork 392
/
DeprecatedDocumentableFilterTransformer.kt
57 lines (48 loc) · 2.47 KB
/
DeprecatedDocumentableFilterTransformer.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package org.jetbrains.dokka.base.transformers.documentables
import org.jetbrains.dokka.DokkaConfiguration.PackageOptions
import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.model.Annotations
import org.jetbrains.dokka.model.Documentable
import org.jetbrains.dokka.model.EnumValue
import org.jetbrains.dokka.model.properties.WithExtraProperties
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.transformers.documentation.perPackageOptions
import org.jetbrains.dokka.transformers.documentation.sourceSet
/**
* If [PackageOptions.skipDeprecated] or [DokkaConfiguration.DokkaSourceSet.skipDeprecated] is set
* to `true`, suppresses documentables marked with [kotlin.Deprecated] or [java.lang.Deprecated].
* Package options are given preference over global options.
*
* Documentables with [kotlin.Deprecated.level] set to [DeprecationLevel.HIDDEN]
* are suppressed regardless of global and package options.
*/
class DeprecatedDocumentableFilterTransformer(context: DokkaContext) :
SuppressedByConditionDocumentableFilterTransformer(context) {
override fun shouldBeSuppressed(d: Documentable): Boolean {
val annotations = (d as? WithExtraProperties<*>)?.annotations() ?: return false
if (annotations.isEmpty())
return false
val deprecatedAnnotations = filterDeprecatedAnnotations(annotations)
if (deprecatedAnnotations.isEmpty())
return false
val kotlinDeprecated = deprecatedAnnotations.find { it.dri.packageName == "kotlin" }
if (kotlinDeprecated?.isHidden() == true)
return true
return perPackageOptions(d)?.skipDeprecated ?: sourceSet(d).skipDeprecated
}
private fun WithExtraProperties<*>.annotations(): List<Annotations.Annotation> {
return this.extra.allOfType<Annotations>().flatMap { annotations ->
annotations.directAnnotations.values.singleOrNull() ?: emptyList()
}
}
private fun filterDeprecatedAnnotations(annotations: List<Annotations.Annotation>): List<Annotations.Annotation> {
return annotations.filter {
(it.dri.packageName == "kotlin" && it.dri.classNames == "Deprecated") ||
(it.dri.packageName == "java.lang" && it.dri.classNames == "Deprecated")
}
}
private fun Annotations.Annotation.isHidden(): Boolean {
val level = (this.params["level"] as? EnumValue) ?: return false
return level.enumName == "DeprecationLevel.HIDDEN"
}
}