Ilya Ryzhenkov | 62cb509 | 2014-07-15 15:54:05 +0400 | [diff] [blame] | 1 | package org.jetbrains.dokka |
| 2 | |
| 3 | import java.util.LinkedHashMap |
Dmitry Jemerov | 0c584d0 | 2015-01-12 17:23:07 +0100 | [diff] [blame] | 4 | import org.jetbrains.dokka.LanguageService.RenderMode |
Ilya Ryzhenkov | 62cb509 | 2014-07-15 15:54:05 +0400 | [diff] [blame] | 5 | |
Dmitry Jemerov | d9bfa02 | 2015-02-19 18:59:00 +0100 | [diff] [blame] | 6 | public data class FormatLink(val text: String, val href: String) |
Ilya Ryzhenkov | 62cb509 | 2014-07-15 15:54:05 +0400 | [diff] [blame] | 7 | |
Dmitry Jemerov | 6659337 | 2015-03-03 19:35:56 +0100 | [diff] [blame^] | 8 | enum class ListKind { |
| 9 | Ordered |
| 10 | Unordered |
| 11 | } |
| 12 | |
Dmitry Jemerov | ea1f4cc | 2015-02-19 19:51:01 +0100 | [diff] [blame] | 13 | public abstract class StructuredFormatService(locationService: LocationService, |
| 14 | val languageService: LanguageService, |
| 15 | override val extension: String) : FormatService { |
| 16 | val locationService: LocationService = locationService.withExtension(extension) |
Ilya Ryzhenkov | 62cb509 | 2014-07-15 15:54:05 +0400 | [diff] [blame] | 17 | |
Dmitry Jemerov | 44cef5c | 2015-02-26 19:34:49 +0100 | [diff] [blame] | 18 | abstract public fun appendBlockCode(to: StringBuilder, line: String, language: String) |
Ilya Ryzhenkov | 62cb509 | 2014-07-15 15:54:05 +0400 | [diff] [blame] | 19 | abstract public fun appendHeader(to: StringBuilder, text: String, level: Int = 1) |
Dmitry Jemerov | 8ef6818 | 2014-12-30 12:36:14 +0100 | [diff] [blame] | 20 | abstract public fun appendParagraph(to: StringBuilder, text: String) |
Ilya Ryzhenkov | 62cb509 | 2014-07-15 15:54:05 +0400 | [diff] [blame] | 21 | abstract public fun appendLine(to: StringBuilder, text: String) |
| 22 | public abstract fun appendLine(to: StringBuilder) |
Dmitry Jemerov | 85a3ae7 | 2015-02-20 14:08:30 +0100 | [diff] [blame] | 23 | public abstract fun appendAnchor(to: StringBuilder, anchor: String) |
Ilya Ryzhenkov | 499d082 | 2014-07-15 16:18:53 +0400 | [diff] [blame] | 24 | |
Ilya Ryzhenkov | aa59acb | 2014-07-15 20:05:55 +0400 | [diff] [blame] | 25 | public abstract fun appendTable(to: StringBuilder, body: () -> Unit) |
| 26 | public abstract fun appendTableHeader(to: StringBuilder, body: () -> Unit) |
| 27 | public abstract fun appendTableBody(to: StringBuilder, body: () -> Unit) |
| 28 | public abstract fun appendTableRow(to: StringBuilder, body: () -> Unit) |
| 29 | public abstract fun appendTableCell(to: StringBuilder, body: () -> Unit) |
Ilya Ryzhenkov | 499d082 | 2014-07-15 16:18:53 +0400 | [diff] [blame] | 30 | |
Ilya Ryzhenkov | aa59acb | 2014-07-15 20:05:55 +0400 | [diff] [blame] | 31 | public abstract fun formatText(text: String): String |
Ilya Ryzhenkov | 7c6da4b | 2014-10-03 19:09:31 +0400 | [diff] [blame] | 32 | public abstract fun formatSymbol(text: String): String |
| 33 | public abstract fun formatKeyword(text: String): String |
Dmitry Jemerov | 4494fd0 | 2015-02-26 21:34:27 +0100 | [diff] [blame] | 34 | public abstract fun formatIdentifier(text: String, kind: IdentifierKind): String |
Ilya Ryzhenkov | 71cd87e | 2014-10-03 22:51:44 +0400 | [diff] [blame] | 35 | public abstract fun formatLink(text: String, href: String): String |
Dmitry Jemerov | d9bfa02 | 2015-02-19 18:59:00 +0100 | [diff] [blame] | 36 | public open fun formatLink(link: FormatLink): String = formatLink(formatText(link.text), link.href) |
Ilya Ryzhenkov | 9f0ff55 | 2014-10-13 13:38:40 +0400 | [diff] [blame] | 37 | public abstract fun formatStrong(text: String): String |
Dmitry Jemerov | e17eaa5 | 2015-01-09 20:59:58 +0100 | [diff] [blame] | 38 | public abstract fun formatStrikethrough(text: String): String |
Ilya Ryzhenkov | 9f0ff55 | 2014-10-13 13:38:40 +0400 | [diff] [blame] | 39 | public abstract fun formatEmphasis(text: String): String |
Ilya Ryzhenkov | 62cb509 | 2014-07-15 15:54:05 +0400 | [diff] [blame] | 40 | public abstract fun formatCode(code: String): String |
Dmitry Jemerov | 6659337 | 2015-03-03 19:35:56 +0100 | [diff] [blame^] | 41 | public abstract fun formatUnorderedList(text: String): String |
| 42 | public abstract fun formatOrderedList(text: String): String |
| 43 | public abstract fun formatListItem(text: String, kind: ListKind): String |
Ilya Ryzhenkov | 62cb509 | 2014-07-15 15:54:05 +0400 | [diff] [blame] | 44 | public abstract fun formatBreadcrumbs(items: Iterable<FormatLink>): String |
Dmitry Jemerov | 722c9af | 2015-02-26 16:28:05 +0100 | [diff] [blame] | 45 | public abstract fun formatNonBreakingSpace(): String |
Ilya Ryzhenkov | 62cb509 | 2014-07-15 15:54:05 +0400 | [diff] [blame] | 46 | |
Dmitry Jemerov | 6659337 | 2015-03-03 19:35:56 +0100 | [diff] [blame^] | 47 | open fun formatText(location: Location, nodes: Iterable<ContentNode>, listKind: ListKind = ListKind.Unordered): String { |
| 48 | return nodes.map { formatText(location, it, listKind) }.join("") |
Ilya Ryzhenkov | 778e2b3 | 2014-09-29 20:54:59 +0400 | [diff] [blame] | 49 | } |
| 50 | |
Dmitry Jemerov | 6659337 | 2015-03-03 19:35:56 +0100 | [diff] [blame^] | 51 | open fun formatText(location: Location, content: ContentNode, listKind: ListKind = ListKind.Unordered): String { |
Ilya Ryzhenkov | 455d74a | 2014-09-19 22:25:27 +0300 | [diff] [blame] | 52 | return StringBuilder { |
Ilya Ryzhenkov | d6fd045 | 2014-10-03 20:20:02 +0400 | [diff] [blame] | 53 | when (content) { |
Dmitry Jemerov | 8ef6818 | 2014-12-30 12:36:14 +0100 | [diff] [blame] | 54 | is ContentText -> append(formatText(content.text)) |
Ilya Ryzhenkov | d6fd045 | 2014-10-03 20:20:02 +0400 | [diff] [blame] | 55 | is ContentSymbol -> append(formatSymbol(content.text)) |
| 56 | is ContentKeyword -> append(formatKeyword(content.text)) |
Dmitry Jemerov | 4494fd0 | 2015-02-26 21:34:27 +0100 | [diff] [blame] | 57 | is ContentIdentifier -> append(formatIdentifier(content.text, content.kind)) |
Dmitry Jemerov | 722c9af | 2015-02-26 16:28:05 +0100 | [diff] [blame] | 58 | is ContentNonBreakingSpace -> append(formatNonBreakingSpace()) |
Ilya Ryzhenkov | 9f0ff55 | 2014-10-13 13:38:40 +0400 | [diff] [blame] | 59 | is ContentStrong -> append(formatStrong(formatText(location, content.children))) |
Dmitry Jemerov | e17eaa5 | 2015-01-09 20:59:58 +0100 | [diff] [blame] | 60 | is ContentStrikethrough -> append(formatStrikethrough(formatText(location, content.children))) |
Ilya Ryzhenkov | 9f0ff55 | 2014-10-13 13:38:40 +0400 | [diff] [blame] | 61 | is ContentCode -> append(formatCode(formatText(location, content.children))) |
| 62 | is ContentEmphasis -> append(formatEmphasis(formatText(location, content.children))) |
Dmitry Jemerov | 6659337 | 2015-03-03 19:35:56 +0100 | [diff] [blame^] | 63 | is ContentUnorderedList -> append(formatUnorderedList(formatText(location, content.children, ListKind.Unordered))) |
| 64 | is ContentOrderedList -> append(formatOrderedList(formatText(location, content.children, ListKind.Ordered))) |
| 65 | is ContentListItem -> append(formatListItem(formatText(location, content.children), listKind)) |
Ilya Ryzhenkov | 1839949 | 2014-12-22 09:50:17 +0200 | [diff] [blame] | 66 | |
Ilya Ryzhenkov | d6fd045 | 2014-10-03 20:20:02 +0400 | [diff] [blame] | 67 | is ContentNodeLink -> { |
Dmitry Jemerov | 184a24c | 2015-02-25 19:03:51 +0100 | [diff] [blame] | 68 | val node = content.node |
| 69 | val linkTo = if (node != null) locationHref(location, node) else "#" |
Ilya Ryzhenkov | d6fd045 | 2014-10-03 20:20:02 +0400 | [diff] [blame] | 70 | val linkText = formatText(location, content.children) |
Dmitry Jemerov | 4b61be3 | 2015-02-26 21:17:13 +0100 | [diff] [blame] | 71 | if (linkTo == ".") { |
| 72 | append(linkText) |
| 73 | } else { |
| 74 | append(formatLink(linkText, linkTo)) |
| 75 | } |
Ilya Ryzhenkov | d6fd045 | 2014-10-03 20:20:02 +0400 | [diff] [blame] | 76 | } |
Ilya Ryzhenkov | 71cd87e | 2014-10-03 22:51:44 +0400 | [diff] [blame] | 77 | is ContentExternalLink -> { |
| 78 | val linkText = formatText(location, content.children) |
Dmitry Jemerov | 4b61be3 | 2015-02-26 21:17:13 +0100 | [diff] [blame] | 79 | if (content.href == ".") { |
| 80 | append(linkText) |
| 81 | } else { |
| 82 | append(formatLink(linkText, content.href)) |
| 83 | } |
Ilya Ryzhenkov | 71cd87e | 2014-10-03 22:51:44 +0400 | [diff] [blame] | 84 | } |
Ilya Ryzhenkov | ad14ea9 | 2014-10-13 18:22:02 +0400 | [diff] [blame] | 85 | is ContentParagraph -> { |
Dmitry Jemerov | 8ef6818 | 2014-12-30 12:36:14 +0100 | [diff] [blame] | 86 | appendParagraph(this, formatText(location, content.children)) |
Ilya Ryzhenkov | ad14ea9 | 2014-10-13 18:22:02 +0400 | [diff] [blame] | 87 | } |
Ilya Ryzhenkov | 1cb3af9 | 2014-10-13 20:14:45 +0400 | [diff] [blame] | 88 | is ContentBlockCode -> { |
Dmitry Jemerov | 44cef5c | 2015-02-26 19:34:49 +0100 | [diff] [blame] | 89 | appendBlockCode(this, formatText(location, content.children), content.language) |
Ilya Ryzhenkov | 1cb3af9 | 2014-10-13 20:14:45 +0400 | [diff] [blame] | 90 | } |
Dmitry Jemerov | 0d0fc1f | 2015-02-10 18:32:12 +0100 | [diff] [blame] | 91 | is ContentBlock -> append(formatText(location, content.children)) |
Ilya Ryzhenkov | 455d74a | 2014-09-19 22:25:27 +0300 | [diff] [blame] | 92 | } |
| 93 | }.toString() |
| 94 | } |
| 95 | |
Ilya Ryzhenkov | 62cb509 | 2014-07-15 15:54:05 +0400 | [diff] [blame] | 96 | open public fun link(from: DocumentationNode, to: DocumentationNode): FormatLink = link(from, to, extension) |
| 97 | |
| 98 | open public fun link(from: DocumentationNode, to: DocumentationNode, extension: String): FormatLink { |
Dmitry Jemerov | ea1f4cc | 2015-02-19 19:51:01 +0100 | [diff] [blame] | 99 | return FormatLink(to.name, locationService.relativePathToLocation(from, to)) |
Ilya Ryzhenkov | 62cb509 | 2014-07-15 15:54:05 +0400 | [diff] [blame] | 100 | } |
| 101 | |
Dmitry Jemerov | 85a3ae7 | 2015-02-20 14:08:30 +0100 | [diff] [blame] | 102 | fun locationHref(from: Location, to: DocumentationNode): String { |
| 103 | val topLevelPage = to.references(DocumentationReference.Kind.TopLevelPage).singleOrNull()?.to |
| 104 | if (topLevelPage != null) { |
| 105 | return from.relativePathTo(locationService.location(topLevelPage), to.name) |
| 106 | } |
| 107 | return from.relativePathTo(locationService.location(to)) |
| 108 | } |
| 109 | |
Dmitry Jemerov | e1a3884 | 2015-02-10 18:55:12 +0100 | [diff] [blame] | 110 | fun appendDocumentation(location: Location, to: StringBuilder, overloads: Iterable<DocumentationNode>) { |
| 111 | val breakdownBySummary = overloads.groupByTo(LinkedHashMap()) { node -> node.content } |
Dmitry Jemerov | bfd9ffd | 2015-01-30 17:59:15 +0100 | [diff] [blame] | 112 | |
Dmitry Jemerov | e1a3884 | 2015-02-10 18:55:12 +0100 | [diff] [blame] | 113 | for ((summary, items) in breakdownBySummary) { |
| 114 | items.forEach { |
Dmitry Jemerov | f90ee50 | 2015-02-26 13:55:37 +0100 | [diff] [blame] | 115 | appendAsSignature(to) { |
| 116 | to.append(formatCode(formatText(location, languageService.render(it)))) |
| 117 | it.appendSourceLink(to) |
| 118 | } |
Dmitry Jemerov | e1a3884 | 2015-02-10 18:55:12 +0100 | [diff] [blame] | 119 | it.appendOverrides(to) |
Dmitry Jemerov | a60d8ba | 2015-02-24 16:24:00 +0100 | [diff] [blame] | 120 | it.appendDeprecation(location, to) |
Ilya Ryzhenkov | 62cb509 | 2014-07-15 15:54:05 +0400 | [diff] [blame] | 121 | } |
Dmitry Jemerov | e1a3884 | 2015-02-10 18:55:12 +0100 | [diff] [blame] | 122 | // All items have exactly the same documentation, so we can use any item to render it |
| 123 | val item = items.first() |
Dmitry Jemerov | f462317 | 2015-03-02 16:17:28 +0100 | [diff] [blame] | 124 | item.details(DocumentationNode.Kind.OverloadGroupNote).forEach { |
| 125 | to.append(formatText(location, it.content)) |
| 126 | } |
Dmitry Jemerov | ebbf265 | 2015-02-10 19:35:27 +0100 | [diff] [blame] | 127 | to.append(formatText(location, item.content.summary)) |
Dmitry Jemerov | e1a3884 | 2015-02-10 18:55:12 +0100 | [diff] [blame] | 128 | appendDescription(location, to, item) |
Dmitry Jemerov | ebbf265 | 2015-02-10 19:35:27 +0100 | [diff] [blame] | 129 | appendLine(to) |
| 130 | appendLine(to) |
Dmitry Jemerov | e1a3884 | 2015-02-10 18:55:12 +0100 | [diff] [blame] | 131 | } |
| 132 | } |
| 133 | |
Dmitry Jemerov | f90ee50 | 2015-02-26 13:55:37 +0100 | [diff] [blame] | 134 | protected open fun appendAsSignature(to: StringBuilder, block: () -> Unit) { |
| 135 | block() |
| 136 | } |
| 137 | |
Dmitry Jemerov | e1a3884 | 2015-02-10 18:55:12 +0100 | [diff] [blame] | 138 | fun appendDescription(location: Location, to: StringBuilder, node: DocumentationNode) { |
| 139 | if (node.content.description != ContentEmpty) { |
| 140 | appendHeader(to, "Description", 3) |
| 141 | appendLine(to, formatText(location, node.content.description)) |
| 142 | appendLine(to) |
| 143 | } |
| 144 | node.content.getSectionsWithSubjects().forEach { |
| 145 | appendSectionWithSubject(it.getKey(), location, it.getValue(), to) |
| 146 | } |
| 147 | |
| 148 | for (section in node.content.sections.filter { it.subjectName == null }) { |
| 149 | appendLine(to, formatStrong(formatText(section.tag))) |
| 150 | appendLine(to, formatText(location, section)) |
Ilya Ryzhenkov | 62cb509 | 2014-07-15 15:54:05 +0400 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
Dmitry Jemerov | 0fac1d9 | 2015-01-30 19:01:40 +0100 | [diff] [blame] | 154 | fun Content.getSectionsWithSubjects(): Map<String, List<ContentSection>> = |
| 155 | sections.filter { it.subjectName != null }.groupBy { it.tag } |
| 156 | |
| 157 | fun appendSectionWithSubject(title: String, location: Location, subjectSections: List<ContentSection>, to: StringBuilder) { |
Dmitry Jemerov | bfd9ffd | 2015-01-30 17:59:15 +0100 | [diff] [blame] | 158 | appendHeader(to, title, 3) |
Dmitry Jemerov | 0fac1d9 | 2015-01-30 19:01:40 +0100 | [diff] [blame] | 159 | subjectSections.forEach { |
| 160 | val subjectName = it.subjectName |
| 161 | if (subjectName != null) { |
Dmitry Jemerov | 85a3ae7 | 2015-02-20 14:08:30 +0100 | [diff] [blame] | 162 | appendAnchor(to, subjectName) |
Dmitry Jemerov | 0fac1d9 | 2015-01-30 19:01:40 +0100 | [diff] [blame] | 163 | to.append(formatCode(subjectName)).append(" - ") |
| 164 | to.append(formatText(location, it)) |
Dmitry Jemerov | bfd9ffd | 2015-01-30 17:59:15 +0100 | [diff] [blame] | 165 | appendLine(to) |
| 166 | } |
| 167 | } |
Dmitry Jemerov | c43a437 | 2014-12-29 20:22:43 +0100 | [diff] [blame] | 168 | } |
| 169 | |
Dmitry Jemerov | 0dd5ea3 | 2015-01-14 13:30:43 +0100 | [diff] [blame] | 170 | private fun DocumentationNode.appendOverrides(to: StringBuilder) { |
| 171 | overrides.forEach { |
| 172 | to.append("Overrides ") |
Dmitry Jemerov | ea1f4cc | 2015-02-19 19:51:01 +0100 | [diff] [blame] | 173 | val location = locationService.relativePathToLocation(this, it) |
Dmitry Jemerov | 0dd5ea3 | 2015-01-14 13:30:43 +0100 | [diff] [blame] | 174 | appendLine(to, formatLink(FormatLink(it.owner!!.name + "." + it.name, location))) |
| 175 | } |
| 176 | } |
| 177 | |
Dmitry Jemerov | a60d8ba | 2015-02-24 16:24:00 +0100 | [diff] [blame] | 178 | private fun DocumentationNode.appendDeprecation(location: Location, to: StringBuilder) { |
Dmitry Jemerov | 0dd5ea3 | 2015-01-14 13:30:43 +0100 | [diff] [blame] | 179 | if (deprecation != null) { |
| 180 | val deprecationParameter = deprecation!!.details(DocumentationNode.Kind.Parameter).firstOrNull() |
| 181 | val deprecationValue = deprecationParameter?.details(DocumentationNode.Kind.Value)?.firstOrNull() |
| 182 | if (deprecationValue != null) { |
Dmitry Jemerov | 7003ad8 | 2015-02-26 13:20:41 +0100 | [diff] [blame] | 183 | to.append(formatStrong("Deprecated:")).append(" ") |
Dmitry Jemerov | 0dd5ea3 | 2015-01-14 13:30:43 +0100 | [diff] [blame] | 184 | appendLine(to, formatText(deprecationValue.name.trim("\""))) |
Dmitry Jemerov | f7c2f2a | 2015-02-26 19:45:36 +0100 | [diff] [blame] | 185 | appendLine(to) |
Dmitry Jemerov | a60d8ba | 2015-02-24 16:24:00 +0100 | [diff] [blame] | 186 | } else if (deprecation?.content != Content.Empty) { |
Dmitry Jemerov | 7003ad8 | 2015-02-26 13:20:41 +0100 | [diff] [blame] | 187 | to.append(formatStrong("Deprecated:")).append(" ") |
Dmitry Jemerov | a60d8ba | 2015-02-24 16:24:00 +0100 | [diff] [blame] | 188 | to.append(formatText(location, deprecation!!.content)) |
Dmitry Jemerov | 0dd5ea3 | 2015-01-14 13:30:43 +0100 | [diff] [blame] | 189 | } else { |
| 190 | appendLine(to, formatStrong("Deprecated")) |
Dmitry Jemerov | f7c2f2a | 2015-02-26 19:45:36 +0100 | [diff] [blame] | 191 | appendLine(to) |
Dmitry Jemerov | 0dd5ea3 | 2015-01-14 13:30:43 +0100 | [diff] [blame] | 192 | } |
| 193 | } |
| 194 | } |
| 195 | |
Dmitry Jemerov | 6146fa8 | 2015-01-14 18:46:36 +0100 | [diff] [blame] | 196 | private fun DocumentationNode.appendSourceLink(to: StringBuilder) { |
| 197 | val sourceUrl = details(DocumentationNode.Kind.SourceUrl).firstOrNull() |
| 198 | if (sourceUrl != null) { |
Dmitry Jemerov | ebbf265 | 2015-02-10 19:35:27 +0100 | [diff] [blame] | 199 | to.append(" ") |
| 200 | appendLine(to, formatLink("(source)", sourceUrl.name)) |
| 201 | } else { |
| 202 | appendLine(to) |
Dmitry Jemerov | 6146fa8 | 2015-01-14 18:46:36 +0100 | [diff] [blame] | 203 | } |
| 204 | } |
| 205 | |
Ilya Ryzhenkov | d6fd045 | 2014-10-03 20:20:02 +0400 | [diff] [blame] | 206 | fun appendLocation(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>) { |
Ilya Ryzhenkov | bd494a8 | 2014-08-21 19:53:36 +0400 | [diff] [blame] | 207 | val breakdownByName = nodes.groupBy { node -> node.name } |
Ilya Ryzhenkov | 62cb509 | 2014-07-15 15:54:05 +0400 | [diff] [blame] | 208 | for ((name, items) in breakdownByName) { |
Ilya Ryzhenkov | aa59acb | 2014-07-15 20:05:55 +0400 | [diff] [blame] | 209 | appendHeader(to, formatText(name)) |
Dmitry Jemerov | e1a3884 | 2015-02-10 18:55:12 +0100 | [diff] [blame] | 210 | appendDocumentation(location, to, items) |
Ilya Ryzhenkov | 62cb509 | 2014-07-15 15:54:05 +0400 | [diff] [blame] | 211 | } |
| 212 | } |
| 213 | |
Ilya Ryzhenkov | 4907736 | 2014-10-14 19:53:13 +0400 | [diff] [blame] | 214 | private fun StructuredFormatService.appendSection(location: Location, caption: String, nodes: List<DocumentationNode>, node: DocumentationNode, to: StringBuilder) { |
Ilya Ryzhenkov | a52e1d5 | 2014-10-03 15:57:16 +0400 | [diff] [blame] | 215 | if (nodes.any()) { |
| 216 | appendHeader(to, caption, 3) |
Ilya Ryzhenkov | 62cb509 | 2014-07-15 15:54:05 +0400 | [diff] [blame] | 217 | |
Ilya Ryzhenkov | a52e1d5 | 2014-10-03 15:57:16 +0400 | [diff] [blame] | 218 | val children = nodes.sortBy { it.name } |
| 219 | val membersMap = children.groupBy { link(node, it) } |
Ilya Ryzhenkov | aa59acb | 2014-07-15 20:05:55 +0400 | [diff] [blame] | 220 | |
Ilya Ryzhenkov | a52e1d5 | 2014-10-03 15:57:16 +0400 | [diff] [blame] | 221 | appendTable(to) { |
| 222 | appendTableBody(to) { |
Ilya Ryzhenkov | d6fd045 | 2014-10-03 20:20:02 +0400 | [diff] [blame] | 223 | for ((memberLocation, members) in membersMap) { |
Ilya Ryzhenkov | a52e1d5 | 2014-10-03 15:57:16 +0400 | [diff] [blame] | 224 | appendTableRow(to) { |
| 225 | appendTableCell(to) { |
Dmitry Jemerov | 8ef6818 | 2014-12-30 12:36:14 +0100 | [diff] [blame] | 226 | to.append(formatLink(memberLocation)) |
Ilya Ryzhenkov | a52e1d5 | 2014-10-03 15:57:16 +0400 | [diff] [blame] | 227 | } |
| 228 | appendTableCell(to) { |
Ilya Ryzhenkov | 280dc29 | 2014-10-14 16:08:10 +0400 | [diff] [blame] | 229 | val breakdownBySummary = members.groupBy { formatText(location, it.summary) } |
Ilya Ryzhenkov | a52e1d5 | 2014-10-03 15:57:16 +0400 | [diff] [blame] | 230 | for ((summary, items) in breakdownBySummary) { |
Dmitry Jemerov | 3fc3e33 | 2014-12-30 15:35:00 +0100 | [diff] [blame] | 231 | val signatureTexts = items map { signature -> |
Dmitry Jemerov | 7170d63 | 2015-03-02 14:35:47 +0100 | [diff] [blame] | 232 | val signatureText = languageService.render(signature, RenderMode.SUMMARY) |
Dmitry Jemerov | 8ef6818 | 2014-12-30 12:36:14 +0100 | [diff] [blame] | 233 | val signatureAsCode = ContentCode() |
Dmitry Jemerov | 7170d63 | 2015-03-02 14:35:47 +0100 | [diff] [blame] | 234 | signatureAsCode.append(signatureText) |
Dmitry Jemerov | 3fc3e33 | 2014-12-30 15:35:00 +0100 | [diff] [blame] | 235 | formatText(location, signatureAsCode) |
Ilya Ryzhenkov | a52e1d5 | 2014-10-03 15:57:16 +0400 | [diff] [blame] | 236 | } |
Dmitry Jemerov | 3fc3e33 | 2014-12-30 15:35:00 +0100 | [diff] [blame] | 237 | signatureTexts.subList(0, signatureTexts.size()-1).forEach { |
Dmitry Jemerov | 86a6db8 | 2015-02-26 14:40:02 +0100 | [diff] [blame] | 238 | appendAsSignature(to) { |
| 239 | appendLine(to, it) |
| 240 | } |
Dmitry Jemerov | 3fc3e33 | 2014-12-30 15:35:00 +0100 | [diff] [blame] | 241 | } |
Dmitry Jemerov | f90ee50 | 2015-02-26 13:55:37 +0100 | [diff] [blame] | 242 | appendAsSignature(to) { |
| 243 | to.append(signatureTexts.last()) |
| 244 | } |
Ilya Ryzhenkov | a52e1d5 | 2014-10-03 15:57:16 +0400 | [diff] [blame] | 245 | if (!summary.isEmpty()) { |
Dmitry Jemerov | 8ef6818 | 2014-12-30 12:36:14 +0100 | [diff] [blame] | 246 | to.append(summary) |
Ilya Ryzhenkov | aa59acb | 2014-07-15 20:05:55 +0400 | [diff] [blame] | 247 | } |
| 248 | } |
| 249 | } |
Ilya Ryzhenkov | e8447fd | 2014-07-15 16:37:50 +0400 | [diff] [blame] | 250 | } |
Ilya Ryzhenkov | 62cb509 | 2014-07-15 15:54:05 +0400 | [diff] [blame] | 251 | } |
Ilya Ryzhenkov | 62cb509 | 2014-07-15 15:54:05 +0400 | [diff] [blame] | 252 | } |
| 253 | } |
Ilya Ryzhenkov | 62cb509 | 2014-07-15 15:54:05 +0400 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | |
Ilya Ryzhenkov | d6fd045 | 2014-10-03 20:20:02 +0400 | [diff] [blame] | 257 | override fun appendNodes(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>) { |
| 258 | val breakdownByLocation = nodes.groupBy { node -> |
Dmitry Jemerov | d9bfa02 | 2015-02-19 18:59:00 +0100 | [diff] [blame] | 259 | formatBreadcrumbs(node.path.filterNot { it.name.isEmpty() }.map { link(node, it) }) |
Ilya Ryzhenkov | d6fd045 | 2014-10-03 20:20:02 +0400 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | for ((breadcrumbs, items) in breakdownByLocation) { |
| 263 | appendLine(to, breadcrumbs) |
| 264 | appendLine(to) |
Dmitry Jemerov | 4b0dcee | 2015-01-09 19:48:44 +0100 | [diff] [blame] | 265 | appendLocation(location, to, items.filter { it.kind != DocumentationNode.Kind.ExternalClass }) |
Ilya Ryzhenkov | d6fd045 | 2014-10-03 20:20:02 +0400 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | for (node in nodes) { |
Dmitry Jemerov | 4b0dcee | 2015-01-09 19:48:44 +0100 | [diff] [blame] | 269 | if (node.kind == DocumentationNode.Kind.ExternalClass) { |
| 270 | appendSection(location, "Extensions for ${node.name}", node.members, node, to) |
| 271 | continue |
| 272 | } |
| 273 | |
Ilya Ryzhenkov | 4907736 | 2014-10-14 19:53:13 +0400 | [diff] [blame] | 274 | appendSection(location, "Packages", node.members(DocumentationNode.Kind.Package), node, to) |
| 275 | appendSection(location, "Types", node.members.filter { |
| 276 | it.kind in setOf( |
| 277 | DocumentationNode.Kind.Class, |
| 278 | DocumentationNode.Kind.Interface, |
| 279 | DocumentationNode.Kind.Enum, |
Dmitry Jemerov | 716483c | 2014-12-30 17:41:14 +0100 | [diff] [blame] | 280 | DocumentationNode.Kind.Object, |
| 281 | DocumentationNode.Kind.AnnotationClass) |
Ilya Ryzhenkov | 4907736 | 2014-10-14 19:53:13 +0400 | [diff] [blame] | 282 | }, node, to) |
Dmitry Jemerov | 4b0dcee | 2015-01-09 19:48:44 +0100 | [diff] [blame] | 283 | appendSection(location, "Extensions for External Classes", node.members(DocumentationNode.Kind.ExternalClass), node, to) |
Ilya Ryzhenkov | 4907736 | 2014-10-14 19:53:13 +0400 | [diff] [blame] | 284 | appendSection(location, "Constructors", node.members(DocumentationNode.Kind.Constructor), node, to) |
| 285 | appendSection(location, "Properties", node.members(DocumentationNode.Kind.Property), node, to) |
| 286 | appendSection(location, "Functions", node.members(DocumentationNode.Kind.Function), node, to) |
Dmitry Jemerov | 2822a3e | 2015-02-17 12:32:17 +0100 | [diff] [blame] | 287 | appendSection(location, "Default Object Properties", node.members(DocumentationNode.Kind.DefaultObjectProperty), node, to) |
| 288 | appendSection(location, "Default Object Functions", node.members(DocumentationNode.Kind.DefaultObjectFunction), node, to) |
Dmitry Jemerov | c4f40a0 | 2015-01-12 16:32:30 +0100 | [diff] [blame] | 289 | appendSection(location, "Enum Values", node.members(DocumentationNode.Kind.EnumItem), node, to) |
Ilya Ryzhenkov | 4907736 | 2014-10-14 19:53:13 +0400 | [diff] [blame] | 290 | appendSection(location, "Other members", node.members.filter { |
| 291 | it.kind !in setOf( |
| 292 | DocumentationNode.Kind.Class, |
| 293 | DocumentationNode.Kind.Interface, |
Dmitry Jemerov | 716483c | 2014-12-30 17:41:14 +0100 | [diff] [blame] | 294 | DocumentationNode.Kind.Enum, |
Ilya Ryzhenkov | 4907736 | 2014-10-14 19:53:13 +0400 | [diff] [blame] | 295 | DocumentationNode.Kind.Object, |
Dmitry Jemerov | 716483c | 2014-12-30 17:41:14 +0100 | [diff] [blame] | 296 | DocumentationNode.Kind.AnnotationClass, |
Ilya Ryzhenkov | 4907736 | 2014-10-14 19:53:13 +0400 | [diff] [blame] | 297 | DocumentationNode.Kind.Constructor, |
| 298 | DocumentationNode.Kind.Property, |
| 299 | DocumentationNode.Kind.Package, |
| 300 | DocumentationNode.Kind.Function, |
Dmitry Jemerov | 2822a3e | 2015-02-17 12:32:17 +0100 | [diff] [blame] | 301 | DocumentationNode.Kind.DefaultObjectProperty, |
| 302 | DocumentationNode.Kind.DefaultObjectFunction, |
Dmitry Jemerov | c4f40a0 | 2015-01-12 16:32:30 +0100 | [diff] [blame] | 303 | DocumentationNode.Kind.ExternalClass, |
| 304 | DocumentationNode.Kind.EnumItem |
Ilya Ryzhenkov | 4907736 | 2014-10-14 19:53:13 +0400 | [diff] [blame] | 305 | ) |
| 306 | }, node, to) |
Dmitry Jemerov | 4f59034 | 2015-02-26 19:19:55 +0100 | [diff] [blame] | 307 | appendSection(location, "Extension Properties", node.extensions.filter { it.kind == DocumentationNode.Kind.Property }, node, to) |
| 308 | appendSection(location, "Extension Functions", node.extensions.filter { it.kind == DocumentationNode.Kind.Function }, node, to) |
Dmitry Jemerov | c4f40a0 | 2015-01-12 16:32:30 +0100 | [diff] [blame] | 309 | appendSection(location, "Inheritors", |
| 310 | node.inheritors.filter { it.kind != DocumentationNode.Kind.EnumItem }, node, to) |
Ilya Ryzhenkov | d6fd045 | 2014-10-03 20:20:02 +0400 | [diff] [blame] | 311 | appendSection(location, "Links", node.links, node, to) |
| 312 | |
| 313 | } |
| 314 | } |
Ilya Ryzhenkov | 62cb509 | 2014-07-15 15:54:05 +0400 | [diff] [blame] | 315 | } |