aboutsummaryrefslogtreecommitdiff
path: root/core/src/main
diff options
context:
space:
mode:
authorDmitry Jemerov <yole@jetbrains.com>2017-02-23 11:18:44 +0100
committerDmitry Jemerov <yole@jetbrains.com>2017-02-23 12:02:23 +0100
commit1270519a551cd30e452d282247d2d963bc9c25ca (patch)
treea42a39450ac361a25e7e1f901fda1132a428a382 /core/src/main
parent7fa258873eab770577879e9721c0864449ba1114 (diff)
downloaddokka-1270519a551cd30e452d282247d2d963bc9c25ca.tar.gz
dokka-1270519a551cd30e452d282247d2d963bc9c25ca.tar.bz2
dokka-1270519a551cd30e452d282247d2d963bc9c25ca.zip
Refactor SinceKotlin support to a more general "platform" mechanism
Diffstat (limited to 'core/src/main')
-rw-r--r--core/src/main/kotlin/Formats/StructuredFormatService.kt16
-rw-r--r--core/src/main/kotlin/Kotlin/DocumentationBuilder.kt34
-rw-r--r--core/src/main/kotlin/Model/DocumentationNode.kt5
-rw-r--r--core/src/main/kotlin/Model/DocumentationReference.kt13
4 files changed, 48 insertions, 20 deletions
diff --git a/core/src/main/kotlin/Formats/StructuredFormatService.kt b/core/src/main/kotlin/Formats/StructuredFormatService.kt
index 1488a4f9..02ec01b0 100644
--- a/core/src/main/kotlin/Formats/StructuredFormatService.kt
+++ b/core/src/main/kotlin/Formats/StructuredFormatService.kt
@@ -291,7 +291,7 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
}
item.appendOverrides()
item.appendDeprecation()
- item.appendSinceKotlin()
+ item.appendPlatforms()
}
// All items have exactly the same documentation, so we can use any item to render it
val item = items.first()
@@ -321,12 +321,6 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
}
}
- private fun DocumentationNode.appendSinceKotlin() {
- val annotation = sinceKotlin ?: return
- val value = annotation.detail(NodeKind.Parameter).detail(NodeKind.Value)
- appendSinceKotlin(value.name)
- }
-
private fun DocumentationNode.appendDeprecation() {
if (deprecation != null) {
val deprecationParameter = deprecation!!.details(NodeKind.Parameter).firstOrNull()
@@ -349,6 +343,14 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
}
}
+ private fun DocumentationNode.appendPlatforms() {
+ if (platforms.isEmpty()) return
+ appendParagraph {
+ appendStrong { to.append("Platform and version requirements:") }
+ to.append(" " + platforms.joinToString())
+ }
+ }
+
private fun DocumentationNode.appendDescription() {
if (content.description != ContentEmpty) {
appendContent(content.description)
diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt
index 30c1413d..bcbdf5f4 100644
--- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt
+++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt
@@ -62,6 +62,7 @@ class DocumentationBuilder
val descriptorDocumentationParser: DescriptorDocumentationParser,
val options: DocumentationOptions,
val refGraph: NodeReferenceGraph,
+ val platformNodeRegistry: PlatformNodeRegistry,
val logger: DokkaLogger,
val linkResolver: DeclarationLinkResolver) {
val boringBuiltinClasses = setOf(
@@ -199,21 +200,34 @@ class DocumentationBuilder
fun DocumentationNode.appendAnnotations(annotated: Annotated) {
annotated.annotations.forEach {
it.build()?.let { annotationNode ->
- val refKind = when {
- it.isDocumented() ->
- when {
- annotationNode.isDeprecation() -> RefKind.Deprecation
- annotationNode.isSinceKotlin() -> RefKind.SinceKotlin
- else -> RefKind.Annotation
- }
- it.isHiddenInDocumentation() -> RefKind.HiddenAnnotation
- else -> return@forEach
+ if (annotationNode.isSinceKotlin()) {
+ appendSinceKotlin(annotationNode)
}
- append(annotationNode, refKind)
+ else {
+ val refKind = when {
+ it.isDocumented() ->
+ when {
+ annotationNode.isDeprecation() -> RefKind.Deprecation
+ else -> RefKind.Annotation
+ }
+ it.isHiddenInDocumentation() -> RefKind.HiddenAnnotation
+ else -> return@forEach
+ }
+ append(annotationNode, refKind)
+ }
+
}
}
}
+ fun DocumentationNode.appendSinceKotlin(annotation: DocumentationNode) {
+ var kotlinVersion = annotation.detail(NodeKind.Parameter).detail(NodeKind.Value).name
+ if (kotlinVersion.startsWith('\"') && kotlinVersion.endsWith('\"')) {
+ kotlinVersion = kotlinVersion.substring(1..kotlinVersion.length-2)
+ }
+ append(platformNodeRegistry["Kotlin " + kotlinVersion], RefKind.Platform)
+ }
+
fun DocumentationNode.appendModifiers(descriptor: DeclarationDescriptor) {
val psi = (descriptor as DeclarationDescriptorWithSource).source.getPsi() as? KtModifierListOwner ?: return
KtTokens.MODIFIER_KEYWORDS_ARRAY.filter { it !in knownModifiers }.forEach {
diff --git a/core/src/main/kotlin/Model/DocumentationNode.kt b/core/src/main/kotlin/Model/DocumentationNode.kt
index 83897a3f..56c295cd 100644
--- a/core/src/main/kotlin/Model/DocumentationNode.kt
+++ b/core/src/main/kotlin/Model/DocumentationNode.kt
@@ -48,6 +48,7 @@ enum class NodeKind {
Signature,
ExternalLink,
+ Platform,
AllTypes,
@@ -97,8 +98,8 @@ open class DocumentationNode(val name: String,
get() = references(RefKind.Annotation).map { it.to }
val deprecation: DocumentationNode?
get() = references(RefKind.Deprecation).singleOrNull()?.to
- val sinceKotlin: DocumentationNode?
- get() = references(RefKind.SinceKotlin).singleOrNull()?.to
+ val platforms: List<String>
+ get() = references(RefKind.Platform).map { it.to.name }
// TODO: Should we allow node mutation? Model merge will copy by ref, so references are transparent, which could nice
fun addReferenceTo(to: DocumentationNode, kind: RefKind) {
diff --git a/core/src/main/kotlin/Model/DocumentationReference.kt b/core/src/main/kotlin/Model/DocumentationReference.kt
index 8263cd6a..4f28d7c3 100644
--- a/core/src/main/kotlin/Model/DocumentationReference.kt
+++ b/core/src/main/kotlin/Model/DocumentationReference.kt
@@ -19,7 +19,7 @@ enum class RefKind {
HiddenAnnotation,
Deprecation,
TopLevelPage,
- SinceKotlin
+ Platform
}
data class DocumentationReference(val from: DocumentationNode, val to: DocumentationNode, val kind: RefKind) {
@@ -71,3 +71,14 @@ class NodeReferenceGraph
references.forEach { it.resolve() }
}
}
+
+@Singleton
+class PlatformNodeRegistry {
+ private val platformNodes = hashMapOf<String, DocumentationNode>()
+
+ operator fun get(platform: String): DocumentationNode {
+ return platformNodes.getOrPut(platform) {
+ DocumentationNode(platform, Content.Empty, NodeKind.Platform)
+ }
+ }
+}