diff options
Diffstat (limited to 'plugins/base/src')
16 files changed, 415 insertions, 255 deletions
diff --git a/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt b/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt index 23e59f8b..e7a36d3f 100644 --- a/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt +++ b/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt @@ -162,6 +162,12 @@ open class MarkdownParser( return linksHandler(linkText, link, linkTitle) } + private fun markdownFileHandler(node: ASTNode) = + DocTagsFromIElementFactory.getInstance( + node.type, + children = node.children.evaluateChildren() + ) + private fun autoLinksHandler(node: ASTNode): DocTag { val link = text.substring(node.startOffset + 1, node.endOffset - 1) @@ -206,11 +212,6 @@ open class MarkdownParser( body = text.substring(node.startOffset, node.endOffset).transform() ) - private fun markdownFileHandler(node: ASTNode) = if (node.children.size == 1) - visitNode(node.children.first()) - else - defaultHandler(node) - private fun strikeThroughHandler(node: ASTNode) = DocTagsFromIElementFactory.getInstance( node.type, children = node.children.evaluateChildrenWithDroppedEnclosingTokens(2) @@ -448,9 +449,9 @@ open class MarkdownParser( KDocKnownTag.SEE -> See( parseStringToDocNode(it.getContent()), it.getSubjectName().orEmpty(), - parseStringToDocNode("[${it.getSubjectName()}]") + (parseStringToDocNode("[${it.getSubjectName()}]")) .let { - val link = it.children[0] + val link = it.children[0].children[0] if (link is DocumentationLink) link.dri else null } diff --git a/plugins/base/src/main/kotlin/parsers/Parser.kt b/plugins/base/src/main/kotlin/parsers/Parser.kt index 894fa82f..228cc88b 100644 --- a/plugins/base/src/main/kotlin/parsers/Parser.kt +++ b/plugins/base/src/main/kotlin/parsers/Parser.kt @@ -18,8 +18,15 @@ abstract class Parser { "author" -> Author(parseStringToDocNode(it.second)) "version" -> Version(parseStringToDocNode(it.second)) "since" -> Since(parseStringToDocNode(it.second)) - "see" -> See(parseStringToDocNode(it.second.substringAfter(' ')), it.second.substringBefore(' '), null) - "param" -> Param(parseStringToDocNode(it.second.substringAfter(' ')), it.second.substringBefore(' ')) + "see" -> See( + parseStringToDocNode(it.second.substringAfter(' ')), + it.second.substringBefore(' '), + null + ) + "param" -> Param( + parseStringToDocNode(it.second.substringAfter(' ')), + it.second.substringBefore(' ') + ) "property" -> Property( parseStringToDocNode(it.second.substringAfter(' ')), it.second.substringBefore(' ') @@ -32,7 +39,10 @@ abstract class Parser { it.second.substringBefore(' ') ) "deprecated" -> Deprecated(parseStringToDocNode(it.second)) - "sample" -> Sample(parseStringToDocNode(it.second.substringAfter(' ')), it.second.substringBefore(' ')) + "sample" -> Sample( + parseStringToDocNode(it.second.substringAfter(' ')), + it.second.substringBefore(' ') + ) "suppress" -> Suppress(parseStringToDocNode(it.second)) else -> CustomTagWrapper(parseStringToDocNode(it.second), it.first) } diff --git a/plugins/base/src/main/kotlin/parsers/factories/DocTagsFromIElementFactory.kt b/plugins/base/src/main/kotlin/parsers/factories/DocTagsFromIElementFactory.kt index 58b4b223..b714caec 100644 --- a/plugins/base/src/main/kotlin/parsers/factories/DocTagsFromIElementFactory.kt +++ b/plugins/base/src/main/kotlin/parsers/factories/DocTagsFromIElementFactory.kt @@ -40,6 +40,7 @@ object DocTagsFromIElementFactory { GFMElementTypes.HEADER -> Th(children, params) GFMElementTypes.ROW -> Tr(children, params) GFMTokenTypes.CELL -> Td(children, params) - else -> CustomDocTag(children, params) + MarkdownElementTypes.MARKDOWN_FILE -> CustomDocTag(children, params, MarkdownElementTypes.MARKDOWN_FILE.name) + else -> CustomDocTag(children, params, type.name) } } diff --git a/plugins/base/src/main/kotlin/parsers/factories/DocTagsFromStringFactory.kt b/plugins/base/src/main/kotlin/parsers/factories/DocTagsFromStringFactory.kt index 124dc3b4..1af4e719 100644 --- a/plugins/base/src/main/kotlin/parsers/factories/DocTagsFromStringFactory.kt +++ b/plugins/base/src/main/kotlin/parsers/factories/DocTagsFromStringFactory.kt @@ -72,6 +72,6 @@ object DocTagsFromStringFactory { "var" -> Var(children, params) "documentationlink" -> DocumentationLink(dri ?: throw NullPointerException("DRI cannot be passed null while constructing documentation link!"), children, params) "hr" -> HorizontalRule - else -> CustomDocTag(children, params) + else -> CustomDocTag(children, params, name) } -}
\ No newline at end of file +} diff --git a/plugins/base/src/main/kotlin/transformers/pages/annotations/SinceKotlinTransformer.kt b/plugins/base/src/main/kotlin/transformers/pages/annotations/SinceKotlinTransformer.kt index 7914e88f..acff5ada 100644 --- a/plugins/base/src/main/kotlin/transformers/pages/annotations/SinceKotlinTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/annotations/SinceKotlinTransformer.kt @@ -1,7 +1,9 @@ package org.jetbrains.dokka.base.transformers.pages.annotations +import org.intellij.markdown.MarkdownElementTypes import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.* +import org.jetbrains.dokka.model.doc.CustomDocTag import org.jetbrains.dokka.model.doc.CustomTagWrapper import org.jetbrains.dokka.model.doc.Text import org.jetbrains.dokka.model.properties.WithExtraProperties @@ -73,10 +75,19 @@ class SinceKotlinTransformer(val context: DokkaContext) : DocumentableTransforme acc.mapValues { if (it.key == sourceSet) it.value.copy( it.value.children + listOf( - CustomTagWrapper(Text(version.dropWhile { it == '"' }.dropLastWhile { it == '"' }), "Since Kotlin") + CustomTagWrapper( + CustomDocTag( + listOf( + Text(version.dropWhile { it == '"' }.dropLastWhile { it == '"' } + ) + ), + name = MarkdownElementTypes.MARKDOWN_FILE.name + ), + "Since Kotlin" + ) ) ) else it.value } } ?: acc } -}
\ No newline at end of file +} diff --git a/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt b/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt index 51ab0858..0fea6b4f 100644 --- a/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt @@ -1,5 +1,6 @@ package org.jetbrains.dokka.base.transformers.pages.comments +import org.intellij.markdown.MarkdownElementTypes import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet import org.jetbrains.dokka.model.doc.* import org.jetbrains.dokka.model.properties.PropertyContainer @@ -175,7 +176,24 @@ object DocTagToContentConverter : CommentsToContentConverter { styles ) ) + + is CustomDocTag -> if (docTag.isNonemptyFile()) { + listOf( + ContentGroup( + buildChildren(docTag), + dci, + sourceSets.toDisplaySourceSets(), + styles, + extra = extra + ) + ) + } else { + buildChildren(docTag) + } + else -> buildChildren(docTag) } } + + private fun CustomDocTag.isNonemptyFile() = name == MarkdownElementTypes.MARKDOWN_FILE.name && children.size > 1 } diff --git a/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt b/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt index b4663b20..905d1898 100644 --- a/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt +++ b/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt @@ -6,6 +6,7 @@ import com.intellij.psi.impl.source.tree.JavaDocElementType import com.intellij.psi.impl.source.tree.LeafPsiElement import com.intellij.psi.javadoc.* import com.intellij.psi.util.PsiTreeUtil +import org.intellij.markdown.MarkdownElementTypes import org.jetbrains.dokka.analysis.from import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.doc.* @@ -55,8 +56,11 @@ class JavadocParser( return DocumentationNode(nodes) } - private fun wrapTagIfNecessary(list: List<DocTag>): DocTag = - if (list.size == 1) list.first() else P(list) + private fun wrapTagIfNecessary(list: List<DocTag>): CustomDocTag = + if (list.size == 1 && (list.first() as? CustomDocTag)?.name == MarkdownElementTypes.MARKDOWN_FILE.name) + list.first() as CustomDocTag + else + CustomDocTag(list, name = MarkdownElementTypes.MARKDOWN_FILE.name) private fun findClosestDocComment(element: PsiNamedElement): PsiDocComment? { (element as? PsiDocCommentOwner)?.docComment?.run { return this } diff --git a/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt b/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt index 4f2bd8dc..1116dfa9 100644 --- a/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt +++ b/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt @@ -605,6 +605,6 @@ class ContentForParamsTest : AbstractCoreTest() { } private fun DocumentationNode.paramsDescription(): String = - children.firstIsInstanceOrNull<Param>()?.root?.children?.firstIsInstanceOrNull<Text>()?.body.orEmpty() + children.firstIsInstanceOrNull<Param>()?.root?.children?.first()?.children?.firstIsInstanceOrNull<Text>()?.body.orEmpty() } diff --git a/plugins/base/src/test/kotlin/content/seealso/ContentForSeeAlsoTest.kt b/plugins/base/src/test/kotlin/content/seealso/ContentForSeeAlsoTest.kt index fd51c895..aa9ac045 100644 --- a/plugins/base/src/test/kotlin/content/seealso/ContentForSeeAlsoTest.kt +++ b/plugins/base/src/test/kotlin/content/seealso/ContentForSeeAlsoTest.kt @@ -89,7 +89,7 @@ class ContentForSeeAlsoTest : AbstractCoreTest() { group { //DRI should be "test//abc/#/-1/" link { +"abc" } - group { group { } } + group { } } } } @@ -201,9 +201,7 @@ class ContentForSeeAlsoTest : AbstractCoreTest() { group { //DRI should be "kotlin.collections/Collection////" link { +"Collection" } - group { - group { } - } + group { } } } } diff --git a/plugins/base/src/test/kotlin/markdown/ParserTest.kt b/plugins/base/src/test/kotlin/markdown/ParserTest.kt index c25678d4..0fdb10c1 100644 --- a/plugins/base/src/test/kotlin/markdown/ParserTest.kt +++ b/plugins/base/src/test/kotlin/markdown/ParserTest.kt @@ -1,6 +1,7 @@ package org.jetbrains.dokka.tests import markdown.KDocTest +import org.intellij.markdown.MarkdownElementTypes import org.jetbrains.dokka.model.doc.* import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test @@ -17,7 +18,10 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P(listOf(Text("This is simple test of string Next line"))) + CustomDocTag( + listOf(P(listOf(Text("This is simple test of string Next line")))), + name = MarkdownElementTypes.MARKDOWN_FILE.name + ) ) ) ) @@ -33,12 +37,17 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( - Text("This is simple test of string"), - Br, - Text("Next line") - ) + P( + listOf( + Text("This is simple test of string"), + Br, + Text("Next line") + ) + ) + ), + name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -55,15 +64,19 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( - Text("This is "), - B(listOf(Text("simple"))), - Text(" test of "), - I(listOf(Text("string"))), - Text(" Next "), - B(listOf(I(listOf(Text("line"))))) - ) + P( + listOf( + Text("This is "), + B(listOf(Text("simple"))), + Text(" test of "), + I(listOf(Text("string"))), + Text(" Next "), + B(listOf(I(listOf(Text("line"))))) + ) + ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -79,7 +92,10 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P(listOf(Text("This is simple text with: colon!"))) + CustomDocTag( + listOf(P(listOf(Text("This is simple text with: colon!")))), + name = MarkdownElementTypes.MARKDOWN_FILE.name + ) ) ) ) @@ -96,7 +112,10 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P(listOf(Text("Text and String"))) + CustomDocTag( + listOf(P(listOf(Text("Text and String")))), + name = MarkdownElementTypes.MARKDOWN_FILE.name + ) ) ) ) @@ -115,11 +134,11 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( P(listOf(Text("Paragraph number one"))), P(listOf(Text("Paragraph"), Br, Text("number two"))) - ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -133,7 +152,10 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P(listOf(I(listOf(Text("text"))))) + CustomDocTag( + listOf(P(listOf(I(listOf(Text("text")))))), + name = MarkdownElementTypes.MARKDOWN_FILE.name + ) ) ) ) @@ -146,7 +168,10 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P(listOf(Text("text_with_underscores"))) + CustomDocTag( + listOf(P(listOf(Text("text_with_underscores")))), + name = MarkdownElementTypes.MARKDOWN_FILE.name + ) ) ) ) @@ -159,7 +184,10 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P(listOf(I(listOf(Text("text"))))) + CustomDocTag( + listOf(P(listOf(I(listOf(Text("text")))))), + name = MarkdownElementTypes.MARKDOWN_FILE.name + ) ) ) ) @@ -169,20 +197,25 @@ class ParserTest : KDocTest() { @Test fun `Stars as italic bounds`() { val kdoc = "The abstract syntax tree node for a multiplying expression. A multiplying\n" + - "expression is a binary expression where the operator is a multiplying operator\n" + - "such as \"*\", \"/\", or \"mod\". A simple example would be \"5*x\"." + "expression is a binary expression where the operator is a multiplying operator\n" + + "such as \"*\", \"/\", or \"mod\". A simple example would be \"5*x\"." val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( - Text("The abstract syntax tree node for a multiplying expression. A multiplying " + - "expression is a binary expression where the operator is a multiplying operator " + - "such as \"" - ), - I(listOf(Text("\", \"/\", or \"mod\". A simple example would be \"5"))), - Text("x\".") - ) + P( + listOf( + Text( + "The abstract syntax tree node for a multiplying expression. A multiplying " + + "expression is a binary expression where the operator is a multiplying operator " + + "such as \"" + ), + I(listOf(Text("\", \"/\", or \"mod\". A simple example would be \"5"))), + Text("x\".") + ) + ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -198,15 +231,20 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( - Text("The abstract syntax tree node for a multiplying expression. A multiplying " + - "expression is a binary expression where the operator is a multiplying operator " + - "such as \"" - ), - B(listOf(Text("\", \"/\", or \"mod\". A simple example would be \"5"))), - Text("x\".") - ) + P( + listOf( + Text( + "The abstract syntax tree node for a multiplying expression. A multiplying " + + "expression is a binary expression where the operator is a multiplying operator " + + "such as \"" + ), + B(listOf(Text("\", \"/\", or \"mod\". A simple example would be \"5"))), + Text("x\".") + ) + ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -220,7 +258,11 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P(listOf(Text("Embedded*Star"))) + CustomDocTag( + listOf( + P(listOf(Text("Embedded*Star"))) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name + ) ) ) ) @@ -237,11 +279,15 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - Ul( + CustomDocTag( listOf( - Li(listOf(P(listOf(Text("list item 1"))))), - Li(listOf(P(listOf(Text("list item 2"))))) - ) + Ul( + listOf( + Li(listOf(P(listOf(Text("list item 1"))))), + Li(listOf(P(listOf(Text("list item 2"))))) + ) + ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -260,11 +306,15 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - Ul( + CustomDocTag( listOf( - Li(listOf(P(listOf(Text("list item 1 continue 1"))))), - Li(listOf(P(listOf(Text("list item 2"), Br, Text("continue 2"))))) - ) + Ul( + listOf( + Li(listOf(P(listOf(Text("list item 1 continue 1"))))), + Li(listOf(P(listOf(Text("list item 2"), Br, Text("continue 2"))))) + ) + ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -283,31 +333,35 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - Ul( + CustomDocTag( listOf( - Li( + Ul( listOf( - P( + Li( listOf( - Text("list "), - B(listOf(Text("item"))), - Text(" 1 continue 1") + P( + listOf( + Text("list "), + B(listOf(Text("item"))), + Text(" 1 continue 1") + ) + ) ) - ) - ) - ), - Li( - listOf( - P( + ), + Li( listOf( - Text("list "), - B(listOf(Text("item"))), - Text(" 2 continue 2") + P( + listOf( + Text("list "), + B(listOf(Text("item"))), + Text(" 2 continue 2") + ) + ) ) ) ) ) - ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -333,7 +387,7 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( Ul( listOf( @@ -355,7 +409,7 @@ class ParserTest : KDocTest() { ) ), P(listOf(Text("New paragraph"))) - ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -372,12 +426,16 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - Ol( + CustomDocTag( listOf( - Li(listOf(P(listOf(Text("list item 1"))))), - Li(listOf(P(listOf(Text("list item 2"))))) - ), - mapOf("start" to "1") + Ol( + listOf( + Li(listOf(P(listOf(Text("list item 1"))))), + Li(listOf(P(listOf(Text("list item 2"))))) + ), + mapOf("start" to "1") + ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -395,12 +453,16 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - Ol( + CustomDocTag( listOf( - Li(listOf(P(listOf(Text("list item 1"))))), - Li(listOf(P(listOf(Text("list item 2"))))) - ), - mapOf("start" to "9") + Ol( + listOf( + Li(listOf(P(listOf(Text("list item 1"))))), + Li(listOf(P(listOf(Text("list item 2"))))) + ), + mapOf("start" to "9") + ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -419,12 +481,16 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - Ol( + CustomDocTag( listOf( - Li(listOf(P(listOf(Text("list item 1 continue 1"))))), - Li(listOf(P(listOf(Text("list item 2 continue 2"))))) - ), - mapOf("start" to "2") + Ol( + listOf( + Li(listOf(P(listOf(Text("list item 1 continue 1"))))), + Li(listOf(P(listOf(Text("list item 2 continue 2"))))) + ), + mapOf("start" to "2") + ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -443,32 +509,36 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - Ol( + CustomDocTag( listOf( - Li( + Ol( listOf( - P( + Li( listOf( - Text("list "), - B(listOf(Text("item"))), - Text(" 1 continue 1") + P( + listOf( + Text("list "), + B(listOf(Text("item"))), + Text(" 1 continue 1") + ) + ) ) - ) - ) - ), - Li( - listOf( - P( + ), + Li( listOf( - Text("list "), - B(listOf(Text("item"))), - Text(" 2 continue 2") + P( + listOf( + Text("list "), + B(listOf(Text("item"))), + Text(" 2 continue 2") + ) + ) ) ) - ) + ), + mapOf("start" to "1") ) - ), - mapOf("start" to "1") + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -494,7 +564,7 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( Ol( listOf( @@ -519,7 +589,7 @@ class ParserTest : KDocTest() { mapOf("start" to "1") ), P(listOf(Text("New paragraph"))) - ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -545,7 +615,7 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( Ol( listOf( @@ -569,7 +639,7 @@ class ParserTest : KDocTest() { mapOf("start" to "1") ), P(listOf(Text("New paragraph"))) - ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -588,12 +658,12 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( H1(listOf(Text("Header 1"))), P(listOf(Text("Following text"))), P(listOf(Text("New paragraph"))) - ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -621,7 +691,7 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( H1(listOf(Text("Header 1"))), P(listOf(Text("Text 1"))), @@ -635,7 +705,7 @@ class ParserTest : KDocTest() { P(listOf(Text("Text 5"))), H6(listOf(Text("Header 6"))), P(listOf(Text("Text 6"))) - ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -652,12 +722,16 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( - B(listOf(Text("line 1"))), - Br, - B(listOf(Text("line 2"))) - ) + P( + listOf( + B(listOf(Text("line 1"))), + Br, + B(listOf(Text("line 2"))) + ) + ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -681,7 +755,7 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( HorizontalRule, P(listOf(Text("text 1"))), @@ -692,7 +766,7 @@ class ParserTest : KDocTest() { HorizontalRule, P(listOf(Text("text 4"))), HorizontalRule - ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -713,7 +787,7 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( BlockQuote( listOf( @@ -730,7 +804,7 @@ class ParserTest : KDocTest() { P(listOf(Text("Quote"))) ) ) - ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -756,7 +830,7 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( BlockQuote( listOf( @@ -775,7 +849,7 @@ class ParserTest : KDocTest() { P(listOf(Text("Quote"))) ) ) - ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -802,7 +876,7 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( BlockQuote( listOf( @@ -837,7 +911,7 @@ class ParserTest : KDocTest() { P(listOf(Text("Quote"))) ) ) - ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -854,11 +928,15 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( - CodeInline(listOf(Text("Some code"))), - Text(" Sample text") - ) + P( + listOf( + CodeInline(listOf(Text("Some code"))), + Text(" Sample text") + ) + ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -883,7 +961,7 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( CodeBlock( listOf( @@ -897,7 +975,7 @@ class ParserTest : KDocTest() { mapOf("lang" to "kotlin") ), P(listOf(Text("Sample text"))) - ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -914,13 +992,17 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( - A( - listOf(Text("I'm an inline-style link")), - mapOf("href" to "https://www.google.com") + P( + listOf( + A( + listOf(Text("I'm an inline-style link")), + mapOf("href" to "https://www.google.com") + ) + ) ) - ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -936,13 +1018,17 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( - A( - listOf(Text("I'm an inline-style link with title")), - mapOf("href" to "https://www.google.com", "title" to "Google's Homepage") + P( + listOf( + A( + listOf(Text("I'm an inline-style link with title")), + mapOf("href" to "https://www.google.com", "title" to "Google's Homepage") + ) + ) ) - ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -960,7 +1046,7 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( P( listOf( @@ -970,7 +1056,7 @@ class ParserTest : KDocTest() { ) ) ) - ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -988,7 +1074,7 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( P( listOf( @@ -998,7 +1084,7 @@ class ParserTest : KDocTest() { ) ) ) - ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -1016,7 +1102,7 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( P( listOf( @@ -1028,7 +1114,7 @@ class ParserTest : KDocTest() { Text(".") ) ) - ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -1046,15 +1132,19 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( - Text("URLs and URLs in angle brackets will automatically get turned into links. http://www.example.com or "), - A( - listOf(Text("http://www.example.com")), - mapOf("href" to "http://www.example.com") - ), - Text(" and sometimes example.com (but not on Github, for example).") - ) + P( + listOf( + Text("URLs and URLs in angle brackets will automatically get turned into links. http://www.example.com or "), + A( + listOf(Text("http://www.example.com")), + mapOf("href" to "http://www.example.com") + ), + Text(" and sometimes example.com (but not on Github, for example).") + ) + ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -1088,7 +1178,7 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( P( listOf( @@ -1143,7 +1233,7 @@ class ParserTest : KDocTest() { ) ), P(listOf(Text("Some text to show that the reference links can follow later."))) - ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -1157,10 +1247,14 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( - Text("text text") - ) + P( + listOf( + Text("text text") + ) + ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -1174,16 +1268,20 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( - Img( - emptyList(), - mapOf( - "href" to "https://www.google.pl/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png", - "alt" to "Sample image" + P( + listOf( + Img( + emptyList(), + mapOf( + "href" to "https://www.google.pl/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png", + "alt" to "Sample image" + ) + ) ) ) - ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -1198,15 +1296,19 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( - Text("It's very easy to make some words "), - B(listOf(Text("bold"))), - Text(" and other words "), - I(listOf(Text("italic"))), - Text(" with Markdown. You can even "), - A(listOf(Text("link to Google!")), mapOf("href" to "http://google.com")) - ) + P( + listOf( + Text("It's very easy to make some words "), + B(listOf(Text("bold"))), + Text(" and other words "), + I(listOf(Text("italic"))), + Text(" with Markdown. You can even "), + A(listOf(Text("link to Google!")), mapOf("href" to "http://google.com")) + ) + ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -1225,7 +1327,7 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( P(listOf(Text("Here is some example how to use conditional instructions:"))), CodeBlock( @@ -1239,7 +1341,7 @@ class ParserTest : KDocTest() { ) ) ) - ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -1256,51 +1358,55 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - Table( + CustomDocTag( listOf( - Th( + Table( listOf( - Td( + Th( listOf( - Text("First Header") - ) - ), - Td( - listOf( - Text("Second Header") - ) - ) - ) - ), - Tr( - listOf( - Td( - listOf( - Text("Content from cell 1") + Td( + listOf( + Text("First Header") + ) + ), + Td( + listOf( + Text("Second Header") + ) + ) ) ), - Td( - listOf( - Text("Content from cell 2") - ) - ) - ) - ), - Tr( - listOf( - Td( + Tr( listOf( - Text("Content in the first column") + Td( + listOf( + Text("Content from cell 1") + ) + ), + Td( + listOf( + Text("Content from cell 2") + ) + ) ) ), - Td( + Tr( listOf( - Text("Content in the second column") + Td( + listOf( + Text("Content in the first column") + ) + ), + Td( + listOf( + Text("Content in the second column") + ) + ) ) ) ) ) - ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -1316,11 +1422,15 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( - Text("This is "), - Strikethrough(listOf(Text("strikethroughed"))) - ) + P( + listOf( + Text("This is "), + Strikethrough(listOf(Text("strikethroughed"))) + ) + ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) diff --git a/plugins/base/src/test/kotlin/model/CommentTest.kt b/plugins/base/src/test/kotlin/model/CommentTest.kt index c1da8ee0..613576ae 100644 --- a/plugins/base/src/test/kotlin/model/CommentTest.kt +++ b/plugins/base/src/test/kotlin/model/CommentTest.kt @@ -30,16 +30,21 @@ class CommentTest : AbstractModelTest("/src/main/kotlin/comment/Test.kt", "comme ) { with((this / "comment" / "prop1").cast<DProperty>()) { name equals "prop1" - with(this.docs().firstOrNull()?.root.assertNotNull("Code")) { - (children.firstOrNull() as? Text) + with(this.docs().firstOrNull()?.children?.firstOrNull()?.assertNotNull("Code")) { + (this?.children?.firstOrNull() as? Text) ?.body equals "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>." - params["lang"] equals "brainfuck" + this?.params?.get("lang") equals "brainfuck" } } with((this / "comment" / "prop2").cast<DProperty>()) { name equals "prop2" - comments() equals "a + b - c" + with(this.docs().firstOrNull()?.children?.firstOrNull()?.assertNotNull("Code")) { + (this?.children?.firstOrNull() as? Text) + ?.body equals "a + b - c" + + this?.params?.get("lang") equals null + } } } } @@ -88,7 +93,7 @@ class CommentTest : AbstractModelTest("/src/main/kotlin/comment/Test.kt", "comme """ ) { with((this / "comment" / "property").cast<DProperty>()) { - comments() equals "doc1\ndoc2 doc3" + comments() equals "doc1\ndoc2 doc3\n" } } } @@ -108,7 +113,7 @@ class CommentTest : AbstractModelTest("/src/main/kotlin/comment/Test.kt", "comme """ ) { with((this / "comment" / "property").cast<DProperty>()) { - comments() equals "doc1\ndoc2 doc3" + comments() equals "doc1\ndoc2 doc3\n" } } } @@ -122,7 +127,7 @@ class CommentTest : AbstractModelTest("/src/main/kotlin/comment/Test.kt", "comme """ ) { with((this / "comment" / "property").cast<DProperty>()) { - comments() equals "doc" + comments() equals "doc\n" } } } @@ -137,7 +142,7 @@ class CommentTest : AbstractModelTest("/src/main/kotlin/comment/Test.kt", "comme """ ) { with((this / "comment" / "property").cast<DProperty>()) { - comments() equals "doc" + comments() equals "doc\n" } } } @@ -152,7 +157,7 @@ class CommentTest : AbstractModelTest("/src/main/kotlin/comment/Test.kt", "comme """ ) { with((this / "comment" / "property").cast<DProperty>()) { - comments() equals "doc" + comments() equals "doc\n" } } } @@ -169,7 +174,7 @@ class CommentTest : AbstractModelTest("/src/main/kotlin/comment/Test.kt", "comme """ ) { with((this / "comment" / "property").cast<DProperty>()) { - comments() equals "Summary\none: []" + comments() equals "Summary\n\none: []" docs().find { it is CustomTagWrapper && it.name == "one" }.let { with(it.assertNotNull("'one' entry")) { root.children counts 0 @@ -189,7 +194,8 @@ class CommentTest : AbstractModelTest("/src/main/kotlin/comment/Test.kt", "comme """ ) { with((this / "comment" / "property").cast<DProperty>()) { - comments() equals """it's "useful"""" + comments() equals """it's "useful" +""" } } } @@ -206,7 +212,7 @@ class CommentTest : AbstractModelTest("/src/main/kotlin/comment/Test.kt", "comme """ ) { with((this / "comment" / "property").cast<DProperty>()) { - comments() equals "Summary\none: [section one]" + comments() equals "Summary\n\none: [section one\n]" } } } @@ -225,7 +231,7 @@ class CommentTest : AbstractModelTest("/src/main/kotlin/comment/Test.kt", "comme """ ) { with((this / "comment" / "property").cast<DProperty>()) { - comments() equals "Summary\none: [section one]\ntwo: [section two]" + comments() equals "Summary\n\none: [section one\n]\ntwo: [section two\n]" } } } @@ -244,7 +250,7 @@ class CommentTest : AbstractModelTest("/src/main/kotlin/comment/Test.kt", "comme """ ) { with((this / "comment" / "property").cast<DProperty>()) { - comments() equals "Summary\none: [line one line two]" + comments() equals "Summary\n\none: [line one line two\n]" } } } @@ -329,4 +335,4 @@ class CommentTest : AbstractModelTest("/src/main/kotlin/comment/Test.kt", "comme // } // } -}
\ No newline at end of file +} diff --git a/plugins/base/src/test/kotlin/model/FunctionsTest.kt b/plugins/base/src/test/kotlin/model/FunctionsTest.kt index c96e7df6..9fffb4fc 100644 --- a/plugins/base/src/test/kotlin/model/FunctionsTest.kt +++ b/plugins/base/src/test/kotlin/model/FunctionsTest.kt @@ -118,14 +118,14 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun """ ) { with((this / "function" / "function").cast<DFunction>()) { - comments() equals "Multiline\nFunction Documentation" + comments() equals "Multiline\nFunction Documentation\n" name equals "function" parameters counts 1 parameters.firstOrNull().assertNotNull("Parameter: ").also { it.name equals "x" it.type.name equals "Int" - it.comments() equals "parameter" + it.comments() equals "parameter\n" } type.assertNotNull("Return type: ").name equals "Unit" @@ -393,4 +393,4 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun } } -}
\ No newline at end of file +} diff --git a/plugins/base/src/test/kotlin/model/JavaTest.kt b/plugins/base/src/test/kotlin/model/JavaTest.kt index 4e9b9de4..51d7556c 100644 --- a/plugins/base/src/test/kotlin/model/JavaTest.kt +++ b/plugins/base/src/test/kotlin/model/JavaTest.kt @@ -34,7 +34,7 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { with((this / "fn").cast<DFunction>()) { name equals "fn" val params = parameters.map { it.documentation.values.first().children.first() as Param } - params.mapNotNull { it.firstChildOfTypeOrNull<Text>()?.body } equals listOf("is String parameter", "is int parameter") + params.mapNotNull { it.firstMemberOfType<Text>()?.body } equals listOf("is String parameter", "is int parameter") } } } diff --git a/plugins/base/src/test/kotlin/translators/JavadocParserTest.kt b/plugins/base/src/test/kotlin/translators/JavadocParserTest.kt index 0cd0a151..762c2e27 100644 --- a/plugins/base/src/test/kotlin/translators/JavadocParserTest.kt +++ b/plugins/base/src/test/kotlin/translators/JavadocParserTest.kt @@ -5,6 +5,7 @@ import org.jetbrains.dokka.model.DModule import org.jetbrains.dokka.model.childrenOfType import org.jetbrains.dokka.model.doc.* import org.jetbrains.dokka.model.firstChildOfType +import org.jetbrains.dokka.model.firstMemberOfType import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest import org.junit.jupiter.api.Test import org.junit.jupiter.api.Assertions.* @@ -144,9 +145,9 @@ class JavadocParserTest : AbstractCoreTest() { performJavadocTest { module -> val authors = module.findClasslike().documentation.values.single().childrenOfType<Author>() assertEquals(3, authors.size) - assertEquals("James Gosling", authors[0].firstChildOfType<Text>().text()) - assertEquals("Arthur van Hoff", authors[1].firstChildOfType<Text>().text()) - assertEquals("Alan Liu", authors[2].firstChildOfType<Text>().text()) + assertEquals("James Gosling", authors[0].firstMemberOfType<Text>().text()) + assertEquals("Arthur van Hoff", authors[1].firstMemberOfType<Text>().text()) + assertEquals("Alan Liu", authors[2].firstMemberOfType<Text>().text()) } } diff --git a/plugins/base/src/test/kotlin/translators/utils.kt b/plugins/base/src/test/kotlin/translators/utils.kt index cbb6efa7..f0522ade 100644 --- a/plugins/base/src/test/kotlin/translators/utils.kt +++ b/plugins/base/src/test/kotlin/translators/utils.kt @@ -7,7 +7,7 @@ import java.util.NoSuchElementException fun DModule.documentationOf(className: String, functionName: String? = null): String = descriptionOf(className, functionName) - ?.firstChildOfType<Text>() + ?.firstMemberOfType<Text>() ?.body.orEmpty() fun DModule.descriptionOf(className: String, functionName: String? = null): Description? { diff --git a/plugins/base/src/test/kotlin/utils/TestUtils.kt b/plugins/base/src/test/kotlin/utils/TestUtils.kt index 2ef6534e..f1585b40 100644 --- a/plugins/base/src/test/kotlin/utils/TestUtils.kt +++ b/plugins/base/src/test/kotlin/utils/TestUtils.kt @@ -52,8 +52,8 @@ fun TagWrapper.text(): String = when (val t = this) { fun DocTag.text(): String = when (val t = this) { is Text -> t.body is Code -> t.children.joinToString("\n") { it.text() } - is P -> t.children.joinToString(separator = "\n") { it.text() } - else -> t.toString() + is P -> t.children.joinToString("") { it.text() } + "\n" + else -> t.children.joinToString("") { it.text() } } fun <T : Documentable> T?.comments(): String = docs().map { it.text() } |