diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/base/base-test-utils/build.gradle.kts | 1 | ||||
-rw-r--r-- | plugins/base/base-test-utils/src/main/kotlin/renderers/JsoupUtils.kt (renamed from plugins/base/src/test/kotlin/utils/JsoupUtils.kt) | 0 | ||||
-rw-r--r-- | plugins/base/base-test-utils/src/main/kotlin/renderers/SignatureUtils.kt (renamed from plugins/base/src/test/kotlin/signatures/SignatureUtils.kt) | 0 | ||||
-rw-r--r-- | plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt | 1 | ||||
-rw-r--r-- | plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt | 30 | ||||
-rw-r--r-- | plugins/base/src/test/kotlin/signatures/SignatureTest.kt | 30 | ||||
-rw-r--r-- | plugins/base/src/test/kotlin/utils/TestUtils.kt | 3 | ||||
-rw-r--r-- | plugins/kotlin-as-java/build.gradle.kts | 1 | ||||
-rw-r--r-- | plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt | 27 | ||||
-rw-r--r-- | plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt | 13 | ||||
-rw-r--r-- | plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt | 90 |
11 files changed, 161 insertions, 35 deletions
diff --git a/plugins/base/base-test-utils/build.gradle.kts b/plugins/base/base-test-utils/build.gradle.kts index a4a4df69..1de0ac0f 100644 --- a/plugins/base/base-test-utils/build.gradle.kts +++ b/plugins/base/base-test-utils/build.gradle.kts @@ -1,4 +1,5 @@ dependencies { compileOnly(project(":plugins:base")) implementation(project(":core:test-api")) + implementation("org.jsoup:jsoup:1.12.1") } diff --git a/plugins/base/src/test/kotlin/utils/JsoupUtils.kt b/plugins/base/base-test-utils/src/main/kotlin/renderers/JsoupUtils.kt index e8c7838d..e8c7838d 100644 --- a/plugins/base/src/test/kotlin/utils/JsoupUtils.kt +++ b/plugins/base/base-test-utils/src/main/kotlin/renderers/JsoupUtils.kt diff --git a/plugins/base/src/test/kotlin/signatures/SignatureUtils.kt b/plugins/base/base-test-utils/src/main/kotlin/renderers/SignatureUtils.kt index e77b8757..e77b8757 100644 --- a/plugins/base/src/test/kotlin/signatures/SignatureUtils.kt +++ b/plugins/base/base-test-utils/src/main/kotlin/renderers/SignatureUtils.kt diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt index 2a091ff5..08e702ba 100644 --- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt +++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt @@ -346,7 +346,6 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog } is TypeAliased -> signatureForProjection(p.typeAlias) - is JavaObject -> link("Any", DriOfAny) is Void -> link("Unit", DriOfUnit) is PrimitiveJavaType -> signatureForProjection(p.translateToKotlin(), showFullyQualifiedName) diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index 392bba7e..b1c82efb 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -635,22 +635,20 @@ private class DokkaDescriptorVisitor( abbreviation.toBound(), expandedType.toBound() ) - else -> { - when (val ctor = constructor.declarationDescriptor) { - is TypeParameterDescriptor -> TypeParameter( - dri = DRI.from(ctor), - name = ctor.name.asString() - ) - else -> TypeConstructor( - DRI.from(ctor!!), // TODO: remove '!!' - arguments.map { it.toProjection() }, - if (isExtensionFunctionType) FunctionModifiers.EXTENSION - else if (isFunctionType) FunctionModifiers.FUNCTION - else FunctionModifiers.NONE - ) - }.let { - if (isMarkedNullable) Nullable(it) else it - } + else -> when (val ctor = constructor.declarationDescriptor) { + is TypeParameterDescriptor -> TypeParameter( + dri = DRI.from(ctor), + name = ctor.name.asString() + ) + else -> TypeConstructor( + DRI.from(ctor!!), // TODO: remove '!!' + arguments.map { it.toProjection() }, + if (isExtensionFunctionType) FunctionModifiers.EXTENSION + else if (isFunctionType) FunctionModifiers.FUNCTION + else FunctionModifiers.NONE + ) + }.let { + if (isMarkedNullable) Nullable(it) else it } } diff --git a/plugins/base/src/test/kotlin/signatures/SignatureTest.kt b/plugins/base/src/test/kotlin/signatures/SignatureTest.kt index df2c3825..f5b1bf2e 100644 --- a/plugins/base/src/test/kotlin/signatures/SignatureTest.kt +++ b/plugins/base/src/test/kotlin/signatures/SignatureTest.kt @@ -1,6 +1,8 @@ package signatures +import org.jetbrains.dokka.DokkaConfiguration import org.jetbrains.dokka.DokkaSourceSetID +import org.jetbrains.dokka.jdk import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest import org.jsoup.Jsoup import org.jsoup.nodes.Element @@ -450,6 +452,34 @@ class SignatureTest : AbstractCoreTest() { } @Test + fun `typealias with generic params swapped`() { + + val writerPlugin = TestOutputWriterPlugin() + + testInline( + """ + |/src/main/kotlin/kotlinAsJavaPlugin/Test.kt + |package kotlinAsJavaPlugin + | + |typealias XD<B, A> = Map<A, B> + | + |class ABC { + | fun someFun(xd: XD<Int, String>) = 1 + |} + """.trimMargin(), + configuration, + pluginOverrides = listOf(writerPlugin) + ) { + renderingStage = { _, _ -> + writerPlugin.writer.renderedContent("root/kotlinAsJavaPlugin/-a-b-c/some-fun.html").signature().first().match( + "fun ", A("someFun"), "(xd: ", A("XD"), "<", A("Int"), + ", ", A("String"), ">):", A("Int"), Span() + ) + } + } + } + + @Test fun `generic constructor params`() { diff --git a/plugins/base/src/test/kotlin/utils/TestUtils.kt b/plugins/base/src/test/kotlin/utils/TestUtils.kt index 5183972a..2ef6534e 100644 --- a/plugins/base/src/test/kotlin/utils/TestUtils.kt +++ b/plugins/base/src/test/kotlin/utils/TestUtils.kt @@ -76,4 +76,5 @@ val Bound.name: String? is Void -> "void" is Dynamic -> "dynamic" is UnresolvedBound -> "<ERROR CLASS>" - }
\ No newline at end of file + is TypeAliased -> typeAlias.name + } diff --git a/plugins/kotlin-as-java/build.gradle.kts b/plugins/kotlin-as-java/build.gradle.kts index f03a28c6..2c7f1e01 100644 --- a/plugins/kotlin-as-java/build.gradle.kts +++ b/plugins/kotlin-as-java/build.gradle.kts @@ -5,6 +5,7 @@ dependencies { testImplementation(project(":plugins:base")) testImplementation(project(":plugins:base:base-test-utils")) testImplementation(project(":core:content-matcher-test-utils")) + testImplementation("org.jsoup:jsoup:1.12.1") } registerDokkaArtifactPublication("kotlinAsJavaPlugin") { diff --git a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt index d79bd7b1..38d904e4 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt @@ -175,20 +175,33 @@ internal fun DClass.asJava(): DClass = copy( private fun DTypeParameter.asJava(): DTypeParameter = copy( variantTypeParameter = variantTypeParameter.withDri(dri.possiblyAsJava()), - bounds = bounds.map { it.asJava() } + bounds = bounds.map { it.asJava() as Bound } ) -private fun Bound.asJava(): Bound = when (this) { +private fun Projection.asJava(): Projection = when(this) { + is Star -> Star + is Covariance<*> -> copy(inner.asJava()) + is Contravariance<*> -> copy(inner.asJava()) + is Invariance<*> -> copy(inner.asJava()) + is Bound -> asJava() +} + +private fun Bound.asJava(): Bound = when(this) { + is TypeParameter -> copy(dri.possiblyAsJava()) is TypeConstructor -> copy( - dri = dri.possiblyAsJava() + dri = dri.possiblyAsJava(), + projections = projections.map { it.asJava() } ) is TypeAliased -> copy( + typeAlias = typeAlias.asJava(), inner = inner.asJava() ) - is Nullable -> copy( - inner = inner.asJava() - ) - else -> this + is Nullable -> copy(inner.asJava()) + is PrimitiveJavaType -> this + is Void -> this + is JavaObject -> this + is Dynamic -> this + is UnresolvedBound -> this } internal fun DEnum.asJava(): DEnum = copy( diff --git a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt index d24fa428..1d62a206 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt @@ -79,10 +79,10 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge c.supertypes.map { (p, dris) -> val (classes, interfaces) = dris.partition { it.kind == JavaClassKindTypes.CLASS } list(classes, prefix = " extends ", sourceSets = setOf(p)) { - link(it.typeConstructor.dri.sureClassNames, it.typeConstructor.dri, sourceSets = setOf(p)) + signatureForProjection(it.typeConstructor) } - list(interfaces, prefix = " implements ", sourceSets = setOf(p)){ - link(it.typeConstructor.dri.sureClassNames, it.typeConstructor.dri, sourceSets = setOf(p)) + list(interfaces, prefix = " implements ", sourceSets = setOf(p)) { + signatureForProjection(it.typeConstructor) } } } @@ -160,7 +160,12 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge } is Variance<*> -> group(styles = emptySet()) { - text("$p ".takeIf { it.isNotBlank() } ?: "") // TODO: "super" && "extends" + val variance = when(p) { + is Covariance<*> -> "? extends " + is Contravariance<*> -> "? super " + is Invariance<*> -> "" + } + text(variance) signatureForProjection(p.inner) } diff --git a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt index 3dbe5888..c6dc9a25 100644 --- a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt +++ b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt @@ -6,6 +6,14 @@ import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest import org.jetbrains.kotlin.utils.addToStdlib.cast import org.junit.jupiter.api.Test import matchers.content.* +import org.jetbrains.dokka.DokkaConfiguration +import org.jetbrains.dokka.jdk +import signatures.renderedContent +import signatures.signature +import utils.A +import utils.Span +import utils.TestOutputWriterPlugin +import utils.match class KotlinAsJavaPluginTest : AbstractCoreTest() { @@ -31,7 +39,7 @@ class KotlinAsJavaPluginTest : AbstractCoreTest() { |fun testF3(to: TestObj) = to |fun <T : Char> testF4(t: T) = listOf(t) |val testV = 1 - """, + """.trimMargin(), configuration, cleanupOutput = true ) { @@ -68,7 +76,7 @@ class KotlinAsJavaPluginTest : AbstractCoreTest() { | |fun testF(i: Int) = i |val testV = 1 - """, + """.trimMargin(), configuration, cleanupOutput = true ) { @@ -109,7 +117,7 @@ class KotlinAsJavaPluginTest : AbstractCoreTest() { |class TestJ { | int testF(int i) { return i; } |} - """, + """.trimMargin(), configuration, cleanupOutput = true ) { @@ -149,7 +157,7 @@ class KotlinAsJavaPluginTest : AbstractCoreTest() { |class Test { | public val publicProperty: String = "" |} - """, + """.trimMargin(), configuration, cleanupOutput = true ) { @@ -202,7 +210,7 @@ class KotlinAsJavaPluginTest : AbstractCoreTest() { |class TestJ { | public Int publicProperty = 1; |} - """, + """.trimMargin(), configuration, cleanupOutput = true ) { @@ -252,7 +260,7 @@ class KotlinAsJavaPluginTest : AbstractCoreTest() { | open class A { } | interface B | class C : A(), B - """, + """.trimMargin(), configuration, cleanupOutput = true ) { @@ -290,6 +298,76 @@ class KotlinAsJavaPluginTest : AbstractCoreTest() { private fun <T> Collection<T>.assertCount(n: Int, prefix: String = "") = assert(count() == n) { "${prefix}Expected $n, got ${count()}" } + @Test + fun `typealias`() { + val writerPlugin = TestOutputWriterPlugin() + val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/") + externalDocumentationLinks = listOf(DokkaConfiguration.ExternalDocumentationLink.jdk(8)) + } + } + } + testInline( + """ + |/src/main/kotlin/kotlinAsJavaPlugin/Test.kt + |package kotlinAsJavaPlugin + | + |typealias XD = Int + |class ABC { + | fun someFun(xd: XD): Int = 1 + |} + """.trimMargin(), + configuration, + pluginOverrides = listOf(writerPlugin), + cleanupOutput = true + ) { + renderingStage = { _, _ -> + writerPlugin.writer.renderedContent("root/kotlinAsJavaPlugin/-a-b-c/some-fun.html").signature().first().match( + "final ", A("Integer"), A("someFun"), "(", A("Integer"), A("xd"), ")", Span() + ) + } + } + } + + @Test + fun `typealias with generic`() { + val writerPlugin = TestOutputWriterPlugin() + val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/") + externalDocumentationLinks = listOf( + DokkaConfiguration.ExternalDocumentationLink.jdk(8), + stdlibExternalDocumentationLink + ) + } + } + } + testInline( + """ + |/src/main/kotlin/kotlinAsJavaPlugin/Test.kt + |package kotlinAsJavaPlugin + | + |typealias XD<B, A> = Map<A, B> + | + |class ABC { + | fun someFun(xd: XD<Int, String>) = 1 + |} + """.trimMargin(), + configuration, + pluginOverrides = listOf(writerPlugin), + cleanupOutput = true + ) { + renderingStage = { _, _ -> + writerPlugin.writer.renderedContent("root/kotlinAsJavaPlugin/-a-b-c/some-fun.html").signature().first().match( + "final ", A("Integer"), A("someFun"), "(", A("Map"), "<", A("String"), + ", ", A("Integer"), ">", A("xd"), ")", Span() + ) + } + } + } } private val ContentNode.mainContents: List<ContentNode> |