diff options
Diffstat (limited to 'src/Model')
-rw-r--r-- | src/Model/Content.kt | 65 | ||||
-rw-r--r-- | src/Model/DocumentationModule.kt | 11 | ||||
-rw-r--r-- | src/Model/DocumentationNode.kt | 14 | ||||
-rw-r--r-- | src/Model/DocumentationReference.kt | 3 | ||||
-rw-r--r-- | src/Model/PackageDocs.kt | 14 | ||||
-rw-r--r-- | src/Model/SourceLinks.kt | 9 |
6 files changed, 80 insertions, 36 deletions
diff --git a/src/Model/Content.kt b/src/Model/Content.kt index 0bb78454..45d42a2d 100644 --- a/src/Model/Content.kt +++ b/src/Model/Content.kt @@ -1,10 +1,14 @@ package org.jetbrains.dokka -public abstract class ContentNode +public interface ContentNode { + val textLength: Int +} -public object ContentEmpty : ContentNode() +public object ContentEmpty : ContentNode { + override val textLength: Int get() = 0 +} -public open class ContentBlock() : ContentNode() { +public open class ContentBlock() : ContentNode { val children = arrayListOf<ContentNode>() fun append(node : ContentNode) { @@ -18,21 +22,58 @@ public open class ContentBlock() : ContentNode() { override fun hashCode(): Int = children.hashCode() + + override val textLength: Int + get() = children.sumBy { it.textLength } } enum class IdentifierKind { TypeName, ParameterName, AnnotationName, + SummarizedTypeName, Other } -public data class ContentText(val text: String) : ContentNode() -public data class ContentKeyword(val text: String) : ContentNode() -public data class ContentIdentifier(val text: String, val kind: IdentifierKind = IdentifierKind.Other) : ContentNode() -public data class ContentSymbol(val text: String) : ContentNode() -public data class ContentEntity(val text: String) : ContentNode() -public object ContentNonBreakingSpace: ContentNode() +public data class ContentText(val text: String) : ContentNode { + override val textLength: Int + get() = text.length +} + +public data class ContentKeyword(val text: String) : ContentNode { + override val textLength: Int + get() = text.length +} + +public data class ContentIdentifier(val text: String, val kind: IdentifierKind = IdentifierKind.Other) : ContentNode { + override val textLength: Int + get() = text.length +} + +public data class ContentSymbol(val text: String) : ContentNode { + override val textLength: Int + get() = text.length +} + +public data class ContentEntity(val text: String) : ContentNode { + override val textLength: Int + get() = text.length +} + +public object ContentNonBreakingSpace: ContentNode { + override val textLength: Int + get() = 1 +} + +public object ContentSoftLineBreak: ContentNode { + override val textLength: Int + get() = 0 +} + +public object ContentIndentedSoftLineBreak: ContentNode { + override val textLength: Int + get() = 0 +} public class ContentParagraph() : ContentBlock() public class ContentEmphasis() : ContentBlock() @@ -101,6 +142,9 @@ fun ContentBlock.keyword(value: String) = append(ContentKeyword(value)) fun ContentBlock.symbol(value: String) = append(ContentSymbol(value)) fun ContentBlock.identifier(value: String, kind: IdentifierKind = IdentifierKind.Other) = append(ContentIdentifier(value, kind)) fun ContentBlock.nbsp() = append(ContentNonBreakingSpace) +fun ContentBlock.softLineBreak() = append(ContentSoftLineBreak) +fun ContentBlock.indentedSoftLineBreak() = append(ContentIndentedSoftLineBreak) + fun ContentBlock.strong(body: ContentBlock.() -> Unit) { val strong = ContentStrong() strong.body() @@ -171,9 +215,6 @@ public open class MutableContent() : Content() { return "<empty>" return (listOf(summary, description) + sections).joinToString() } - - val isEmpty: Boolean - get() = sections.none() } fun javadocSectionDisplayName(sectionName: String?): String? = diff --git a/src/Model/DocumentationModule.kt b/src/Model/DocumentationModule.kt deleted file mode 100644 index e74c544b..00000000 --- a/src/Model/DocumentationModule.kt +++ /dev/null @@ -1,11 +0,0 @@ -package org.jetbrains.dokka - -public class DocumentationModule(name: String, content: Content = Content.Empty) : DocumentationNode(name, content, DocumentationNode.Kind.Module) { - fun merge(other: DocumentationModule): DocumentationModule { - val model = DocumentationModule(name) - model.addAllReferencesFrom(other) - model.addAllReferencesFrom(this) - return model - } -} - diff --git a/src/Model/DocumentationNode.kt b/src/Model/DocumentationNode.kt index c3b9942d..4a77f761 100644 --- a/src/Model/DocumentationNode.kt +++ b/src/Model/DocumentationNode.kt @@ -1,6 +1,6 @@ package org.jetbrains.dokka -import java.util.LinkedHashSet +import java.util.* public open class DocumentationNode(val name: String, content: Content, @@ -19,6 +19,8 @@ public open class DocumentationNode(val name: String, get() = references(DocumentationReference.Kind.Detail).map { it.to } public val members: List<DocumentationNode> get() = references(DocumentationReference.Kind.Member).map { it.to } + public val inheritedMembers: List<DocumentationNode> + get() = references(DocumentationReference.Kind.InheritedMember).map { it.to } public val extensions: List<DocumentationNode> get() = references(DocumentationReference.Kind.Extension).map { it.to } public val inheritors: List<DocumentationNode> @@ -27,6 +29,8 @@ public open class DocumentationNode(val name: String, get() = references(DocumentationReference.Kind.Override).map { it.to } public val links: List<DocumentationNode> get() = references(DocumentationReference.Kind.Link).map { it.to } + public val hiddenLinks: List<DocumentationNode> + get() = references(DocumentationReference.Kind.HiddenLink).map { it.to } public val annotations: List<DocumentationNode> get() = references(DocumentationReference.Kind.Annotation).map { it.to } public val deprecation: DocumentationNode? @@ -50,6 +54,7 @@ public open class DocumentationNode(val name: String, public fun details(kind: DocumentationNode.Kind): List<DocumentationNode> = details.filter { it.kind == kind } public fun members(kind: DocumentationNode.Kind): List<DocumentationNode> = members.filter { it.kind == kind } + public fun inheritedMembers(kind: DocumentationNode.Kind): List<DocumentationNode> = inheritedMembers.filter { it.kind == kind } public fun links(kind: DocumentationNode.Kind): List<DocumentationNode> = links.filter { it.kind == kind } public fun detail(kind: DocumentationNode.Kind): DocumentationNode = details.filter { it.kind == kind }.single() @@ -112,6 +117,10 @@ public open class DocumentationNode(val name: String, } +public class DocumentationModule(name: String, content: Content = Content.Empty) + : DocumentationNode(name, content, DocumentationNode.Kind.Module) { +} + val DocumentationNode.path: List<DocumentationNode> get() { val parent = owner ?: return listOf(this) @@ -137,6 +146,7 @@ fun DocumentationNode.append(child: DocumentationNode, kind: DocumentationRefere DocumentationReference.Kind.Detail -> child.addReferenceTo(this, DocumentationReference.Kind.Owner) DocumentationReference.Kind.Member -> child.addReferenceTo(this, DocumentationReference.Kind.Owner) DocumentationReference.Kind.Owner -> child.addReferenceTo(this, DocumentationReference.Kind.Member) + else -> { /* Do not add any links back for other types */ } } } @@ -145,3 +155,5 @@ fun DocumentationNode.appendTextNode(text: String, refKind: DocumentationReference.Kind = DocumentationReference.Kind.Detail) { append(DocumentationNode(text, Content.Empty, kind), refKind) } + +fun DocumentationNode.qualifiedName() = path.drop(1).map { it.name }.filter { it.length > 0 }.joinToString(".") diff --git a/src/Model/DocumentationReference.kt b/src/Model/DocumentationReference.kt index a61ac65f..79cec2f3 100644 --- a/src/Model/DocumentationReference.kt +++ b/src/Model/DocumentationReference.kt @@ -4,10 +4,13 @@ public data class DocumentationReference(val from: DocumentationNode, val to: Do public enum class Kind { Owner, Member, + InheritedMember, Detail, Link, + HiddenLink, Extension, Inheritor, + Superclass, Override, Annotation, Deprecation, diff --git a/src/Model/PackageDocs.kt b/src/Model/PackageDocs.kt index b5b34942..99da327b 100644 --- a/src/Model/PackageDocs.kt +++ b/src/Model/PackageDocs.kt @@ -5,7 +5,7 @@ import org.intellij.markdown.MarkdownTokenTypes import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import java.io.File -public class PackageDocs(val documentationBuilder: DocumentationBuilder, +public class PackageDocs(val documentationBuilder: DocumentationBuilder?, val linkResolveContext: DeclarationDescriptor?, val logger: DokkaLogger) { public val moduleContent: MutableContent = MutableContent() @@ -13,17 +13,17 @@ public class PackageDocs(val documentationBuilder: DocumentationBuilder, public val packageContent: Map<String, Content> get() = _packageContent - fun parse(path: String) { - val file = File(path) + fun parse(fileName: String) { + val file = File(fileName) if (file.exists()) { val text = file.readText() val tree = parseMarkdown(text) var targetContent: MutableContent = moduleContent tree.children.forEach { if (it.type == MarkdownElementTypes.ATX_1) { - val headingText = it.child(MarkdownTokenTypes.TEXT)?.text + val headingText = it.child(MarkdownTokenTypes.ATX_CONTENT)?.text if (headingText != null) { - targetContent = findTargetContent(headingText) + targetContent = findTargetContent(headingText.trimStart()) } } else { buildContentTo(it, targetContent, { resolveContentLink(it) }) @@ -39,7 +39,7 @@ public class PackageDocs(val documentationBuilder: DocumentationBuilder, return moduleContent } if (heading.startsWith("Package") || heading.startsWith("package")) { - return findOrCreatePackageContent(heading.substring("package".length()).trim()) + return findOrCreatePackageContent(heading.substring("package".length).trim()) } return findOrCreatePackageContent(heading) } @@ -48,7 +48,7 @@ public class PackageDocs(val documentationBuilder: DocumentationBuilder, _packageContent.getOrPut(packageName) { -> MutableContent() } private fun resolveContentLink(href: String): ContentBlock { - if (linkResolveContext != null) { + if (linkResolveContext != null && documentationBuilder != null) { return documentationBuilder.resolveContentLink(linkResolveContext, href) } return ContentExternalLink("#") diff --git a/src/Model/SourceLinks.kt b/src/Model/SourceLinks.kt index 4530518f..956bfe4b 100644 --- a/src/Model/SourceLinks.kt +++ b/src/Model/SourceLinks.kt @@ -15,7 +15,7 @@ fun DocumentationNode.appendSourceLink(psi: PsiElement?, sourceLinks: List<Sourc val absPath = File(path).absolutePath val linkDef = sourceLinks.firstOrNull { absPath.startsWith(it.path) } if (linkDef != null) { - var url = linkDef.url + path.substring(linkDef.path.length()) + var url = linkDef.url + path.substring(linkDef.path.length) if (linkDef.lineSuffix != null) { val line = target?.lineNumber() if (line != null) { @@ -50,8 +50,7 @@ fun PsiElement.lineNumber(): Int? { } fun PsiElement.columnNumber(): Int? { - val doc = PsiDocumentManager.getInstance(project).getDocument(containingFile) - // IJ uses 0-based line-numbers; external source browsers use 1-based - val lineNumber = doc?.getLineNumber(textRange.startOffset)?.plus(1) ?: return null - return startOffset - doc!!.getLineStartOffset(lineNumber) + val doc = PsiDocumentManager.getInstance(project).getDocument(containingFile) ?: return null + val lineNumber = doc.getLineNumber(textRange.startOffset) + return startOffset - doc.getLineStartOffset(lineNumber) }
\ No newline at end of file |