From fc70184fee01430ed9c673336026c6ede8bff5f3 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 25 Feb 2015 20:06:16 +0100 Subject: working test for cross-language links in documentation (Kotlin class extends Java class) --- src/Kotlin/DocumentationBuilder.kt | 15 +++++++++++-- .../format/crossLanguage/kotlinExtendsJava.html | 26 ++++++++++++++++++++++ .../format/crossLanguage/kotlinExtendsJava/Bar.kt | 6 +++++ .../crossLanguage/kotlinExtendsJava/test/Foo.java | 6 +++++ test/src/TestAPI.kt | 4 +++- test/src/format/HtmlFormatTest.kt | 6 +++++ 6 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 test/data/format/crossLanguage/kotlinExtendsJava.html create mode 100644 test/data/format/crossLanguage/kotlinExtendsJava/Bar.kt create mode 100644 test/data/format/crossLanguage/kotlinExtendsJava/test/Foo.java diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt index 693f2675..1d7589a5 100644 --- a/src/Kotlin/DocumentationBuilder.kt +++ b/src/Kotlin/DocumentationBuilder.kt @@ -101,10 +101,10 @@ class DocumentationBuilder(val session: ResolveSession, fun resolveContentLink(descriptor: DeclarationDescriptor, href: String): ContentBlock { val symbols = resolveKDocLink(session, descriptor, null, href.split('.').toList()) + val symbol = findTargetSymbol(symbols) // 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 (symbols.isNotEmpty()) { - val symbol = symbols.first() + if (symbol != null) { return ContentNodeLazyLink(href, {() -> refGraph.lookup(symbol.signature()) }) } if ("/" in href) { @@ -113,6 +113,17 @@ class DocumentationBuilder(val session: ResolveSession, return ContentExternalLink("#") } + fun findTargetSymbol(symbols: Collection): DeclarationDescriptor? { + if (symbols.isEmpty()) { + return null + } + val symbol = symbols.first() + if (symbol is CallableMemberDescriptor && symbol.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) { + return symbol.getOverriddenDescriptors().firstOrNull() + } + return symbol + } + fun KDocSection.getTags(): Array = PsiTreeUtil.getChildrenOfType(this, javaClass()) ?: array() private fun Content.addTagToSeeAlso(descriptor: DeclarationDescriptor, seeTag: KDocTag) { diff --git a/test/data/format/crossLanguage/kotlinExtendsJava.html b/test/data/format/crossLanguage/kotlinExtendsJava.html new file mode 100644 index 00000000..49a9ff8f --- /dev/null +++ b/test/data/format/crossLanguage/kotlinExtendsJava.html @@ -0,0 +1,26 @@ + + +test / test.Bar + + +test / test / Bar
+
+

Bar

+class Bar : Foo
+

See xyzzy

+
+
+

Constructors

+ + + + + + + +
+<init> +public Bar()

See xyzzy

+
+ + diff --git a/test/data/format/crossLanguage/kotlinExtendsJava/Bar.kt b/test/data/format/crossLanguage/kotlinExtendsJava/Bar.kt new file mode 100644 index 00000000..102782f9 --- /dev/null +++ b/test/data/format/crossLanguage/kotlinExtendsJava/Bar.kt @@ -0,0 +1,6 @@ +package test + +/** + * See [xyzzy] + */ +class Bar(): Foo() diff --git a/test/data/format/crossLanguage/kotlinExtendsJava/test/Foo.java b/test/data/format/crossLanguage/kotlinExtendsJava/test/Foo.java new file mode 100644 index 00000000..7c143030 --- /dev/null +++ b/test/data/format/crossLanguage/kotlinExtendsJava/test/Foo.java @@ -0,0 +1,6 @@ +package test; + +public class Foo { + public void xyzzy() { + } +} diff --git a/test/src/TestAPI.kt b/test/src/TestAPI.kt index 7c6a2e73..6fc83279 100644 --- a/test/src/TestAPI.kt +++ b/test/src/TestAPI.kt @@ -30,6 +30,7 @@ public fun verifyModel(vararg files: String, verifier: (DocumentationModule) -> val stringRoot = PathManager.getResourceRoot(javaClass(), "/java/lang/String.class") addClasspath(File(stringRoot)) addSources(files.toList()) + addClasspath(files.map { File(it)}.filter { it.isDirectory()} ) } val options = DocumentationOptions(includeNonPublic = true, sourceLinks = listOf()) val documentation = buildDocumentationModule(environment, "test", options, logger = DokkaConsoleLogger) @@ -48,7 +49,8 @@ public fun verifyOutput(path: String, outputExtension: String, outputGenerator: verifyModel(path) { val output = StringBuilder() outputGenerator(it, output) - val expectedOutput = File(path.replace(".kt", outputExtension).replace(".java", outputExtension)).readText() + val ext = outputExtension.trimLeading(".") + val expectedOutput = File(path.replaceAfterLast(".", ext, path + "." + ext)).readText() assertEqualsIgnoringSeparators(expectedOutput, output.toString()) } } diff --git a/test/src/format/HtmlFormatTest.kt b/test/src/format/HtmlFormatTest.kt index 85badf8e..c81b2d85 100644 --- a/test/src/format/HtmlFormatTest.kt +++ b/test/src/format/HtmlFormatTest.kt @@ -117,4 +117,10 @@ public class HtmlFormatTest { htmlService.appendNodes(tempLocation, output, model.members.single().members.single { it.name == "Foo" }.members.filter { it.name == "foo" }) } } + + Test fun crossLanguageKotlinExtendsJava() { + verifyOutput("test/data/format/crossLanguage/kotlinExtendsJava", ".html") { model, output -> + htmlService.appendNodes(tempLocation, output, model.members.single().members.filter { it.name == "Bar" }) + } + } } -- cgit