Skip to content

Commit

Permalink
[backport] Make possible to generate signatures on output format side
Browse files Browse the repository at this point in the history
Original: 4469044
semoro committed Jul 13, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 5906960 commit 63ab561
Showing 3 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions core/src/main/kotlin/Kotlin/DocumentationBuilder.kt
Original file line number Diff line number Diff line change
@@ -234,6 +234,7 @@ class DocumentationBuilder
val externalLink = linkResolver.externalDocumentationLinkResolver.buildExternalDocumentationLink(classifierDescriptor)
if (externalLink != null) {
node.append(DocumentationNode(externalLink, Content.Empty, NodeKind.ExternalLink), RefKind.Link)
node.append(DocumentationNode(classifierDescriptor.fqNameUnsafe.asString(), Content.Empty, NodeKind.QualifiedName), RefKind.Detail)
} else {
link(node, classifierDescriptor,
if (classifierDescriptor.isBoringBuiltinClass()) RefKind.HiddenLink else RefKind.Link)
28 changes: 15 additions & 13 deletions core/src/main/kotlin/Kotlin/KotlinLanguageService.kt
Original file line number Diff line number Diff line change
@@ -48,8 +48,7 @@ class KotlinLanguageService : LanguageService {
val typeParameter = functionWithTypeParameter.details(NodeKind.TypeParameter).first()
if (functionWithTypeParameter.kind == NodeKind.Function) {
renderFunction(functionWithTypeParameter, RenderMode.SUMMARY, SummarizingMapper(receiverKind, typeParameter.name))
}
else {
} else {
renderProperty(functionWithTypeParameter, RenderMode.SUMMARY, SummarizingMapper(receiverKind, typeParameter.name))
}
}
@@ -103,7 +102,7 @@ class KotlinLanguageService : LanguageService {
fun renderReceiver(receiver: DocumentationNode, to: ContentBlock)
}

private class SummarizingMapper(val kind: ReceiverKind, val typeParameterName: String): SignatureMapper {
private class SummarizingMapper(val kind: ReceiverKind, val typeParameterName: String) : SignatureMapper {
override fun renderReceiver(receiver: DocumentationNode, to: ContentBlock) {
to.append(ContentIdentifier(kind.receiverName, IdentifierKind.SummarizedTypeName))
to.text("<$typeParameterName>")
@@ -117,7 +116,7 @@ class KotlinLanguageService : LanguageService {
}

private fun <T> ContentBlock.renderList(nodes: List<T>, separator: String = ", ",
noWrap: Boolean = false, renderItem: (T) -> Unit) {
noWrap: Boolean = false, renderItem: (T) -> Unit) {
if (nodes.none())
return
renderItem(nodes.first())
@@ -132,7 +131,7 @@ class KotlinLanguageService : LanguageService {
}
}

private fun ContentBlock.renderLinked(node: DocumentationNode, body: ContentBlock.(DocumentationNode)->Unit) {
private fun ContentBlock.renderLinked(node: DocumentationNode, body: ContentBlock.(DocumentationNode) -> Unit) {
val to = node.links.firstOrNull()
if (to == null)
body(node)
@@ -216,13 +215,13 @@ class KotlinLanguageService : LanguageService {

private fun ContentBlock.renderModifier(node: DocumentationNode, nowrap: Boolean = false) {
when (node.name) {
"final", "public", "var" -> {}
"final", "public", "var" -> {
}
else -> {
keyword(node.name)
if (nowrap) {
nbsp()
}
else {
} else {
text(" ")
}
}
@@ -239,11 +238,12 @@ class KotlinLanguageService : LanguageService {
nbsp()
symbol(":")
nbsp()
renderList(constraints, noWrap=true) {
renderList(constraints, noWrap = true) {
renderType(it, renderMode)
}
}
}

private fun ContentBlock.renderParameter(node: DocumentationNode, renderMode: RenderMode) {
if (renderMode == RenderMode.FULL) {
renderAnnotationsForNode(node)
@@ -402,8 +402,7 @@ class KotlinLanguageService : LanguageService {
symbol(")")
symbol(": ")
renderType(node.detail(NodeKind.Type), renderMode)
}
else {
} else {
symbol(")")
}
renderExtraTypeParameterConstraints(node, renderMode)
@@ -429,7 +428,7 @@ class KotlinLanguageService : LanguageService {
}
}

private fun needReturnType(node: DocumentationNode) = when(node.kind) {
private fun needReturnType(node: DocumentationNode) = when (node.kind) {
NodeKind.Constructor -> false
else -> !node.isUnitReturnType()
}
@@ -476,4 +475,7 @@ class KotlinLanguageService : LanguageService {
}
}

fun DocumentationNode.qualifiedNameFromType() = (links.firstOrNull() ?: hiddenLinks.firstOrNull())?.qualifiedName() ?: name
fun DocumentationNode.qualifiedNameFromType() =
details.firstOrNull { it.kind == NodeKind.QualifiedName }?.name
?: (links.firstOrNull() ?: hiddenLinks.firstOrNull())?.qualifiedName()
?: name
1 change: 1 addition & 0 deletions core/src/main/kotlin/Model/DocumentationNode.kt
Original file line number Diff line number Diff line change
@@ -48,6 +48,7 @@ enum class NodeKind {
Signature,

ExternalLink,
QualifiedName,
Platform,

AllTypes,

0 comments on commit 63ab561

Please sign in to comment.