From 0298076ba9cf22b70b6c85846ad555e201ee95ee Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Mon, 20 Nov 2017 22:38:11 +0300 Subject: Support receiver reference --- core/src/main/kotlin/Kotlin/DocumentationBuilder.kt | 2 ++ 1 file changed, 2 insertions(+) (limited to 'core/src/main/kotlin/Kotlin/DocumentationBuilder.kt') diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt index fddf0814..04993ad4 100644 --- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt @@ -746,6 +746,7 @@ class DocumentationBuilder val node = DocumentationNode(name.asString(), Content.Empty, NodeKind.Receiver) node.appendType(type) + register(this, node) return node } @@ -915,6 +916,7 @@ fun DeclarationDescriptor.signature(): String = when (this) { is FunctionDescriptor -> containingDeclaration.signature() + "$" + name + parameterSignature() is ValueParameterDescriptor -> containingDeclaration.signature() + "/" + name is TypeParameterDescriptor -> containingDeclaration.signature() + "*" + name + is ReceiverParameterDescriptor -> containingDeclaration.signature() + "*" + name else -> throw UnsupportedOperationException("Don't know how to calculate signature for $this") } -- cgit From 80bde3cb243b324df162a16d23f9dfd3e0ab2597 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Tue, 21 Nov 2017 15:05:04 +0300 Subject: Fix find node by signature when linking to extension with Type Param --- .../src/main/kotlin/Kotlin/DocumentationBuilder.kt | 29 ++++++++++++---------- core/src/test/kotlin/format/MarkdownFormatTest.kt | 4 +++ core/testdata/format/extensionScope.kt | 14 +++++++++++ core/testdata/format/extensionScope.md | 8 ++++++ 4 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 core/testdata/format/extensionScope.kt create mode 100644 core/testdata/format/extensionScope.md (limited to 'core/src/main/kotlin/Kotlin/DocumentationBuilder.kt') diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt index 04993ad4..177c6f50 100644 --- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt @@ -906,18 +906,21 @@ fun CallableMemberDescriptor.getExtensionClassDescriptor(): ClassifierDescriptor return null } -fun DeclarationDescriptor.signature(): String = when (this) { - is ClassDescriptor, - is PackageFragmentDescriptor, - is PackageViewDescriptor, - is TypeAliasDescriptor -> DescriptorUtils.getFqName(this).asString() - - is PropertyDescriptor -> containingDeclaration.signature() + "$" + name + receiverSignature() - is FunctionDescriptor -> containingDeclaration.signature() + "$" + name + parameterSignature() - is ValueParameterDescriptor -> containingDeclaration.signature() + "/" + name - is TypeParameterDescriptor -> containingDeclaration.signature() + "*" + name - is ReceiverParameterDescriptor -> containingDeclaration.signature() + "*" + name - else -> throw UnsupportedOperationException("Don't know how to calculate signature for $this") +fun DeclarationDescriptor.signature(): String { + if (this != original) return original.signature() + return when (this) { + is ClassDescriptor, + is PackageFragmentDescriptor, + is PackageViewDescriptor, + is TypeAliasDescriptor -> DescriptorUtils.getFqName(this).asString() + + is PropertyDescriptor -> containingDeclaration.signature() + "$" + name + receiverSignature() + is FunctionDescriptor -> containingDeclaration.signature() + "$" + name + parameterSignature() + is ValueParameterDescriptor -> containingDeclaration.signature() + "/" + name + is TypeParameterDescriptor -> containingDeclaration.signature() + "*" + name + is ReceiverParameterDescriptor -> containingDeclaration.signature() + "*" + name + else -> throw UnsupportedOperationException("Don't know how to calculate signature for $this") + } } fun PropertyDescriptor.receiverSignature(): String { @@ -934,7 +937,7 @@ fun CallableMemberDescriptor.parameterSignature(): String { if (extensionReceiver != null) { params.add(0, extensionReceiver.type) } - return "(" + params.map { it.signature() }.joinToString() + ")" + return params.joinToString(prefix = "(", postfix = ")") { it.signature() } } fun KotlinType.signature(): String { diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt index 97a8ad4b..5fbd80fb 100644 --- a/core/src/test/kotlin/format/MarkdownFormatTest.kt +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -384,6 +384,10 @@ class MarkdownFormatTest { verifyMarkdownNode("receiverReference") } + @Test fun extensionScope() { + verifyMarkdownNodeByName("extensionScope", "test") + } + private fun buildMultiplePlatforms(path: String): DocumentationModule { val module = DocumentationModule("test") val options = DocumentationOptions("", "html", generateIndexPages = false, noStdlibLink = true) diff --git a/core/testdata/format/extensionScope.kt b/core/testdata/format/extensionScope.kt new file mode 100644 index 00000000..9f3130b8 --- /dev/null +++ b/core/testdata/format/extensionScope.kt @@ -0,0 +1,14 @@ +/** + * Test class with Type-parameter + */ +class Foo + +/** + * Some extension on Foo + */ +fun Foo.ext() {} + +/** + * Correct link: [Foo.ext] + */ +fun test() {} \ No newline at end of file diff --git a/core/testdata/format/extensionScope.md b/core/testdata/format/extensionScope.md new file mode 100644 index 00000000..3515ed84 --- /dev/null +++ b/core/testdata/format/extensionScope.md @@ -0,0 +1,8 @@ +[test](test/index) / [test](test/test) + +# test + +`fun test(): Unit` + +Correct link: [Foo.ext](test/ext) + -- cgit From ebcea5c3ad6248c5a02adc5740103a23a5108c58 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Tue, 21 Nov 2017 15:24:32 +0300 Subject: Fix find node by signature when referencing type parameter --- core/src/main/kotlin/Kotlin/DocumentationBuilder.kt | 1 + core/src/test/kotlin/format/MarkdownFormatTest.kt | 4 ++++ core/src/test/kotlin/model/FunctionTest.kt | 14 ++++++++------ core/testdata/format/annotatedTypeParameter.md | 2 +- core/testdata/format/extensionFunctionParameter.md | 2 +- core/testdata/format/genericInheritedExtensions.md | 6 +++--- core/testdata/format/htmlEscaping.html | 2 +- core/testdata/format/nullability.md | 2 +- core/testdata/format/parameterAnchor.html | 2 +- core/testdata/format/receiverParameterTypeBound.md | 2 +- core/testdata/format/summarizeSignatures.md | 2 +- core/testdata/format/typeAliases.md | 4 ++-- core/testdata/format/typeAliases.package.md | 4 ++-- core/testdata/format/typeParameterBounds.md | 2 +- core/testdata/format/typeParameterReference.kt | 6 ++++++ core/testdata/format/typeParameterReference.md | 8 ++++++++ core/testdata/format/typeProjectionVariance.md | 2 +- 17 files changed, 43 insertions(+), 22 deletions(-) create mode 100644 core/testdata/format/typeParameterReference.kt create mode 100644 core/testdata/format/typeParameterReference.md (limited to 'core/src/main/kotlin/Kotlin/DocumentationBuilder.kt') diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt index 177c6f50..856127d3 100644 --- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt @@ -726,6 +726,7 @@ class DocumentationBuilder } node.appendType(constraint, NodeKind.UpperBound) } + register(this, node) return node } diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt index 5fbd80fb..a2891c47 100644 --- a/core/src/test/kotlin/format/MarkdownFormatTest.kt +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -388,6 +388,10 @@ class MarkdownFormatTest { verifyMarkdownNodeByName("extensionScope", "test") } + @Test fun typeParameterReference() { + verifyMarkdownNode("typeParameterReference") + } + private fun buildMultiplePlatforms(path: String): DocumentationModule { val module = DocumentationModule("test") val options = DocumentationOptions("", "html", generateIndexPages = false, noStdlibLink = true) diff --git a/core/src/test/kotlin/model/FunctionTest.kt b/core/src/test/kotlin/model/FunctionTest.kt index 065decef..32910682 100644 --- a/core/src/test/kotlin/model/FunctionTest.kt +++ b/core/src/test/kotlin/model/FunctionTest.kt @@ -5,6 +5,7 @@ import org.jetbrains.dokka.NodeKind import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import org.junit.Test +import kotlin.test.assertNotNull class FunctionTest { @Test fun function() { @@ -83,9 +84,10 @@ class FunctionTest { assertEquals(NodeKind.Function, kind) assertEquals("generic function", content.summary.toTestString()) - assertEquals("public", details.elementAt(0).name) - assertEquals("final", details.elementAt(1).name) - with(details.elementAt(3)) { + val functionDetails = details + assertEquals("public", functionDetails.elementAt(0).name) + assertEquals("final", functionDetails.elementAt(1).name) + with(functionDetails.elementAt(3)) { assertEquals("T", name) assertEquals(NodeKind.TypeParameter, kind) assertEquals(Content.Empty, content) @@ -95,19 +97,19 @@ class FunctionTest { assertEquals(Content.Empty, content) assertTrue(details.none()) assertTrue(members.none()) - assertTrue(links.none()) + assertTrue(links.singleOrNull() == functionDetails.elementAt(4)) } assertTrue(members.none()) assertTrue(links.none()) } - with(details.elementAt(4)) { + with(functionDetails.elementAt(4)) { assertEquals("R", name) assertEquals(NodeKind.TypeParameter, kind) assertEquals(Content.Empty, content) assertTrue(members.none()) assertTrue(links.none()) } - assertEquals("Unit", details.elementAt(5).name) + assertEquals("Unit", functionDetails.elementAt(5).name) assertTrue(members.none()) assertTrue(links.none()) diff --git a/core/testdata/format/annotatedTypeParameter.md b/core/testdata/format/annotatedTypeParameter.md index 0aa1b9d7..aa8b8592 100644 --- a/core/testdata/format/annotatedTypeParameter.md +++ b/core/testdata/format/annotatedTypeParameter.md @@ -2,4 +2,4 @@ # containsAll -`fun containsAll(elements: Collection<@UnsafeVariance E>): @UnsafeVariance E` \ No newline at end of file +`fun containsAll(elements: Collection<@UnsafeVariance `[`E`](test/contains-all#E)`>): @UnsafeVariance `[`E`](test/contains-all#E) \ No newline at end of file diff --git a/core/testdata/format/extensionFunctionParameter.md b/core/testdata/format/extensionFunctionParameter.md index b459d49e..501d731d 100644 --- a/core/testdata/format/extensionFunctionParameter.md +++ b/core/testdata/format/extensionFunctionParameter.md @@ -2,4 +2,4 @@ # apply -`inline fun T.apply(f: T.() -> Unit): T` \ No newline at end of file +`inline fun `[`T`](test/apply#T)`.apply(f: `[`T`](test/apply#T)`.() -> Unit): `[`T`](test/apply#T) \ No newline at end of file diff --git a/core/testdata/format/genericInheritedExtensions.md b/core/testdata/format/genericInheritedExtensions.md index a3091aeb..163ff0c9 100644 --- a/core/testdata/format/genericInheritedExtensions.md +++ b/core/testdata/format/genericInheritedExtensions.md @@ -2,7 +2,7 @@ # Bar -`class Bar : `[`Foo`](test/-foo/index)`` +`class Bar : `[`Foo`](test/-foo/index)`<`[`T`](test/-bar/index#T)`>` ### Constructors @@ -10,6 +10,6 @@ ### Extension Functions -| [first](test/first) | `fun `[`Foo`](test/-foo/index)`.first(): Unit` | -| [second](test/second) | `fun `[`Bar`](test/-bar/index)`.second(): Unit` | +| [first](test/first) | `fun `[`Foo`](test/-foo/index)`<`[`T`](test/first#T)`>.first(): Unit` | +| [second](test/second) | `fun `[`Bar`](test/-bar/index)`<`[`T`](test/second#T)`>.second(): Unit` | diff --git a/core/testdata/format/htmlEscaping.html b/core/testdata/format/htmlEscaping.html index fd9a3235..17d48161 100644 --- a/core/testdata/format/htmlEscaping.html +++ b/core/testdata/format/htmlEscaping.html @@ -8,7 +8,7 @@

x

-fun <T> x(): T? +fun <T> x(): T?

Special characters: < is "less than", > is "greater than", & is "ampersand"

diff --git a/core/testdata/format/nullability.md b/core/testdata/format/nullability.md index 6a4c3761..014eb485 100644 --- a/core/testdata/format/nullability.md +++ b/core/testdata/format/nullability.md @@ -10,5 +10,5 @@ ### Functions -| [foo](test/-c/foo) | `fun foo(): Comparable?` | +| [foo](test/-c/foo) | `fun foo(): Comparable<`[`T`](test/-c/index#T)`>?` | diff --git a/core/testdata/format/parameterAnchor.html b/core/testdata/format/parameterAnchor.html index ecb89fe6..3ffcf595 100644 --- a/core/testdata/format/parameterAnchor.html +++ b/core/testdata/format/parameterAnchor.html @@ -8,7 +8,7 @@

processFiles

-fun <T> processFiles(processor: () -> T): List<T> +fun <T> processFiles(processor: () -> T): List<T>

Runs processor for each file and collects its results into single list

Parameters

diff --git a/core/testdata/format/receiverParameterTypeBound.md b/core/testdata/format/receiverParameterTypeBound.md index 8a8c4220..9c767449 100644 --- a/core/testdata/format/receiverParameterTypeBound.md +++ b/core/testdata/format/receiverParameterTypeBound.md @@ -10,5 +10,5 @@ ### Extension Functions -| [xyzzy](test/xyzzy) | `fun T.xyzzy(): Unit` | +| [xyzzy](test/xyzzy) | `fun `[`T`](test/xyzzy#T)`.xyzzy(): Unit` | diff --git a/core/testdata/format/summarizeSignatures.md b/core/testdata/format/summarizeSignatures.md index d37f2301..c1830fb5 100644 --- a/core/testdata/format/summarizeSignatures.md +++ b/core/testdata/format/summarizeSignatures.md @@ -10,5 +10,5 @@ ### Functions -| [foo](test/kotlin/foo) | `fun any_array.foo(predicate: (T) -> Boolean): Boolean`
Returns true if foo. | +| [foo](test/kotlin/foo) | `fun any_array.foo(predicate: (`[`T`](test/kotlin/foo#T)`) -> Boolean): Boolean`
Returns true if foo. | diff --git a/core/testdata/format/typeAliases.md b/core/testdata/format/typeAliases.md index 55e9317e..2a813c32 100644 --- a/core/testdata/format/typeAliases.md +++ b/core/testdata/format/typeAliases.md @@ -30,11 +30,11 @@ # H -`typealias H = `[`C`](test/-c/index)``[test](test/index) / [I](test/-i) +`typealias H = `[`C`](test/-c/index)`<`[`T`](test/-h#T)`>`[test](test/index) / [I](test/-i) # I -`typealias I = `[`H`](test/-h)``[test](test/index) / [J](test/-j) +`typealias I = `[`H`](test/-h)`<`[`T`](test/-i#T)`>`[test](test/index) / [J](test/-j) # J diff --git a/core/testdata/format/typeAliases.package.md b/core/testdata/format/typeAliases.package.md index 0eff1ed5..9407588b 100644 --- a/core/testdata/format/typeAliases.package.md +++ b/core/testdata/format/typeAliases.package.md @@ -14,8 +14,8 @@ | [E](test/-e) | `typealias E = `[`D`](test/-d) | | [F](test/-f) | `typealias F = (`[`A`](test/-a/index)`) -> `[`B`](test/-b/index) | | [G](test/-g) | `typealias G = `[`C`](test/-c/index)`<`[`A`](test/-a/index)`>` | -| [H](test/-h) | `typealias H = `[`C`](test/-c/index)`` | -| [I](test/-i) | `typealias I = `[`H`](test/-h)`` | +| [H](test/-h) | `typealias H = `[`C`](test/-c/index)`<`[`T`](test/-h#T)`>` | +| [I](test/-i) | `typealias I = `[`H`](test/-h)`<`[`T`](test/-i#T)`>` | | [J](test/-j) | `typealias J = `[`H`](test/-h)`<`[`A`](test/-a/index)`>` | | [K](test/-k) | `typealias K = `[`H`](test/-h)`<`[`J`](test/-j)`>` | | [L](test/-l) | `typealias L = (`[`K`](test/-k)`, `[`B`](test/-b/index)`) -> `[`J`](test/-j) | diff --git a/core/testdata/format/typeParameterBounds.md b/core/testdata/format/typeParameterBounds.md index 58df82a3..8f369ed6 100644 --- a/core/testdata/format/typeParameterBounds.md +++ b/core/testdata/format/typeParameterBounds.md @@ -2,7 +2,7 @@ # generic -`fun generic(): Unit` +`fun generic(): Unit` generic function diff --git a/core/testdata/format/typeParameterReference.kt b/core/testdata/format/typeParameterReference.kt new file mode 100644 index 00000000..f196112d --- /dev/null +++ b/core/testdata/format/typeParameterReference.kt @@ -0,0 +1,6 @@ +/** + * Correct ref to [T] + */ +fun T.tt() { + println("T.tt") +} \ No newline at end of file diff --git a/core/testdata/format/typeParameterReference.md b/core/testdata/format/typeParameterReference.md new file mode 100644 index 00000000..ea49d48a --- /dev/null +++ b/core/testdata/format/typeParameterReference.md @@ -0,0 +1,8 @@ +[test](test/index) / [tt](test/tt) + +# tt + +`fun `[`T`](test/tt#T)`.tt(): Unit` + +Correct ref to [T](test/tt#T) + diff --git a/core/testdata/format/typeProjectionVariance.md b/core/testdata/format/typeProjectionVariance.md index 5b8fc190..072b9fc7 100644 --- a/core/testdata/format/typeProjectionVariance.md +++ b/core/testdata/format/typeProjectionVariance.md @@ -2,5 +2,5 @@ ### Extensions for kotlin.Array -| [foo](test/kotlin.-array/foo) | `fun Array.foo(): Unit` | +| [foo](test/kotlin.-array/foo) | `fun Array.foo(): Unit` | -- cgit From b6d79cf83917e6a8c843209df3ffa7d9e54d0917 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Tue, 21 Nov 2017 17:18:25 +0300 Subject: Do not suppress Companions when it's extends/implements something --- core/src/main/kotlin/Kotlin/DocumentationBuilder.kt | 8 +++++--- core/testdata/format/inheritedCompanionObjectProperties.md | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'core/src/main/kotlin/Kotlin/DocumentationBuilder.kt') diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt index 856127d3..24840a9d 100644 --- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt @@ -20,9 +20,7 @@ import org.jetbrains.kotlin.psi.KtModifierListOwner import org.jetbrains.kotlin.psi.KtParameter import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.constants.ConstantValue -import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns -import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe -import org.jetbrains.kotlin.resolve.descriptorUtil.isDocumentedAnnotation +import org.jetbrains.kotlin.resolve.descriptorUtil.* import org.jetbrains.kotlin.resolve.findTopMostOverriddenDescriptors import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolver import org.jetbrains.kotlin.resolve.source.PsiSourceElement @@ -576,6 +574,10 @@ class DocumentationBuilder descriptorsToDocument.mapTo(result) { ClassMember(it, inheritedLinkKind = RefKind.InheritedCompanionObjectMember) } + + if (companionObjectDescriptor.getAllSuperclassesWithoutAny().isNotEmpty()) { + result += ClassMember(companionObjectDescriptor) + } } return result } diff --git a/core/testdata/format/inheritedCompanionObjectProperties.md b/core/testdata/format/inheritedCompanionObjectProperties.md index b3b3230e..db764ff0 100644 --- a/core/testdata/format/inheritedCompanionObjectProperties.md +++ b/core/testdata/format/inheritedCompanionObjectProperties.md @@ -4,6 +4,10 @@ `class C : `[`A`](test/-a/index) +### Types + +| [Companion](test/-c/-companion/index) | `companion object Companion : `[`B`](test/-b/index) | + ### Constructors | [<init>](test/-c/-init-) | `C()` | -- cgit From 454b4a4c8490a04fcfe17309596c6316cd321113 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Tue, 21 Nov 2017 19:46:20 +0300 Subject: Fix suppressing of companion when it implements some interface --- core/src/main/kotlin/Kotlin/DocumentationBuilder.kt | 3 ++- core/src/test/kotlin/format/MarkdownFormatTest.kt | 4 ++++ core/testdata/format/companionImplements.kt | 9 +++++++++ core/testdata/format/companionImplements.md | 16 ++++++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 core/testdata/format/companionImplements.kt create mode 100644 core/testdata/format/companionImplements.md (limited to 'core/src/main/kotlin/Kotlin/DocumentationBuilder.kt') diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt index 24840a9d..0f6f217e 100644 --- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt @@ -575,7 +575,8 @@ class DocumentationBuilder ClassMember(it, inheritedLinkKind = RefKind.InheritedCompanionObjectMember) } - if (companionObjectDescriptor.getAllSuperclassesWithoutAny().isNotEmpty()) { + if (companionObjectDescriptor.getAllSuperclassesWithoutAny().isNotEmpty() + || companionObjectDescriptor.getSuperInterfaces().isNotEmpty()) { result += ClassMember(companionObjectDescriptor) } } diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt index f572922c..d2ab5b5c 100644 --- a/core/src/test/kotlin/format/MarkdownFormatTest.kt +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -396,6 +396,10 @@ class MarkdownFormatTest { verifyMarkdownNodeByName("notPublishedTypeAliasAutoExpansion", "foo", includeNonPublic = false) } + @Test fun companionImplements() { + verifyMarkdownNodeByName("companionImplements", "Foo") + } + private fun buildMultiplePlatforms(path: String): DocumentationModule { val module = DocumentationModule("test") val options = DocumentationOptions("", "html", generateIndexPages = false, noStdlibLink = true) diff --git a/core/testdata/format/companionImplements.kt b/core/testdata/format/companionImplements.kt new file mode 100644 index 00000000..154ef9b1 --- /dev/null +++ b/core/testdata/format/companionImplements.kt @@ -0,0 +1,9 @@ + +interface Bar + +/** + * Correct ref [Foo.Companion] + */ +class Foo { + companion object : Bar +} \ No newline at end of file diff --git a/core/testdata/format/companionImplements.md b/core/testdata/format/companionImplements.md new file mode 100644 index 00000000..8a93ed6b --- /dev/null +++ b/core/testdata/format/companionImplements.md @@ -0,0 +1,16 @@ +[test](test/index) / [Foo](test/-foo/index) + +# Foo + +`class Foo` + +Correct ref [Foo.Companion](test/-foo/-companion) + +### Types + +| [Companion](test/-foo/-companion) | `companion object Companion : `[`Bar`](test/-bar) | + +### Constructors + +| [<init>](test/-foo/-init-) | `Foo()`
Correct ref [Foo.Companion](test/-foo/-companion) | + -- cgit From c821247cf3c342788e372470cf9c3ff9c2665a7f Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Wed, 22 Nov 2017 17:52:32 +0300 Subject: Use / for receiver parameter signature --- core/src/main/kotlin/Kotlin/DocumentationBuilder.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/src/main/kotlin/Kotlin/DocumentationBuilder.kt') diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt index 0f6f217e..8f8c08a4 100644 --- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt @@ -922,7 +922,7 @@ fun DeclarationDescriptor.signature(): String { is FunctionDescriptor -> containingDeclaration.signature() + "$" + name + parameterSignature() is ValueParameterDescriptor -> containingDeclaration.signature() + "/" + name is TypeParameterDescriptor -> containingDeclaration.signature() + "*" + name - is ReceiverParameterDescriptor -> containingDeclaration.signature() + "*" + name + is ReceiverParameterDescriptor -> containingDeclaration.signature() + "/" + name else -> throw UnsupportedOperationException("Don't know how to calculate signature for $this") } } -- cgit From f941d6adefa71d2b3b1cc69120edf7eae70187ba Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Fri, 6 Oct 2017 14:14:09 +0100 Subject: Add new "suppress" per-package option. --- .../kotlin/Java/JavaPsiDocumentationBuilder.kt | 4 ++- .../src/main/kotlin/Kotlin/DocumentationBuilder.kt | 2 +- core/src/test/kotlin/TestAPI.kt | 2 ++ core/src/test/kotlin/model/PackageTest.kt | 35 ++++++++++++++++++++-- core/testdata/packages/classInPackage.kt | 3 ++ 5 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 core/testdata/packages/classInPackage.kt (limited to 'core/src/main/kotlin/Kotlin/DocumentationBuilder.kt') diff --git a/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt b/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt index 6b1f8cb4..cf2b0514 100644 --- a/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt +++ b/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt @@ -58,7 +58,7 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder { } override fun appendFile(file: PsiJavaFile, module: DocumentationModule, packageContent: Map) { - if (file.classes.all { skipElement(it) }) { + if (skipFile(file) || file.classes.all { skipElement(it) }) { return } val packageNode = module.findOrCreatePackageNode(file.packageName, emptyMap(), refGraph) @@ -132,6 +132,8 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder { } } + private fun skipFile(javaFile: PsiJavaFile): Boolean = options.effectivePackageOptions(javaFile.packageName).suppress + private fun skipElement(element: Any) = skipElementByVisibility(element) || hasSuppressDocTag(element) || diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt index 8f8c08a4..8d34a6f1 100644 --- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt @@ -790,7 +790,7 @@ fun DeclarationDescriptor.isDocumented(options: DocumentationOptions): Boolean { return (options.effectivePackageOptions(fqNameSafe).includeNonPublic || this !is MemberDescriptor || this.visibility in visibleToDocumentation) && - !isDocumentationSuppressed(options) && + !isDocumentationSuppressed(options) && !options.effectivePackageOptions(fqNameSafe).suppress && (!options.effectivePackageOptions(fqNameSafe).skipDeprecated || !isDeprecated()) } diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt index 6c62c998..8bbeb2f2 100644 --- a/core/src/test/kotlin/TestAPI.kt +++ b/core/src/test/kotlin/TestAPI.kt @@ -24,6 +24,7 @@ fun verifyModel(vararg roots: ContentRoot, withKotlinRuntime: Boolean = false, format: String = "html", includeNonPublic: Boolean = true, + perPackageOptions: List = emptyList(), verifier: (DocumentationModule) -> Unit) { val documentation = DocumentationModule("test") @@ -32,6 +33,7 @@ fun verifyModel(vararg roots: ContentRoot, skipEmptyPackages = false, includeRootPackage = true, sourceLinks = listOf(), + perPackageOptions = perPackageOptions, generateIndexPages = false, noStdlibLink = true, cacheRoot = "default") diff --git a/core/src/test/kotlin/model/PackageTest.kt b/core/src/test/kotlin/model/PackageTest.kt index 97810e80..052f0d28 100644 --- a/core/src/test/kotlin/model/PackageTest.kt +++ b/core/src/test/kotlin/model/PackageTest.kt @@ -2,10 +2,10 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.Content import org.jetbrains.dokka.NodeKind +import org.jetbrains.dokka.PackageOptionsImpl import org.jetbrains.kotlin.config.KotlinSourceRoot +import org.junit.Assert.* import org.junit.Test -import org.junit.Assert.assertEquals -import org.junit.Assert.assertTrue public class PackageTest { @Test fun rootPackage() { @@ -83,4 +83,33 @@ public class PackageTest { } } } -} \ No newline at end of file + + @Test fun classAtPackageLevel() { + verifyModel(KotlinSourceRoot("testdata/packages/classInPackage.kt")) { model -> + assertEquals(1, model.members.count()) + with(model.members.elementAt(0)) { + assertEquals(NodeKind.Package, kind) + assertEquals("simple.name", name) + assertEquals(Content.Empty, content) + assertTrue(details.none()) + assertEquals(1, members.size) + assertTrue(links.none()) + } + } + } + + @Test fun suppressAtPackageLevel() { + verifyModel(KotlinSourceRoot("testdata/packages/classInPackage.kt"), + perPackageOptions = listOf(PackageOptionsImpl(prefix = "simple.name", suppress = true))) { model -> + assertEquals(1, model.members.count()) + with(model.members.elementAt(0)) { + assertEquals(NodeKind.Package, kind) + assertEquals("simple.name", name) + assertEquals(Content.Empty, content) + assertTrue(details.none()) + assertTrue(members.none()) + assertTrue(links.none()) + } + } + } +} diff --git a/core/testdata/packages/classInPackage.kt b/core/testdata/packages/classInPackage.kt new file mode 100644 index 00000000..b22273af --- /dev/null +++ b/core/testdata/packages/classInPackage.kt @@ -0,0 +1,3 @@ +package simple.name + +class Foo {} -- cgit From dc7ddcc57f07fc72e2c42f820b7852dd555a2891 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Thu, 23 Nov 2017 15:36:01 +0300 Subject: Cleanup GH-222 a bit --- core/src/main/kotlin/Kotlin/DocumentationBuilder.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'core/src/main/kotlin/Kotlin/DocumentationBuilder.kt') diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt index 8d34a6f1..2998e314 100644 --- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt @@ -789,9 +789,9 @@ val visibleToDocumentation = setOf(Visibilities.PROTECTED, Visibilities.PUBLIC) fun DeclarationDescriptor.isDocumented(options: DocumentationOptions): Boolean { return (options.effectivePackageOptions(fqNameSafe).includeNonPublic || this !is MemberDescriptor - || this.visibility in visibleToDocumentation) && - !isDocumentationSuppressed(options) && !options.effectivePackageOptions(fqNameSafe).suppress && - (!options.effectivePackageOptions(fqNameSafe).skipDeprecated || !isDeprecated()) + || this.visibility in visibleToDocumentation) + && !isDocumentationSuppressed(options) + && (!options.effectivePackageOptions(fqNameSafe).skipDeprecated || !isDeprecated()) } private fun DeclarationDescriptor.isGenerated() = this is CallableMemberDescriptor && kind != CallableMemberDescriptor.Kind.DECLARATION @@ -861,6 +861,8 @@ fun AnnotationDescriptor.mustBeDocumented(): Boolean { fun DeclarationDescriptor.isDocumentationSuppressed(options: DocumentationOptions): Boolean { + if (options.effectivePackageOptions(fqNameSafe).suppress) return true + val path = this.findPsi()?.containingFile?.virtualFile?.path if (path != null) { if (File(path).absoluteFile in options.suppressedFiles) return true -- cgit From 13c4cb93f55693f3bfa396ccad9549d8654ec3f9 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Mon, 27 Nov 2017 16:05:59 +0300 Subject: Add language version arguments --- .../main/kotlin/Analysis/AnalysisEnvironment.kt | 9 +++- core/src/main/kotlin/DokkaBootstrapImpl.kt | 2 + core/src/main/kotlin/Generation/DokkaGenerator.kt | 2 + .../main/kotlin/Generation/configurationImpl.kt | 46 +++++++++++---------- .../src/main/kotlin/Kotlin/DocumentationBuilder.kt | 2 + core/src/test/kotlin/TestAPI.kt | 13 ++++-- .../test/kotlin/format/KotlinWebSiteFormatTest.kt | 9 +++- .../kotlin/format/KotlinWebSiteHtmlFormatTest.kt | 9 +++- core/src/test/kotlin/format/MarkdownFormatTest.kt | 18 +++++++- .../kotlin/org/jetbrains/dokka/configuration.kt | 48 ++++++++++++---------- runners/ant/src/main/kotlin/ant/dokka.kt | 11 ++++- runners/cli/src/main/kotlin/cli/main.kt | 11 ++++- runners/gradle-plugin/src/main/kotlin/main.kt | 14 ++++++- runners/maven-plugin/src/main/kotlin/DokkaMojo.kt | 10 ++++- 14 files changed, 147 insertions(+), 57 deletions(-) (limited to 'core/src/main/kotlin/Kotlin/DocumentationBuilder.kt') diff --git a/core/src/main/kotlin/Analysis/AnalysisEnvironment.kt b/core/src/main/kotlin/Analysis/AnalysisEnvironment.kt index 3eb235e5..003c6835 100644 --- a/core/src/main/kotlin/Analysis/AnalysisEnvironment.kt +++ b/core/src/main/kotlin/Analysis/AnalysisEnvironment.kt @@ -69,7 +69,6 @@ class AnalysisEnvironment(val messageCollector: MessageCollector) : Disposable { val projectFileIndex = CoreProjectFileIndex(environment.project, environment.configuration.getList(JVMConfigurationKeys.CONTENT_ROOTS)) - environment.configuration.put(CommonConfigurationKeys.LANGUAGE_VERSION_SETTINGS, LanguageVersionSettingsImpl.DEFAULT) val moduleManager = object : CoreModuleManager(environment.project, this) { override fun getModules(): Array = arrayOf(projectFileIndex.module) @@ -142,7 +141,7 @@ class AnalysisEnvironment(val messageCollector: MessageCollector) : Disposable { }, CompilerEnvironment, packagePartProviderFactory = { info, content -> - JvmPackagePartProvider(LanguageVersionSettingsImpl.DEFAULT, content.moduleContentScope).apply { + JvmPackagePartProvider(configuration.languageVersionSettings, content.moduleContentScope).apply { addRoots(javaRoots) } }, @@ -157,6 +156,12 @@ class AnalysisEnvironment(val messageCollector: MessageCollector) : Disposable { return DokkaResolutionFacade(environment.project, moduleDescriptor, resolverForModule) } + fun loadLanguageVersionSettings(languageVersionString: String?, apiVersionString: String?) { + val languageVersion = LanguageVersion.fromVersionString(languageVersionString) ?: LanguageVersion.LATEST_STABLE + val apiVersion = apiVersionString?.let { ApiVersion.parse(it) } ?: ApiVersion.createByLanguageVersion(languageVersion) + configuration.languageVersionSettings = LanguageVersionSettingsImpl(languageVersion, apiVersion) + } + /** * Classpath for this environment. */ diff --git a/core/src/main/kotlin/DokkaBootstrapImpl.kt b/core/src/main/kotlin/DokkaBootstrapImpl.kt index 0aea4422..126a0175 100644 --- a/core/src/main/kotlin/DokkaBootstrapImpl.kt +++ b/core/src/main/kotlin/DokkaBootstrapImpl.kt @@ -66,6 +66,8 @@ class DokkaBootstrapImpl : DokkaBootstrap { perPackageOptions, externalDocumentationLinks, noStdlibLink, + languageVersion, + apiVersion, cacheRoot, suppressedFiles.map { File(it) } ) diff --git a/core/src/main/kotlin/Generation/DokkaGenerator.kt b/core/src/main/kotlin/Generation/DokkaGenerator.kt index 17b6b156..09e5cedf 100644 --- a/core/src/main/kotlin/Generation/DokkaGenerator.kt +++ b/core/src/main/kotlin/Generation/DokkaGenerator.kt @@ -94,6 +94,8 @@ class DokkaGenerator(val logger: DokkaLogger, addSources(sourcePaths) addSources(this@DokkaGenerator.samples) + + loadLanguageVersionSettings(options.languageVersion, options.apiVersion) } return environment diff --git a/core/src/main/kotlin/Generation/configurationImpl.kt b/core/src/main/kotlin/Generation/configurationImpl.kt index befe7e72..34d4154e 100644 --- a/core/src/main/kotlin/Generation/configurationImpl.kt +++ b/core/src/main/kotlin/Generation/configurationImpl.kt @@ -35,24 +35,28 @@ data class PackageOptionsImpl(override val prefix: String, override val skipDeprecated: Boolean = false, override val suppress: Boolean = false) : DokkaConfiguration.PackageOptions -data class DokkaConfigurationImpl(override val moduleName: String, - override val classpath: List, - override val sourceRoots: List, - override val samples: List, - override val includes: List, - override val outputDir: String, - override val format: String, - override val includeNonPublic: Boolean, - override val includeRootPackage: Boolean, - override val reportUndocumented: Boolean, - override val skipEmptyPackages: Boolean, - override val skipDeprecated: Boolean, - override val jdkVersion: Int, - override val generateIndexPages: Boolean, - override val sourceLinks: List, - override val impliedPlatforms: List, - override val perPackageOptions: List, - override val externalDocumentationLinks: List, - override val noStdlibLink: Boolean, - override val cacheRoot: String?, - override val suppressedFiles: List) : DokkaConfiguration \ No newline at end of file +data class DokkaConfigurationImpl( + override val moduleName: String, + override val classpath: List, + override val sourceRoots: List, + override val samples: List, + override val includes: List, + override val outputDir: String, + override val format: String, + override val includeNonPublic: Boolean, + override val includeRootPackage: Boolean, + override val reportUndocumented: Boolean, + override val skipEmptyPackages: Boolean, + override val skipDeprecated: Boolean, + override val jdkVersion: Int, + override val generateIndexPages: Boolean, + override val sourceLinks: List, + override val impliedPlatforms: List, + override val perPackageOptions: List, + override val externalDocumentationLinks: List, + override val noStdlibLink: Boolean, + override val cacheRoot: String?, + override val suppressedFiles: List, + override val languageVersion: String?, + override val apiVersion: String? +) : DokkaConfiguration \ 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 2998e314..61bf50d6 100644 --- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt @@ -48,6 +48,8 @@ class DocumentationOptions(val outputDir: String, perPackageOptions: List = emptyList(), externalDocumentationLinks: List = emptyList(), noStdlibLink: Boolean, + val languageVersion: String?, + val apiVersion: String?, cacheRoot: String? = null, val suppressedFiles: List = emptyList()) { init { diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt index 8bbeb2f2..ff8a5260 100644 --- a/core/src/test/kotlin/TestAPI.kt +++ b/core/src/test/kotlin/TestAPI.kt @@ -28,15 +28,20 @@ fun verifyModel(vararg roots: ContentRoot, verifier: (DocumentationModule) -> Unit) { val documentation = DocumentationModule("test") - val options = DocumentationOptions("", format, + val options = DocumentationOptions( + "", + format, includeNonPublic = includeNonPublic, skipEmptyPackages = false, includeRootPackage = true, - sourceLinks = listOf(), + sourceLinks = listOf(), perPackageOptions = perPackageOptions, generateIndexPages = false, noStdlibLink = true, - cacheRoot = "default") + cacheRoot = "default", + languageVersion = null, + apiVersion = null + ) appendDocumentation(documentation, *roots, withJdk = withJdk, @@ -88,6 +93,8 @@ fun appendDocumentation(documentation: DocumentationModule, addClasspath(File(kotlinStrictfpRoot)) } addRoots(roots.toList()) + + loadLanguageVersionSettings(options.languageVersion, options.apiVersion) } val defaultPlatformsProvider = object : DefaultPlatformsProvider { override fun getDefaultPlatforms(descriptor: DeclarationDescriptor) = defaultPlatforms diff --git a/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt index f4ca2982..af44b048 100644 --- a/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt +++ b/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt @@ -42,7 +42,14 @@ class KotlinWebSiteFormatTest { private fun buildMultiplePlatforms(path: String): DocumentationModule { val module = DocumentationModule("test") - val options = DocumentationOptions("", "html", generateIndexPages = false, noStdlibLink = true) + val options = DocumentationOptions( + outputDir = "", + outputFormat = "html", + generateIndexPages = false, + noStdlibLink = true, + languageVersion = null, + apiVersion = null + ) appendDocumentation(module, contentRootFromPath("testdata/format/website/$path/jvm.kt"), defaultPlatforms = listOf("JVM"), options = options) appendDocumentation(module, contentRootFromPath("testdata/format/website/$path/jre7.kt"), defaultPlatforms = listOf("JVM", "JRE7"), options = options) appendDocumentation(module, contentRootFromPath("testdata/format/website/$path/js.kt"), defaultPlatforms = listOf("JS"), options = options) diff --git a/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt index b4b133f4..433c9c13 100644 --- a/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt +++ b/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt @@ -57,7 +57,14 @@ class KotlinWebSiteHtmlFormatTest { private fun buildMultiplePlatforms(path: String): DocumentationModule { val module = DocumentationModule("test") - val options = DocumentationOptions("", "html", generateIndexPages = false, noStdlibLink = true) + val options = DocumentationOptions( + outputDir = "", + outputFormat = "kotlin-website-html", + generateIndexPages = false, + noStdlibLink = true, + languageVersion = null, + apiVersion = null + ) appendDocumentation(module, contentRootFromPath("testdata/format/website-html/$path/jvm.kt"), defaultPlatforms = listOf("JVM"), options = options) appendDocumentation(module, contentRootFromPath("testdata/format/website-html/$path/jre7.kt"), defaultPlatforms = listOf("JVM", "JRE7"), options = options) appendDocumentation(module, contentRootFromPath("testdata/format/website-html/$path/js.kt"), defaultPlatforms = listOf("JS"), options = options) diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt index d2ab5b5c..2c5422c5 100644 --- a/core/src/test/kotlin/format/MarkdownFormatTest.kt +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -300,7 +300,14 @@ class MarkdownFormatTest { @Test fun packagePlatformsWithExtExtensions() { val path = "multiplatform/packagePlatformsWithExtExtensions" val module = DocumentationModule("test") - val options = DocumentationOptions("", "html", generateIndexPages = false, noStdlibLink = true) + val options = DocumentationOptions( + outputDir = "", + outputFormat = "html", + generateIndexPages = false, + noStdlibLink = true, + languageVersion = null, + apiVersion = null + ) appendDocumentation(module, contentRootFromPath("testdata/format/$path/jvm.kt"), defaultPlatforms = listOf("JVM"), withKotlinRuntime = true, options = options) verifyMultiplatformIndex(module, path) verifyMultiplatformPackage(module, path) @@ -402,7 +409,14 @@ class MarkdownFormatTest { private fun buildMultiplePlatforms(path: String): DocumentationModule { val module = DocumentationModule("test") - val options = DocumentationOptions("", "html", generateIndexPages = false, noStdlibLink = true) + val options = DocumentationOptions( + outputDir = "", + outputFormat = "html", + generateIndexPages = false, + noStdlibLink = true, + languageVersion = null, + apiVersion = null + ) appendDocumentation(module, contentRootFromPath("testdata/format/$path/jvm.kt"), defaultPlatforms = listOf("JVM"), options = options) appendDocumentation(module, contentRootFromPath("testdata/format/$path/js.kt"), defaultPlatforms = listOf("JS"), options = options) return module diff --git a/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt b/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt index fd6a4209..90e5b5fc 100644 --- a/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt +++ b/integration/src/main/kotlin/org/jetbrains/dokka/configuration.kt @@ -36,6 +36,8 @@ interface DokkaConfiguration { val impliedPlatforms: List val perPackageOptions: List val externalDocumentationLinks: List + val languageVersion: String? + val apiVersion: String? val noStdlibLink: Boolean val cacheRoot: String? val suppressedFiles: List @@ -79,27 +81,31 @@ interface DokkaConfiguration { } } -data class SerializeOnlyDokkaConfiguration(override val moduleName: String, - override val classpath: List, - override val sourceRoots: List, - override val samples: List, - override val includes: List, - override val outputDir: String, - override val format: String, - override val includeNonPublic: Boolean, - override val includeRootPackage: Boolean, - override val reportUndocumented: Boolean, - override val skipEmptyPackages: Boolean, - override val skipDeprecated: Boolean, - override val jdkVersion: Int, - override val generateIndexPages: Boolean, - override val sourceLinks: List, - override val impliedPlatforms: List, - override val perPackageOptions: List, - override val externalDocumentationLinks: List, - override val noStdlibLink: Boolean, - override val cacheRoot: String?, - override val suppressedFiles: List) : DokkaConfiguration +data class SerializeOnlyDokkaConfiguration( + override val moduleName: String, + override val classpath: List, + override val sourceRoots: List, + override val samples: List, + override val includes: List, + override val outputDir: String, + override val format: String, + override val includeNonPublic: Boolean, + override val includeRootPackage: Boolean, + override val reportUndocumented: Boolean, + override val skipEmptyPackages: Boolean, + override val skipDeprecated: Boolean, + override val jdkVersion: Int, + override val generateIndexPages: Boolean, + override val sourceLinks: List, + override val impliedPlatforms: List, + override val perPackageOptions: List, + override val externalDocumentationLinks: List, + override val noStdlibLink: Boolean, + override val cacheRoot: String?, + override val suppressedFiles: List, + override val languageVersion: String?, + override val apiVersion: String? +) : DokkaConfiguration data class ExternalDocumentationLinkImpl(@CustomSerializer(UrlSerializer::class) override val url: URL, diff --git a/runners/ant/src/main/kotlin/ant/dokka.kt b/runners/ant/src/main/kotlin/ant/dokka.kt index 2872f845..d1b6bef5 100644 --- a/runners/ant/src/main/kotlin/ant/dokka.kt +++ b/runners/ant/src/main/kotlin/ant/dokka.kt @@ -45,6 +45,9 @@ class DokkaAntTask: Task() { var cacheRoot: String? = null + var languageVersion: String? = null + var apiVersion: String? = null + val compileClasspath: Path by lazy { Path(getProject()) } val sourcePath: Path by lazy { Path(getProject()) } val samplesPath: Path by lazy { Path(getProject()) } @@ -118,7 +121,9 @@ class DokkaAntTask: Task() { samplesPath.list().toList(), includesPath.list().toList(), moduleName!!, - DocumentationOptions(outputDir!!, outputFormat, + DocumentationOptions( + outputDir!!, + outputFormat, skipDeprecated = skipDeprecated, sourceLinks = sourceLinks, jdkVersion = jdkVersion, @@ -126,7 +131,9 @@ class DokkaAntTask: Task() { perPackageOptions = antPackageOptions, externalDocumentationLinks = antExternalDocumentationLinks.map { it.build() }, noStdlibLink = noStdlibLink, - cacheRoot = cacheRoot + cacheRoot = cacheRoot, + languageVersion = languageVersion, + apiVersion = apiVersion ) ) generator.generate() diff --git a/runners/cli/src/main/kotlin/cli/main.kt b/runners/cli/src/main/kotlin/cli/main.kt index b6eb1564..fe945ed3 100644 --- a/runners/cli/src/main/kotlin/cli/main.kt +++ b/runners/cli/src/main/kotlin/cli/main.kt @@ -55,6 +55,13 @@ class DokkaArguments { @set:Argument(value = "cacheRoot", description = "Path to cache folder, or 'default' to use ~/.cache/dokka, if not provided caching is disabled") var cacheRoot: String? = null + + @set:Argument(value = "languageVersion", description = "Language Version to pass to Kotlin Analysis") + var languageVersion: String? = null + + @set:Argument(value = "apiVersion", description = "Kotlin Api Version to pass to Kotlin Analysis") + var apiVersion: String? = null + } @@ -108,7 +115,9 @@ object MainKt { jdkVersion = arguments.jdkVersion, externalDocumentationLinks = parseLinks(arguments.links), noStdlibLink = arguments.noStdlibLink, - cacheRoot = arguments.cacheRoot + cacheRoot = arguments.cacheRoot, + languageVersion = arguments.languageVersion, + apiVersion = arguments.apiVersion ) val generator = DokkaGenerator( diff --git a/runners/gradle-plugin/src/main/kotlin/main.kt b/runners/gradle-plugin/src/main/kotlin/main.kt index 623a627c..bdecc3f6 100644 --- a/runners/gradle-plugin/src/main/kotlin/main.kt +++ b/runners/gradle-plugin/src/main/kotlin/main.kt @@ -112,7 +112,15 @@ open class DokkaTask : DefaultTask() { @Input var noStdlibLink: Boolean = false - @Optional @Input var cacheRoot: String? = null + @Optional @Input + var cacheRoot: String? = null + + + @Optional @Input + var languageVersion: String? = null + + @Optional @Input + var apiVersion: String? = null @get:Input internal val kotlinCompileBasedClasspathAndSourceRoots: ClasspathAndSourceRoots by lazy { extractClasspathAndSourceRootsFromKotlinTasks() } @@ -281,7 +289,9 @@ open class DokkaTask : DefaultTask() { externalDocumentationLinks, noStdlibLink, cacheRoot, - collectSuppressedFiles(sourceRoots)) + collectSuppressedFiles(sourceRoots), + languageVersion, + apiVersion) bootstrapProxy.configure( diff --git a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt index c0904396..09da90c6 100644 --- a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt +++ b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt @@ -107,6 +107,12 @@ abstract class AbstractDokkaMojo : AbstractMojo() { @Parameter var cacheRoot: String? = null + @Parameter + var languageVersion: String? = null + + @Parameter + var apiVersion: String? = null + protected abstract fun getOutDir(): String protected abstract fun getOutFormat(): String @@ -133,7 +139,9 @@ abstract class AbstractDokkaMojo : AbstractMojo() { perPackageOptions = perPackageOptions, externalDocumentationLinks = externalDocumentationLinks.map { it.build() }, noStdlibLink = noStdlibLink, - cacheRoot = cacheRoot + cacheRoot = cacheRoot, + languageVersion = languageVersion, + apiVersion = apiVersion ) ) -- cgit From 3eb23215edcd1cf92966f8d39afe754fef0c7a19 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Wed, 21 Feb 2018 11:51:06 +0300 Subject: Update bundled kotlin compiler --- build.gradle | 2 + core/build.gradle | 2 +- .../main/kotlin/Analysis/AnalysisEnvironment.kt | 53 ++++++++++++++++++++-- .../main/kotlin/Analysis/CoreKotlinCacheService.kt | 30 ++++++++++++ .../main/kotlin/Analysis/CoreProjectFileIndex.kt | 30 ++++++------ .../kotlin/Kotlin/DescriptorDocumentationParser.kt | 2 +- .../src/main/kotlin/Kotlin/DocumentationBuilder.kt | 10 ++++ gradle.properties | 4 +- 8 files changed, 111 insertions(+), 22 deletions(-) create mode 100644 core/src/main/kotlin/Analysis/CoreKotlinCacheService.kt (limited to 'core/src/main/kotlin/Kotlin/DocumentationBuilder.kt') diff --git a/build.gradle b/build.gradle index ee76c9cb..f1748259 100644 --- a/build.gradle +++ b/build.gradle @@ -6,6 +6,7 @@ allprojects { def repo = { artifactPattern("https://teamcity.jetbrains.com/guestAuth/repository/download/Kotlin_dev_CompilerAllPlugins/[revision]/internal/[module](.[ext])") + artifactPattern("https://teamcity.jetbrains.com/guestAuth/repository/download/IntelliJMarkdownParser_Build/[revision]/([module]_[ext]/)[module](.[ext])") } buildscript { @@ -70,6 +71,7 @@ task wrapper(type: Wrapper) { def versions = DependenciesVersionGetter.getVersions(project, bundled_kotlin_compiler_version) ext.ideaVersion = versions["idea.build.id"] +ext.markdownVersion = versions["markdown.build.id"].replace("%20", " ") configurations { ideaIC diff --git a/core/build.gradle b/core/build.gradle index a8f0f275..1a93bb48 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -29,7 +29,7 @@ dependencies { compile "org.jetbrains.kotlin:kotlin-script-runtime:$bundled_kotlin_compiler_version" compile "teamcity:kotlin-ide-common:$bundled_kotlin_compiler_version" - compile "teamcity:markdown:$bundled_kotlin_compiler_version" + compile "teamcity:markdown:$markdownVersion" compile intellijCoreAnalysis() diff --git a/core/src/main/kotlin/Analysis/AnalysisEnvironment.kt b/core/src/main/kotlin/Analysis/AnalysisEnvironment.kt index 56249ac4..5522d4f0 100644 --- a/core/src/main/kotlin/Analysis/AnalysisEnvironment.kt +++ b/core/src/main/kotlin/Analysis/AnalysisEnvironment.kt @@ -1,5 +1,6 @@ package org.jetbrains.dokka +import com.google.common.collect.ImmutableMap import com.intellij.core.CoreApplicationEnvironment import com.intellij.core.CoreModuleManager import com.intellij.mock.MockComponentManager @@ -17,6 +18,7 @@ import com.intellij.psi.PsiElement import com.intellij.psi.search.GlobalSearchScope import com.intellij.util.io.URLUtil import org.jetbrains.kotlin.analyzer.* +import org.jetbrains.kotlin.caches.resolve.KotlinCacheService import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles @@ -34,16 +36,19 @@ import org.jetbrains.kotlin.idea.resolve.ResolutionFacade import org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.platform.JvmBuiltIns -import org.jetbrains.kotlin.psi.KtDeclaration -import org.jetbrains.kotlin.psi.KtElement -import org.jetbrains.kotlin.psi.KtFile +import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.resolve.BindingTrace import org.jetbrains.kotlin.resolve.CompilerEnvironment +import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics import org.jetbrains.kotlin.resolve.jvm.JvmAnalyzerFacade import org.jetbrains.kotlin.resolve.jvm.JvmPlatformParameters import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.resolve.lazy.ResolveSession +import org.jetbrains.kotlin.types.KotlinType +import org.jetbrains.kotlin.util.slicedMap.ReadOnlySlice +import org.jetbrains.kotlin.util.slicedMap.WritableSlice import java.io.File /** @@ -158,7 +163,11 @@ class AnalysisEnvironment(val messageCollector: MessageCollector) : Disposable { val resolverForModule = resolverForProject.resolverForModule(module) val moduleDescriptor = resolverForProject.descriptorForModule(module) builtIns.initialize(moduleDescriptor, true) - return DokkaResolutionFacade(environment.project, moduleDescriptor, resolverForModule) + val created = DokkaResolutionFacade(environment.project, moduleDescriptor, resolverForModule) + val projectComponentManager = environment.project as MockComponentManager + projectComponentManager.registerService(KotlinCacheService::class.java, CoreKotlinCacheService(created)) + + return created } fun loadLanguageVersionSettings(languageVersionString: String?, apiVersionString: String?) { @@ -247,6 +256,42 @@ class DokkaResolutionFacade(override val project: Project, val resolveSession: ResolveSession get() = getFrontendService(ResolveSession::class.java) override fun analyze(element: KtElement, bodyResolveMode: BodyResolveMode): BindingContext { + if (element is KtDeclaration) { + val descriptor = resolveToDescriptor(element) + return object : BindingContext { + override fun getKeys(p0: WritableSlice?): Collection { + throw UnsupportedOperationException() + } + + override fun getType(p0: KtExpression): KotlinType? { + throw UnsupportedOperationException() + } + + override fun get(slice: ReadOnlySlice?, key: K): V? { + if (key != element) { + throw UnsupportedOperationException() + } + return when { + slice == BindingContext.DECLARATION_TO_DESCRIPTOR -> descriptor as V + slice == BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER && (element as KtParameter).hasValOrVar() -> descriptor as V + else -> null + } + } + + override fun getDiagnostics(): Diagnostics { + throw UnsupportedOperationException() + } + + override fun addOwnDataTo(p0: BindingTrace, p1: Boolean) { + throw UnsupportedOperationException() + } + + override fun getSliceContents(p0: ReadOnlySlice): ImmutableMap { + throw UnsupportedOperationException() + } + + } + } throw UnsupportedOperationException() } diff --git a/core/src/main/kotlin/Analysis/CoreKotlinCacheService.kt b/core/src/main/kotlin/Analysis/CoreKotlinCacheService.kt new file mode 100644 index 00000000..31b8ffc7 --- /dev/null +++ b/core/src/main/kotlin/Analysis/CoreKotlinCacheService.kt @@ -0,0 +1,30 @@ +package org.jetbrains.dokka + +import com.intellij.psi.PsiFile +import org.jetbrains.kotlin.analyzer.ModuleInfo +import org.jetbrains.kotlin.caches.resolve.KotlinCacheService +import org.jetbrains.kotlin.idea.resolve.ResolutionFacade +import org.jetbrains.kotlin.psi.KtElement +import org.jetbrains.kotlin.resolve.TargetPlatform +import org.jetbrains.kotlin.resolve.diagnostics.KotlinSuppressCache + + +class CoreKotlinCacheService(private val resolutionFacade: DokkaResolutionFacade) : KotlinCacheService { + override fun getResolutionFacade(elements: List): ResolutionFacade { + return resolutionFacade + } + + override fun getResolutionFacadeByFile(file: PsiFile, platform: TargetPlatform): ResolutionFacade { + return resolutionFacade + } + + override fun getResolutionFacadeByModuleInfo(moduleInfo: ModuleInfo, platform: TargetPlatform): ResolutionFacade? { + return resolutionFacade + } + + override fun getSuppressionCache(): KotlinSuppressCache { + throw UnsupportedOperationException() + } + +} + diff --git a/core/src/main/kotlin/Analysis/CoreProjectFileIndex.kt b/core/src/main/kotlin/Analysis/CoreProjectFileIndex.kt index 2f2f94b3..4f6a7c76 100644 --- a/core/src/main/kotlin/Analysis/CoreProjectFileIndex.kt +++ b/core/src/main/kotlin/Analysis/CoreProjectFileIndex.kt @@ -228,24 +228,26 @@ class CoreProjectFileIndex(private val project: Project, contentRoots: List { + override fun getFiles(p0: OrderRootType): Array { throw UnsupportedOperationException() } - override fun getPresentableName(): String { + override fun getUrls(p0: OrderRootType): Array { throw UnsupportedOperationException() } - override fun getUrls(p0: OrderRootType?): Array { + override fun accept(p0: RootPolicy, p1: R?): R { throw UnsupportedOperationException() } - override fun getOwnerModule(): Module = module - override fun accept(p0: RootPolicy?, p1: R?): R { + override fun getPresentableName(): String { throw UnsupportedOperationException() } + override fun getOwnerModule(): Module = module + + override fun isValid(): Boolean { throw UnsupportedOperationException() } @@ -262,29 +264,29 @@ class CoreProjectFileIndex(private val project: Project, contentRoots: List { throw UnsupportedOperationException() } - override fun getJdk(): Sdk = sdk - - override fun getFiles(p0: OrderRootType?): Array { + override fun getUrls(p0: OrderRootType): Array { throw UnsupportedOperationException() } - override fun getPresentableName(): String { + override fun accept(p0: RootPolicy, p1: R?): R { throw UnsupportedOperationException() } - override fun getUrls(p0: OrderRootType?): Array { + override fun getJdkName(): String? { throw UnsupportedOperationException() } - override fun getOwnerModule(): Module { + override fun getJdk(): Sdk = sdk + + override fun getPresentableName(): String { throw UnsupportedOperationException() } - override fun accept(p0: RootPolicy?, p1: R?): R { + override fun getOwnerModule(): Module { throw UnsupportedOperationException() } @@ -358,7 +360,7 @@ class CoreProjectFileIndex(private val project: Project, contentRoots: List getModuleExtension(p0: Class?): T { + override fun getModuleExtension(p0: Class): T { throw UnsupportedOperationException() } diff --git a/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt b/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt index eb8c12d0..f2d9d3a7 100644 --- a/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt +++ b/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt @@ -81,7 +81,7 @@ class DescriptorDocumentationParser val suppressAnnotation = annotations.findAnnotation(FqName(Suppress::class.qualifiedName!!)) return if (suppressAnnotation != null) { @Suppress("UNCHECKED_CAST") - (suppressAnnotation.argumentValue("names") as List).any { it.value == "NOT_DOCUMENTED" } + (suppressAnnotation.argumentValue("names")?.value as List).any { it.value == "NOT_DOCUMENTED" } } else containingDeclaration?.isSuppressWarning() ?: false } diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt index 61bf50d6..916f89c9 100644 --- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt @@ -15,7 +15,9 @@ import org.jetbrains.kotlin.js.resolve.diagnostics.findPsi import org.jetbrains.kotlin.kdoc.psi.impl.KDocSection import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl +import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.KtModifierListOwner import org.jetbrains.kotlin.psi.KtParameter import org.jetbrains.kotlin.resolve.DescriptorUtils @@ -779,6 +781,14 @@ class DocumentationBuilder "\"" + StringUtil.escapeStringCharacters(value) + "\"" is EnumEntrySyntheticClassDescriptor -> value.containingDeclaration.name.asString() + "." + value.name.asString() + is Pair<*, *> -> { + val (classId, name) = value + if (classId is ClassId && name is Name) { + classId.shortClassName.asString() + "." + name.asString() + } else { + value.toString() + } + } else -> value.toString() }.let { valueString -> DocumentationNode(valueString, Content.Empty, NodeKind.Value) diff --git a/gradle.properties b/gradle.properties index 4a6475b1..cabae269 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,8 +2,8 @@ dokka_version=0.9.16 dokka_publication_channel=dokka #Kotlin compiler and plugin -bundled_kotlin_compiler_version=1.2.20-dev-419 -kotlin_version=1.2.0 +bundled_kotlin_compiler_version=1.2.40-dev-529 +kotlin_version=1.2.21 kotlin_for_gradle_runtime_version=1.1.60 ant_version=1.9.6 -- cgit