aboutsummaryrefslogtreecommitdiff
path: root/plugins/kotlin-as-java/src/main/kotlin
diff options
context:
space:
mode:
authorvmishenev <vad-mishenev@yandex.ru>2021-08-25 17:14:31 +0300
committerGitHub <noreply@github.com>2021-08-25 16:14:31 +0200
commit4fa9524e52d8ff422bb355336e3810ab28ae135c (patch)
tree66d2bc381ffc7d5c598cee4ea9e0ba13f81b1d7b /plugins/kotlin-as-java/src/main/kotlin
parent742f96bdf5c0b842e68dfaf43f4ab3446e87e3df (diff)
downloaddokka-4fa9524e52d8ff422bb355336e3810ab28ae135c.tar.gz
dokka-4fa9524e52d8ff422bb355336e3810ab28ae135c.tar.bz2
dokka-4fa9524e52d8ff422bb355336e3810ab28ae135c.zip
Manual highlighting webhelp (#2079)
* Add manual code highlighting * Fix test * Add kotlinAsJava highlighting * Add runtime highlighting via Prism * Add copy-button for code block * Add tests and refactor * Replace `<br>` for prism.js * Parse trivial default values Co-authored-by: Marcin Aman <marcin.aman@gmail.com>
Diffstat (limited to 'plugins/kotlin-as-java/src/main/kotlin')
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt67
1 files changed, 39 insertions, 28 deletions
diff --git a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt
index 58a3043c..65b34017 100644
--- a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt
+++ b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt
@@ -1,18 +1,17 @@
package org.jetbrains.dokka.kotlinAsJava.signatures
-import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.base.signatures.JvmSignatureUtils
import org.jetbrains.dokka.base.signatures.SignatureProvider
import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter
import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder
import org.jetbrains.dokka.links.DRI
-import org.jetbrains.dokka.links.sureClassNames
import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.model.properties.WithExtraProperties
import org.jetbrains.dokka.pages.ContentKind
import org.jetbrains.dokka.pages.ContentNode
import org.jetbrains.dokka.pages.TextStyle
+import org.jetbrains.dokka.pages.TokenStyle
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.plugability.plugin
import org.jetbrains.dokka.plugability.querySingle
@@ -64,33 +63,39 @@ class JavaSignatureProvider internal constructor(ctcc: CommentsToContentConverte
?: emptySet()),
sourceSets = setOf(it)
) {
- text(c.visibility[it]?.takeIf { it !in ignoredVisibilities }?.name?.plus(" ") ?: "")
+ c.visibility[it]?.takeIf { it !in ignoredVisibilities }?.name?.plus(" ")?.let { keyword(it) }
if (c is DClass) {
- text(c.modifier[it]?.takeIf { it !in ignoredModifiers }?.name?.plus(" ") ?: "")
- text(c.modifiers()[it]?.toSignatureString() ?: "")
+ c.modifier[it]?.takeIf { it !in ignoredModifiers }?.name?.plus(" ")?.let { keyword(it) }
+ c.modifiers()[it]?.toSignatureString()?.let { keyword(it) }
}
when (c) {
- is DClass -> text("class ")
- is DInterface -> text("interface ")
- is DEnum -> text("enum ")
- is DObject -> text("class ")
- is DAnnotation -> text("@interface ")
+ is DClass -> keyword("class ")
+ is DInterface -> keyword("interface ")
+ is DEnum -> keyword("enum ")
+ is DObject -> keyword("class ")
+ is DAnnotation -> keyword("@interface ")
}
link(c.name!!, c.dri)
if (c is WithGenerics) {
- list(c.generics, prefix = "<", suffix = ">") {
+ list(c.generics, prefix = "<", suffix = ">",
+ separatorStyles = mainStyles + TokenStyle.Punctuation,
+ surroundingCharactersStyle = mainStyles + TokenStyle.Operator) {
+buildSignature(it)
}
}
if (c is WithSupertypes) {
c.supertypes.map { (p, dris) ->
val (classes, interfaces) = dris.partition { it.kind == JavaClassKindTypes.CLASS }
- list(classes, prefix = " extends ", sourceSets = setOf(p)) {
+ list(classes, prefix = " extends ", sourceSets = setOf(p),
+ separatorStyles = mainStyles + TokenStyle.Punctuation,
+ surroundingCharactersStyle = mainStyles + TokenStyle.Keyword) {
signatureForProjection(it.typeConstructor)
}
- list(interfaces, prefix = " implements ", sourceSets = setOf(p)) {
+ list(interfaces, prefix = " implements ", sourceSets = setOf(p),
+ separatorStyles = mainStyles + TokenStyle.Punctuation,
+ surroundingCharactersStyle = mainStyles + TokenStyle.Keyword) {
signatureForProjection(it.typeConstructor)
}
}
@@ -107,9 +112,9 @@ class JavaSignatureProvider internal constructor(ctcc: CommentsToContentConverte
sourceSets = setOf(it)
) {
annotationsBlock(p)
- text(p.visibility[it]?.takeIf { it !in ignoredVisibilities }?.name?.plus(" ") ?: "")
- text(p.modifier[it]?.name + " ")
- text(p.modifiers()[it]?.toSignatureString() ?: "")
+ p.visibility[it]?.takeIf { it !in ignoredVisibilities }?.name?.let { keyword("$it ") }
+ p.modifier[it]?.name?.let { keyword("$it ") }
+ p.modifiers()[it]?.toSignatureString()?.let { keyword(it) }
signatureForProjection(p.type)
text(nbsp.toString())
link(p.name, p.dri)
@@ -125,25 +130,27 @@ class JavaSignatureProvider internal constructor(ctcc: CommentsToContentConverte
sourceSets = setOf(sourceSet)
) {
annotationsBlock(f)
- text(f.modifier[sourceSet]?.takeIf { it !in ignoredModifiers }?.name?.plus(" ") ?: "")
- text(f.modifiers()[sourceSet]?.toSignatureString() ?: "")
+ f.modifier[sourceSet]?.takeIf { it !in ignoredModifiers }?.name?.plus(" ")?.let { keyword(it) }
+ f.modifiers()[sourceSet]?.toSignatureString()?.let { keyword(it) }
val returnType = f.type
signatureForProjection(returnType)
text(nbsp.toString())
- link(f.name, f.dri)
+ link(f.name, f.dri, styles = mainStyles + TokenStyle.Function)
val usedGenerics = if (f.isConstructor) f.generics.filter { f uses it } else f.generics
- list(usedGenerics, prefix = "<", suffix = ">") {
+ list(usedGenerics, prefix = "<", suffix = ">",
+ separatorStyles = mainStyles + TokenStyle.Punctuation,
+ surroundingCharactersStyle = mainStyles + TokenStyle.Operator) {
+buildSignature(it)
}
- text("(")
- list(f.parameters) {
+ punctuation("(")
+ list(f.parameters, separatorStyles = mainStyles + TokenStyle.Punctuation) {
annotationsInline(it)
- text(it.modifiers()[sourceSet]?.toSignatureString() ?: "")
+ text(it.modifiers()[sourceSet]?.toSignatureString() ?: "", styles = mainStyles + TokenStyle.Keyword)
signatureForProjection(it.type)
text(nbsp.toString())
text(it.name!!)
}
- text(")")
+ punctuation(")")
}
}
@@ -151,7 +158,9 @@ class JavaSignatureProvider internal constructor(ctcc: CommentsToContentConverte
t.sourceSets.map {
contentBuilder.contentFor(t, styles = t.stylesIfDeprecated(it), sourceSets = setOf(it)) {
text(t.name.substringAfterLast("."))
- list(t.bounds, prefix = " extends ") {
+ list(t.bounds, prefix = " extends ",
+ separatorStyles = mainStyles + TokenStyle.Punctuation,
+ surroundingCharactersStyle = mainStyles + TokenStyle.Keyword) {
signatureForProjection(it)
}
}
@@ -163,7 +172,9 @@ class JavaSignatureProvider internal constructor(ctcc: CommentsToContentConverte
is TypeConstructor -> group(styles = emptySet()) {
link(p.dri.classNames.orEmpty(), p.dri)
- list(p.projections, prefix = "<", suffix = ">") {
+ list(p.projections, prefix = "<", suffix = ">",
+ separatorStyles = mainStyles + TokenStyle.Punctuation,
+ surroundingCharactersStyle = mainStyles + TokenStyle.Operator) {
signatureForProjection(it)
}
}
@@ -174,11 +185,11 @@ class JavaSignatureProvider internal constructor(ctcc: CommentsToContentConverte
is Contravariance<*> -> "? super "
is Invariance<*> -> ""
}
- text(variance)
+ keyword(variance)
signatureForProjection(p.inner)
}
- is Star -> text("?")
+ is Star -> operator("?")
is Nullable -> signatureForProjection(p.inner)