From c43a437caa047f787bd3bb84ff612f505d0f8efc Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Mon, 29 Dec 2014 20:22:43 +0100 Subject: don't generate "Description" header if nothing is going to follow it --- src/Formats/StructuredFormatService.kt | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/Formats') diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt index 08b7e55d..adfac99c 100644 --- a/src/Formats/StructuredFormatService.kt +++ b/src/Formats/StructuredFormatService.kt @@ -78,9 +78,9 @@ public abstract class StructuredFormatService(val locationService: LocationServi } fun appendDescription(location: Location, to: StringBuilder, nodes: Iterable) { - val described = nodes.filter { !it.content.isEmpty } + val described = nodes.filter { it.hasDescription() } if (described.any()) { - val single = described.size == 1 + val single = described.size() == 1 appendHeader(to, "Description", 3) for (node in described) { if (!single) { @@ -89,10 +89,7 @@ public abstract class StructuredFormatService(val locationService: LocationServi appendLine(to, formatText(location, node.content.description)) appendLine(to) for ((label, section) in node.content.sections) { - if (label.startsWith("$")) - continue - if (node.members.any { it.name == label }) - continue + if (!isDescriptionSection(label, node)) continue appendLine(to, formatStrong(formatText(label))) appendLine(to, formatText(location, section)) } @@ -100,6 +97,17 @@ public abstract class StructuredFormatService(val locationService: LocationServi } } + private fun DocumentationNode.hasDescription() = + content.description != ContentEmpty || content.sections.any { isDescriptionSection(it.key, this) } + + private fun isDescriptionSection(label: String, node: DocumentationNode): Boolean { + if (label.startsWith("$")) + return false + if (node.members.any { it.name == label }) + return false + return true + } + fun appendSummary(location: Location, to: StringBuilder, nodes: Iterable) { val breakdownBySummary = nodes.groupByTo(LinkedHashMap()) { node -> formatText(location, node.summary) -- cgit