aboutsummaryrefslogtreecommitdiff
path: root/src/Model
diff options
context:
space:
mode:
authorDmitry Jemerov <yole@jetbrains.com>2015-02-13 17:19:44 +0100
committerDmitry Jemerov <yole@jetbrains.com>2015-02-13 17:19:44 +0100
commit2527b962c394511ef90d9d76fe66a39caeea436e (patch)
treed9d2a93d786744b3b7a348023344fc15cbce4570 /src/Model
parentaa3f05136ca743eac15a9f8deb939f69cff6eb70 (diff)
downloaddokka-2527b962c394511ef90d9d76fe66a39caeea436e.tar.gz
dokka-2527b962c394511ef90d9d76fe66a39caeea436e.tar.bz2
dokka-2527b962c394511ef90d9d76fe66a39caeea436e.zip
extract source links to non-Kotlin-specific part
Diffstat (limited to 'src/Model')
-rw-r--r--src/Model/SourceLinks.kt31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/Model/SourceLinks.kt b/src/Model/SourceLinks.kt
new file mode 100644
index 00000000..556b813b
--- /dev/null
+++ b/src/Model/SourceLinks.kt
@@ -0,0 +1,31 @@
+package org.jetbrains.dokka
+
+import com.intellij.psi.PsiElement
+import java.io.File
+import com.intellij.psi.PsiDocumentManager
+import com.intellij.psi.PsiNameIdentifierOwner
+
+class SourceLinkDefinition(val path: String, val url: String, val lineSuffix: String?)
+
+fun DocumentationNode.appendSourceLink(psi: PsiElement?, sourceLinks: List<SourceLinkDefinition>) {
+ val path = psi?.getContainingFile()?.getVirtualFile()?.getPath()
+ if (path == null) {
+ return
+ }
+ val target = if (psi is PsiNameIdentifierOwner) psi.getNameIdentifier() else psi
+ val absPath = File(path).getAbsolutePath()
+ val linkDef = sourceLinks.firstOrNull { absPath.startsWith(it.path) }
+ if (linkDef != null) {
+ var url = linkDef.url + path.substring(linkDef.path.length())
+ if (linkDef.lineSuffix != null) {
+ val doc = PsiDocumentManager.getInstance(psi!!.getProject()).getDocument(psi.getContainingFile())
+ if (doc != null) {
+ // IJ uses 0-based line-numbers; external source browsers use 1-based
+ val line = doc.getLineNumber(target!!.getTextRange().getStartOffset()) + 1
+ url += linkDef.lineSuffix + line.toString()
+ }
+ }
+ append(DocumentationNode(url, Content.Empty, DocumentationNode.Kind.SourceUrl),
+ DocumentationReference.Kind.Detail);
+ }
+}