aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/Kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/kotlin/Kotlin')
-rw-r--r--core/src/main/kotlin/Kotlin/DeclarationLinkResolver.kt32
-rw-r--r--core/src/main/kotlin/Kotlin/DocumentationBuilder.kt13
2 files changed, 42 insertions, 3 deletions
diff --git a/core/src/main/kotlin/Kotlin/DeclarationLinkResolver.kt b/core/src/main/kotlin/Kotlin/DeclarationLinkResolver.kt
index 2569bc71..c1c301f2 100644
--- a/core/src/main/kotlin/Kotlin/DeclarationLinkResolver.kt
+++ b/core/src/main/kotlin/Kotlin/DeclarationLinkResolver.kt
@@ -1,9 +1,15 @@
package org.jetbrains.dokka
import com.google.inject.Inject
+import com.intellij.psi.PsiMethod
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.idea.kdoc.resolveKDocLink
+import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
+import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor
+import org.jetbrains.kotlin.name.Name
+import org.jetbrains.kotlin.resolve.DescriptorUtils
+import org.jetbrains.kotlin.resolve.source.PsiSourceElement
class DeclarationLinkResolver
@Inject constructor(val resolutionFacade: DokkaResolutionFacade,
@@ -20,6 +26,10 @@ class DeclarationLinkResolver
// don't include unresolved links in generated doc
// assume that if an href doesn't contain '/', it's not an attempt to reference an external file
if (symbol != null) {
+ val jdkHref = buildJdkLink(symbol)
+ if (jdkHref != null) {
+ return ContentExternalLink(jdkHref)
+ }
return ContentNodeLazyLink(href, { -> refGraph.lookup(symbol.signature()) })
}
if ("/" in href) {
@@ -40,4 +50,26 @@ class DeclarationLinkResolver
return symbol
}
+ fun buildJdkLink(symbol: DeclarationDescriptor): String? {
+ if (symbol is JavaClassDescriptor) {
+ val fqName = DescriptorUtils.getFqName(symbol)
+ if (fqName.startsWith(Name.identifier("java")) || fqName.startsWith(Name.identifier("javax"))) {
+ return javadocRoot + fqName.asString().replace(".", "/") + ".html"
+ }
+ }
+ else if (symbol is JavaMethodDescriptor) {
+ val containingClass = symbol.containingDeclaration as? JavaClassDescriptor ?: return null
+ val containingClassLink = buildJdkLink(containingClass)
+ if (containingClassLink != null) {
+ val psi = (symbol.original.source as? PsiSourceElement)?.psi as? PsiMethod
+ if (psi != null) {
+ val params = psi.parameterList.parameters.joinToString { it.type.canonicalText }
+ return containingClassLink + "#" + symbol.name + "(" + params + ")"
+ }
+ }
+ }
+ return null
+ }
+
+ private val javadocRoot = "http://docs.oracle.com/javase/6/docs/api/"
} \ No newline at end of file
diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt
index f3b206c6..4694bcdf 100644
--- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt
+++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt
@@ -66,7 +66,8 @@ class DocumentationBuilder
val descriptorDocumentationParser: DescriptorDocumentationParser,
val options: DocumentationOptions,
val refGraph: NodeReferenceGraph,
- val logger: DokkaLogger)
+ val logger: DokkaLogger,
+ val linkResolver: DeclarationLinkResolver)
{
val visibleToDocumentation = setOf(Visibilities.PROTECTED, Visibilities.PUBLIC)
val boringBuiltinClasses = setOf(
@@ -180,8 +181,14 @@ class DocumentationBuilder
node.appendTextNode("?", NodeKind.NullabilityModifier)
}
if (classifierDescriptor != null) {
- link(node, classifierDescriptor,
- if (classifierDescriptor.isBoringBuiltinClass()) RefKind.HiddenLink else RefKind.Link)
+ val jdkLink = linkResolver.buildJdkLink(classifierDescriptor)
+ if (jdkLink != null) {
+ node.append(DocumentationNode(jdkLink, Content.Empty, NodeKind.ExternalLink), RefKind.Link)
+ }
+ else {
+ link(node, classifierDescriptor,
+ if (classifierDescriptor.isBoringBuiltinClass()) RefKind.HiddenLink else RefKind.Link)
+ }
}
append(node, RefKind.Detail)