From eed6dd88004992da4c3545b756c23b4e62e54043 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Kongstad?= Date: Mon, 5 Dec 2022 14:55:41 +0100 Subject: Add support for "Added in " Teach Dokka to parse @sdkExtSince javadoc comments. These comments are equivalent to @apiSince, but for SDK extensions. Because symbols can be finalized in an Android dessert (@apiSince), an SDK extensions (@sdkExtSince) or both (@apiSince + @sdkExtSince), Dokka will emit one of the following snippets: - Added in API level - Added in - Added in API level Also in Bug: 261168446 Test: m ds-docs-kt # and manually inspect out/target/common/docs/ds-docs-kt-docs.zip Change-Id: Ia207d1284cda84ae612a955edfc67aecc75ac462 --- .../JavaLayoutHtml/JavaLayoutHtmlFormatOutputBuilder.kt | 16 ++++++++++++++-- core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt | 5 ++++- core/src/main/kotlin/Java/JavadocParser.kt | 15 ++++++++++++++- .../main/kotlin/Kotlin/DescriptorDocumentationParser.kt | 6 ++++++ core/src/main/kotlin/Model/DocumentationNode.kt | 3 +++ 5 files changed, 41 insertions(+), 4 deletions(-) diff --git a/core/src/main/kotlin/Formats/JavaLayoutHtml/JavaLayoutHtmlFormatOutputBuilder.kt b/core/src/main/kotlin/Formats/JavaLayoutHtml/JavaLayoutHtmlFormatOutputBuilder.kt index 2711a2df9..38921608b 100644 --- a/core/src/main/kotlin/Formats/JavaLayoutHtml/JavaLayoutHtmlFormatOutputBuilder.kt +++ b/core/src/main/kotlin/Formats/JavaLayoutHtml/JavaLayoutHtmlFormatOutputBuilder.kt @@ -857,19 +857,31 @@ open class JavaLayoutHtmlFormatOutputBuilder( protected open fun FlowContent.apiAndDeprecatedVersions(node: DocumentationNode) { val apiLevelExists = node.apiLevel.name.isNotEmpty() + val sdkExtSinceExists = node.sdkExtSince.name.isNotEmpty() val deprecatedLevelExists = node.deprecatedLevel.name.isNotEmpty() - if (apiLevelExists || deprecatedLevelExists) { + if (apiLevelExists || sdkExtSinceExists || deprecatedLevelExists) { div(classes = "api-level") { if (apiLevelExists) { +"Added in " a(href = "https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels") { +"API level ${node.apiLevel.name}" } - if (deprecatedLevelExists) { + } + if (sdkExtSinceExists) { + if (apiLevelExists) { br + +"Also in " + } else { + +"Added in " + } + a(href = "https://developer.android.com/sdkExtensions") { + +"${node.sdkExtSince.name}" } } if (deprecatedLevelExists) { + if (apiLevelExists || sdkExtSinceExists) { + br + } +"Deprecated in " a(href = "https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels") { +"API level ${node.deprecatedLevel.name}" diff --git a/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt b/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt index a7df4e482..94bb0455d 100644 --- a/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt +++ b/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt @@ -112,7 +112,7 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder { fun nodeForElement(element: PsiNamedElement, kind: NodeKind, name: String = element.name ?: ""): DocumentationNode { - val (docComment, deprecatedContent, attrs, apiLevel, deprecatedLevel, artifactId, attribute) = docParser.parseDocumentation(element) + val (docComment, deprecatedContent, attrs, apiLevel, sdkExtSince, deprecatedLevel, artifactId, attribute) = docParser.parseDocumentation(element) val node = DocumentationNode(name, docComment, kind) if (element is PsiModifierListOwner) { node.appendModifiers(element) @@ -140,6 +140,9 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder { apiLevel?.let { node.append(it, RefKind.Detail) } + sdkExtSince?.let { + node.append(it, RefKind.Detail) + } deprecatedLevel?.let { node.append(it, RefKind.Detail) } diff --git a/core/src/main/kotlin/Java/JavadocParser.kt b/core/src/main/kotlin/Java/JavadocParser.kt index 21cc2bbdf..0c73e7661 100644 --- a/core/src/main/kotlin/Java/JavadocParser.kt +++ b/core/src/main/kotlin/Java/JavadocParser.kt @@ -25,6 +25,7 @@ data class JavadocParseResult( val deprecatedContent: Content?, val attributeRefs: List, val apiLevel: DocumentationNode? = null, + val sdkExtSince: DocumentationNode? = null, val deprecatedLevel: DocumentationNode? = null, val artifactId: DocumentationNode? = null, val attribute: DocumentationNode? = null @@ -35,6 +36,7 @@ data class JavadocParseResult( emptyList(), null, null, + null, null ) } @@ -109,6 +111,7 @@ class JavadocParser( val attrRefSignatures = mutableListOf() var since: DocumentationNode? = null + var sdkextsince: DocumentationNode? = null var deprecated: DocumentationNode? = null var artifactId: DocumentationNode? = null var attrName: String? = null @@ -135,6 +138,9 @@ class JavadocParser( "since", "apisince" -> { since = DocumentationNode(tag.getApiLevel() ?: "", Content.Empty, NodeKind.ApiLevel) } + "sdkextsince" -> { + sdkextsince = DocumentationNode(tag.getSdkExtSince() ?: "", Content.Empty, NodeKind.SdkExtSince) + } "deprecatedsince" -> { deprecated = DocumentationNode(tag.getApiLevel() ?: "", Content.Empty, NodeKind.DeprecatedLevel) } @@ -153,7 +159,7 @@ class JavadocParser( attrName?.let { name -> attr = DocumentationNode(name, attrDesc ?: Content.Empty, NodeKind.AttributeRef) } - return JavadocParseResult(result, deprecatedContent, attrRefSignatures, since, deprecated, artifactId, attr) + return JavadocParseResult(result, deprecatedContent, attrRefSignatures, since, sdkextsince, deprecated, artifactId, attr) } private val tagsToInherit = setOf("param", "return", "throws") @@ -182,6 +188,13 @@ class JavadocParser( return null } + fun PsiDocTag.getSdkExtSince(): String? { + if (dataElements.isNotEmpty()) { + return join(dataElements.map { it.text }, " ") + } + return null + } + private fun PsiDocTag.getAttrRef(element: PsiNamedElement): String? { if (dataElements.size > 1) { val elementText = dataElements[1].text diff --git a/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt b/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt index 6841503fc..098a17f97 100644 --- a/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt +++ b/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt @@ -142,6 +142,9 @@ class DescriptorDocumentationParser @Inject constructor( } else if (name?.toLowerCase() == "since" || name?.toLowerCase() == "apisince") { val apiLevel = DocumentationNode(it.getContent(), Content.Empty, NodeKind.ApiLevel) append(apiLevel, RefKind.Detail) + } else if (name?.toLowerCase() == "sdkextsince") { + val sdkExtSince = DocumentationNode(it.getContent(), Content.Empty, NodeKind.SdkExtSince) + append(sdkExtSince, RefKind.Detail) } else if (name?.toLowerCase() == "deprecatedsince") { val deprecatedLevel = DocumentationNode(it.getContent(), Content.Empty, NodeKind.DeprecatedLevel) append(deprecatedLevel, RefKind.Detail) @@ -223,6 +226,9 @@ class DescriptorDocumentationParser @Inject constructor( parseResult.apiLevel?.let { node.append(it, RefKind.Detail) } + parseResult.sdkExtSince?.let { + node.append(it, RefKind.Detail) + } parseResult.deprecatedLevel?.let { node.append(it, RefKind.Detail) } diff --git a/core/src/main/kotlin/Model/DocumentationNode.kt b/core/src/main/kotlin/Model/DocumentationNode.kt index c84d4169d..7ac6d8f4a 100644 --- a/core/src/main/kotlin/Model/DocumentationNode.kt +++ b/core/src/main/kotlin/Model/DocumentationNode.kt @@ -64,6 +64,7 @@ enum class NodeKind { AttributeRef, ApiLevel, + SdkExtSince, DeprecatedLevel, @@ -120,6 +121,8 @@ open class DocumentationNode(val name: String, get() = references(RefKind.ExternalType).map { it.to }.firstOrNull() val apiLevel: DocumentationNode get() = detailOrNull(NodeKind.ApiLevel) ?: DocumentationNode("", Content.Empty, NodeKind.ApiLevel) + val sdkExtSince: DocumentationNode + get() = detailOrNull(NodeKind.SdkExtSince) ?: DocumentationNode("", Content.Empty, NodeKind.SdkExtSince) val deprecatedLevel: DocumentationNode get() = detailOrNull(NodeKind.DeprecatedLevel) ?: DocumentationNode("", Content.Empty, NodeKind.DeprecatedLevel) val artifactId: DocumentationNode -- cgit v1.2.3