diff options
author | Dmitry Jemerov <yole@jetbrains.com> | 2015-12-03 16:22:11 +0100 |
---|---|---|
committer | Dmitry Jemerov <yole@jetbrains.com> | 2015-12-03 16:22:49 +0100 |
commit | 39631054c58df5841ea268b7002b820ec55f6e0a (patch) | |
tree | cefedd8411c859243bd181568e16fcdd372a38c8 /src/Model/SourceLinks.kt | |
parent | 797cb4732c53bf1e3b2091add8cf731fc436607f (diff) | |
download | dokka-39631054c58df5841ea268b7002b820ec55f6e0a.tar.gz dokka-39631054c58df5841ea268b7002b820ec55f6e0a.tar.bz2 dokka-39631054c58df5841ea268b7002b820ec55f6e0a.zip |
restructure Dokka build to use Gradle for everything except for the Maven plugin
Diffstat (limited to 'src/Model/SourceLinks.kt')
-rw-r--r-- | src/Model/SourceLinks.kt | 56 |
1 files changed, 0 insertions, 56 deletions
diff --git a/src/Model/SourceLinks.kt b/src/Model/SourceLinks.kt deleted file mode 100644 index 956bfe4b..00000000 --- a/src/Model/SourceLinks.kt +++ /dev/null @@ -1,56 +0,0 @@ -package org.jetbrains.dokka - -import com.intellij.psi.PsiElement -import java.io.File -import com.intellij.psi.PsiDocumentManager -import com.intellij.psi.PsiNameIdentifierOwner -import org.jetbrains.kotlin.psi.psiUtil.startOffset - -class SourceLinkDefinition(val path: String, val url: String, val lineSuffix: String?) - -fun DocumentationNode.appendSourceLink(psi: PsiElement?, sourceLinks: List<SourceLinkDefinition>) { - val path = psi?.containingFile?.virtualFile?.path ?: return - - val target = if (psi is PsiNameIdentifierOwner) psi.nameIdentifier else psi - 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) - if (linkDef.lineSuffix != null) { - val line = target?.lineNumber() - if (line != null) { - url += linkDef.lineSuffix + line.toString() - } - } - append(DocumentationNode(url, Content.Empty, DocumentationNode.Kind.SourceUrl), - DocumentationReference.Kind.Detail); - } - - if (target != null) { - append(DocumentationNode(target.sourcePosition(), Content.Empty, DocumentationNode.Kind.SourcePosition), DocumentationReference.Kind.Detail) - } -} - -private fun PsiElement.sourcePosition(): String { - val path = containingFile.virtualFile.path - val lineNumber = lineNumber() - val columnNumber = columnNumber() - - return when { - lineNumber == null -> path - columnNumber == null -> "$path:$lineNumber" - else -> "$path:$lineNumber:$columnNumber" - } -} - -fun PsiElement.lineNumber(): Int? { - val doc = PsiDocumentManager.getInstance(project).getDocument(containingFile) - // IJ uses 0-based line-numbers; external source browsers use 1-based - return doc?.getLineNumber(textRange.startOffset)?.plus(1) -} - -fun PsiElement.columnNumber(): Int? { - 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 |