aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ogorodnik <Simon.Ogorodnik@jetbrains.com>2017-11-04 02:09:16 +0300
committerSimon Ogorodnik <Simon.Ogorodnik@jetbrains.com>2017-11-05 02:11:51 +0300
commit694d51d7bb5a5900fb30d201a8d675cec0f5e92b (patch)
treea308b00dd5275a24ea235b7d7b4da27111f15095
parentce7ebd213a56abd2be6beacbef26b339935baeb6 (diff)
downloaddokka-694d51d7bb5a5900fb30d201a8d675cec0f5e92b.tar.gz
dokka-694d51d7bb5a5900fb30d201a8d675cec0f5e92b.tar.bz2
dokka-694d51d7bb5a5900fb30d201a8d675cec0f5e92b.zip
Fix Can't find node by signature in asJava mode
fixes #205
-rw-r--r--core/src/main/kotlin/Formats/FormatDescriptor.kt2
-rw-r--r--core/src/main/kotlin/Formats/StandardFormats.kt5
-rw-r--r--core/src/main/kotlin/Kotlin/DeclarationLinkResolver.kt7
-rw-r--r--core/src/main/kotlin/Kotlin/KotlinAsJavaDescriptorSignatureProvider.kt17
-rw-r--r--core/src/main/kotlin/Kotlin/KotlinDescriptorSignatureProvider.kt9
-rw-r--r--core/src/main/kotlin/Model/DescriptorSignatureProvider.kt7
-rw-r--r--core/src/main/kotlin/Utilities/DokkaModules.kt3
-rw-r--r--core/src/main/kotlin/javadoc/dokka-adapters.kt3
-rw-r--r--core/src/test/kotlin/javadoc/JavadocTest.kt10
-rw-r--r--core/testdata/javadoc/companionMethodReference.kt13
-rw-r--r--runners/cli/src/main/kotlin/cli/main.kt4
11 files changed, 76 insertions, 4 deletions
diff --git a/core/src/main/kotlin/Formats/FormatDescriptor.kt b/core/src/main/kotlin/Formats/FormatDescriptor.kt
index fc925f40..da0156a7 100644
--- a/core/src/main/kotlin/Formats/FormatDescriptor.kt
+++ b/core/src/main/kotlin/Formats/FormatDescriptor.kt
@@ -1,6 +1,7 @@
package org.jetbrains.dokka.Formats
import org.jetbrains.dokka.*
+import org.jetbrains.dokka.Model.DescriptorSignatureProvider
import org.jetbrains.dokka.Samples.SampleProcessingService
import kotlin.reflect.KClass
@@ -12,4 +13,5 @@ interface FormatDescriptor {
val javaDocumentationBuilderClass: KClass<out JavaDocumentationBuilder>
val sampleProcessingService: KClass<out SampleProcessingService>
val packageListServiceClass: KClass<out PackageListService>?
+ val descriptorSignatureProvider: KClass<out DescriptorSignatureProvider>
}
diff --git a/core/src/main/kotlin/Formats/StandardFormats.kt b/core/src/main/kotlin/Formats/StandardFormats.kt
index fad65ff1..f3d638c6 100644
--- a/core/src/main/kotlin/Formats/StandardFormats.kt
+++ b/core/src/main/kotlin/Formats/StandardFormats.kt
@@ -1,6 +1,9 @@
package org.jetbrains.dokka.Formats
import org.jetbrains.dokka.*
+import org.jetbrains.dokka.Kotlin.KotlinAsJavaDescriptorSignatureProvider
+import org.jetbrains.dokka.Kotlin.KotlinDescriptorSignatureProvider
+import org.jetbrains.dokka.Model.DescriptorSignatureProvider
import org.jetbrains.dokka.Samples.DefaultSampleProcessingService
import org.jetbrains.dokka.Samples.KotlinWebsiteSampleProcessingService
import org.jetbrains.dokka.Samples.SampleProcessingService
@@ -14,6 +17,7 @@ abstract class KotlinFormatDescriptorBase : FormatDescriptor {
override val outlineServiceClass: KClass<out OutlineFormatService>? = null
override val sampleProcessingService: KClass<out SampleProcessingService> = DefaultSampleProcessingService::class
override val packageListServiceClass: KClass<out PackageListService>? = DefaultPackageListService::class
+ override val descriptorSignatureProvider = KotlinDescriptorSignatureProvider::class
}
class HtmlFormatDescriptor : KotlinFormatDescriptorBase() {
@@ -29,6 +33,7 @@ class HtmlAsJavaFormatDescriptor : FormatDescriptor {
override val javaDocumentationBuilderClass = JavaPsiDocumentationBuilder::class
override val sampleProcessingService: KClass<out SampleProcessingService> = DefaultSampleProcessingService::class
override val packageListServiceClass: KClass<out PackageListService>? = DefaultPackageListService::class
+ override val descriptorSignatureProvider = KotlinAsJavaDescriptorSignatureProvider::class
}
class KotlinWebsiteFormatDescriptor : KotlinFormatDescriptorBase() {
diff --git a/core/src/main/kotlin/Kotlin/DeclarationLinkResolver.kt b/core/src/main/kotlin/Kotlin/DeclarationLinkResolver.kt
index 2b085769..275972fa 100644
--- a/core/src/main/kotlin/Kotlin/DeclarationLinkResolver.kt
+++ b/core/src/main/kotlin/Kotlin/DeclarationLinkResolver.kt
@@ -1,6 +1,7 @@
package org.jetbrains.dokka
import com.google.inject.Inject
+import org.jetbrains.dokka.Model.DescriptorSignatureProvider
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.idea.kdoc.resolveKDocLink
@@ -10,7 +11,8 @@ class DeclarationLinkResolver
val refGraph: NodeReferenceGraph,
val logger: DokkaLogger,
val options: DocumentationOptions,
- val externalDocumentationLinkResolver: ExternalDocumentationLinkResolver) {
+ val externalDocumentationLinkResolver: ExternalDocumentationLinkResolver,
+ val descriptorSignatureProvider: DescriptorSignatureProvider) {
fun tryResolveContentLink(fromDescriptor: DeclarationDescriptor, href: String): ContentBlock? {
@@ -29,7 +31,8 @@ class DeclarationLinkResolver
if (externalHref != null) {
return ContentExternalLink(externalHref)
}
- return ContentNodeLazyLink(href, { -> refGraph.lookupOrWarn(symbol.signature(), logger) })
+ val signature = descriptorSignatureProvider.signature(symbol)
+ return ContentNodeLazyLink(href, { -> refGraph.lookupOrWarn(signature, logger) })
}
if ("/" in href) {
return ContentExternalLink(href)
diff --git a/core/src/main/kotlin/Kotlin/KotlinAsJavaDescriptorSignatureProvider.kt b/core/src/main/kotlin/Kotlin/KotlinAsJavaDescriptorSignatureProvider.kt
new file mode 100644
index 00000000..ca15b89f
--- /dev/null
+++ b/core/src/main/kotlin/Kotlin/KotlinAsJavaDescriptorSignatureProvider.kt
@@ -0,0 +1,17 @@
+package org.jetbrains.dokka.Kotlin
+
+import org.jetbrains.dokka.Model.DescriptorSignatureProvider
+import org.jetbrains.dokka.getSignature
+import org.jetbrains.dokka.sourcePsi
+import org.jetbrains.kotlin.asJava.toLightElements
+import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
+import org.jetbrains.kotlin.psi.KtElement
+
+class KotlinAsJavaDescriptorSignatureProvider : DescriptorSignatureProvider {
+ override fun signature(forDesc: DeclarationDescriptor): String {
+
+ val sourcePsi = forDesc.sourcePsi() as? KtElement
+ return getSignature(sourcePsi?.toLightElements().orEmpty().firstOrNull()) ?:
+ throw UnsupportedOperationException("Don't know how to calculate signature for $forDesc")
+ }
+} \ No newline at end of file
diff --git a/core/src/main/kotlin/Kotlin/KotlinDescriptorSignatureProvider.kt b/core/src/main/kotlin/Kotlin/KotlinDescriptorSignatureProvider.kt
new file mode 100644
index 00000000..7ecd0389
--- /dev/null
+++ b/core/src/main/kotlin/Kotlin/KotlinDescriptorSignatureProvider.kt
@@ -0,0 +1,9 @@
+package org.jetbrains.dokka.Kotlin
+
+import org.jetbrains.dokka.Model.DescriptorSignatureProvider
+import org.jetbrains.dokka.signature
+import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
+
+class KotlinDescriptorSignatureProvider : DescriptorSignatureProvider {
+ override fun signature(forDesc: DeclarationDescriptor): String = forDesc.signature()
+} \ No newline at end of file
diff --git a/core/src/main/kotlin/Model/DescriptorSignatureProvider.kt b/core/src/main/kotlin/Model/DescriptorSignatureProvider.kt
new file mode 100644
index 00000000..85584e3c
--- /dev/null
+++ b/core/src/main/kotlin/Model/DescriptorSignatureProvider.kt
@@ -0,0 +1,7 @@
+package org.jetbrains.dokka.Model
+
+import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
+
+interface DescriptorSignatureProvider {
+ fun signature(forDesc: DeclarationDescriptor): String
+} \ No newline at end of file
diff --git a/core/src/main/kotlin/Utilities/DokkaModules.kt b/core/src/main/kotlin/Utilities/DokkaModules.kt
index 28c5dc45..dfb114ec 100644
--- a/core/src/main/kotlin/Utilities/DokkaModules.kt
+++ b/core/src/main/kotlin/Utilities/DokkaModules.kt
@@ -7,6 +7,7 @@ import com.google.inject.TypeLiteral
import com.google.inject.name.Names
import org.jetbrains.dokka.*
import org.jetbrains.dokka.Formats.FormatDescriptor
+import org.jetbrains.dokka.Model.DescriptorSignatureProvider
import org.jetbrains.dokka.Samples.SampleProcessingService
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import java.io.File
@@ -22,7 +23,7 @@ class DokkaAnalysisModule(val environment: AnalysisEnvironment,
binder.bind<DokkaLogger>().toInstance(logger)
val descriptor = ServiceLocator.lookup<FormatDescriptor>("format", options.outputFormat)
-
+ binder.bind<DescriptorSignatureProvider>().to(descriptor.descriptorSignatureProvider.java)
binder.registerCategory<LanguageService>("language")
binder.bind<PackageDocumentationBuilder>().to(descriptor.packageDocumentationBuilderClass.java)
binder.bind<JavaDocumentationBuilder>().to(descriptor.javaDocumentationBuilderClass.java)
diff --git a/core/src/main/kotlin/javadoc/dokka-adapters.kt b/core/src/main/kotlin/javadoc/dokka-adapters.kt
index 9555aeb9..c98a3801 100644
--- a/core/src/main/kotlin/javadoc/dokka-adapters.kt
+++ b/core/src/main/kotlin/javadoc/dokka-adapters.kt
@@ -4,6 +4,8 @@ import com.google.inject.Inject
import com.sun.tools.doclets.formats.html.HtmlDoclet
import org.jetbrains.dokka.*
import org.jetbrains.dokka.Formats.FormatDescriptor
+import org.jetbrains.dokka.Kotlin.KotlinAsJavaDescriptorSignatureProvider
+import org.jetbrains.dokka.Model.DescriptorSignatureProvider
import org.jetbrains.dokka.Samples.DefaultSampleProcessingService
import kotlin.reflect.KClass
@@ -36,4 +38,5 @@ class JavadocFormatDescriptor : FormatDescriptor {
override val javaDocumentationBuilderClass = JavaPsiDocumentationBuilder::class
override val sampleProcessingService = DefaultSampleProcessingService::class
override val packageListServiceClass: KClass<out PackageListService>? = null
+ override val descriptorSignatureProvider = KotlinAsJavaDescriptorSignatureProvider::class
}
diff --git a/core/src/test/kotlin/javadoc/JavadocTest.kt b/core/src/test/kotlin/javadoc/JavadocTest.kt
index 359c5fef..45c45aa4 100644
--- a/core/src/test/kotlin/javadoc/JavadocTest.kt
+++ b/core/src/test/kotlin/javadoc/JavadocTest.kt
@@ -151,6 +151,16 @@ class JavadocTest {
}
}
+ @Test
+ fun testCompanionMethodReference() {
+ verifyJavadoc("testdata/javadoc/companionMethodReference.kt") { doc ->
+ val classDoc = doc.classNamed("foo.TestClass")!!
+ val tag = classDoc.inlineTags().filterIsInstance<SeeMethodTagAdapter>().first()
+ assertEquals("TestClass.Companion", tag.referencedClassName())
+ assertEquals("test", tag.referencedMemberName())
+ }
+ }
+
private fun verifyJavadoc(name: String,
withJdk: Boolean = false,
withKotlinRuntime: Boolean = false,
diff --git a/core/testdata/javadoc/companionMethodReference.kt b/core/testdata/javadoc/companionMethodReference.kt
new file mode 100644
index 00000000..499e4492
--- /dev/null
+++ b/core/testdata/javadoc/companionMethodReference.kt
@@ -0,0 +1,13 @@
+package foo
+
+
+/**
+ * Linking to [test]
+ */
+class TestClass {
+
+ companion object {
+
+ @JvmStatic fun test(arg: String) {}
+ }
+} \ No newline at end of file
diff --git a/runners/cli/src/main/kotlin/cli/main.kt b/runners/cli/src/main/kotlin/cli/main.kt
index c12166c5..77ca57f6 100644
--- a/runners/cli/src/main/kotlin/cli/main.kt
+++ b/runners/cli/src/main/kotlin/cli/main.kt
@@ -139,8 +139,10 @@ object MainKt {
fun createClassLoaderWithTools(): ClassLoader {
val toolsJar = findToolsJar().canonicalFile.toURI().toURL()
+ val originalUrls = (javaClass.classLoader as? URLClassLoader)?.urLs
val dokkaJar = javaClass.protectionDomain.codeSource.location
- return URLClassLoader(arrayOf(toolsJar, dokkaJar), ClassLoader.getSystemClassLoader().parent)
+ val urls = if (originalUrls != null) arrayOf(toolsJar, *originalUrls) else arrayOf(toolsJar, dokkaJar)
+ return URLClassLoader(urls, ClassLoader.getSystemClassLoader().parent)
}
fun startWithToolsJar(args: Array<String>) {