• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.jetbrains.dokka
2 
3 import org.jetbrains.dokka.Formats.nameWithOuterClass
4 
5 
6 abstract class CommonLanguageService : LanguageService {
7 
ContentBlocknull8     protected fun ContentBlock.renderPackage(node: DocumentationNode) {
9         keyword("package")
10         nbsp()
11         identifier(node.name)
12     }
13 
renderNamenull14     override fun renderName(node: DocumentationNode): String {
15         return when (node.kind) {
16             NodeKind.Constructor -> node.owner!!.name
17             else -> node.name
18         }
19     }
20 
renderNameWithOuterClassnull21     override fun renderNameWithOuterClass(node: DocumentationNode): String {
22         return when (node.kind) {
23             NodeKind.Constructor -> node.owner!!.nameWithOuterClass()
24             else -> node.nameWithOuterClass()
25         }
26     }
27 
renderModifiernull28     open fun renderModifier(
29         block: ContentBlock,
30         node: DocumentationNode,
31         renderMode: LanguageService.RenderMode,
32         nowrap: Boolean = false
33     ) = with(block) {
34         keyword(node.name)
35         if (nowrap) {
36             nbsp()
37         } else {
38             text(" ")
39         }
40     }
41 
renderLinkednull42     protected fun renderLinked(
43         block: ContentBlock,
44         node: DocumentationNode,
45         body: ContentBlock.(DocumentationNode) -> Unit
46     ) = with(block) {
47         val to = node.links.firstOrNull()
48         if (to == null)
49             body(node)
50         else
51             link(to) {
52                 this.body(node)
53             }
54     }
55 
renderHardWrappingListnull56     protected fun <T> ContentBlock.renderHardWrappingList(
57         nodes: List<T>, separator: String = ", ",
58         renderItem: (T) -> Unit
59     ) {
60         if (nodes.none())
61             return
62 
63         if (nodes.count() > 1) {
64             hardLineBreak()
65             repeat(4) {
66                 nbsp()
67             }
68         }
69 
70         renderItem(nodes.first())
71         nodes.drop(1).forEach {
72             symbol(separator)
73             hardLineBreak()
74             repeat(4) {
75                 nbsp()
76             }
77             renderItem(it)
78         }
79     }
80 
renderListnull81     protected fun <T> ContentBlock.renderList(
82         nodes: List<T>, separator: String = ", ",
83         noWrap: Boolean = false, renderItem: (T) -> Unit
84     ) {
85         if (nodes.none())
86             return
87         renderItem(nodes.first())
88         nodes.drop(1).forEach {
89             if (noWrap) {
90                 symbol(separator.removeSuffix(" "))
91                 nbsp()
92             } else {
93                 symbol(separator)
94             }
95             renderItem(it)
96         }
97     }
98 
showModifierInSummarynull99     abstract fun showModifierInSummary(node: DocumentationNode): Boolean
100 
101     protected fun ContentBlock.renderModifiersForNode(
102         node: DocumentationNode,
103         renderMode: LanguageService.RenderMode,
104         nowrap: Boolean = false
105     ) {
106         val modifiers = node.details(NodeKind.Modifier)
107         for (it in modifiers) {
108             if (node.kind == NodeKind.Interface && it.name == "abstract")
109                 continue
110             if (renderMode == LanguageService.RenderMode.SUMMARY && !showModifierInSummary(it)) {
111                 continue
112             }
113             renderModifier(this, it, renderMode, nowrap)
114         }
115     }
116 
117 
118 }