Skip to content

Commit

Permalink
Implement analysis test API
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnatBeresnev committed Oct 4, 2023
1 parent 38e09dd commit b6a6ca8
Show file tree
Hide file tree
Showing 46 changed files with 2,320 additions and 41 deletions.
26 changes: 26 additions & 0 deletions core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -4513,6 +4513,32 @@ public abstract interface class org/jetbrains/dokka/renderers/Renderer {
public abstract fun render (Lorg/jetbrains/dokka/pages/RootPageNode;)V
}

public final class org/jetbrains/dokka/transformers/documentation/ClashingDriIdentifier : org/jetbrains/dokka/model/properties/ExtraProperty {
public static final field Companion Lorg/jetbrains/dokka/transformers/documentation/ClashingDriIdentifier$Companion;
public fun <init> (Ljava/util/Set;)V
public final fun component1 ()Ljava/util/Set;
public final fun copy (Ljava/util/Set;)Lorg/jetbrains/dokka/transformers/documentation/ClashingDriIdentifier;
public static synthetic fun copy$default (Lorg/jetbrains/dokka/transformers/documentation/ClashingDriIdentifier;Ljava/util/Set;ILjava/lang/Object;)Lorg/jetbrains/dokka/transformers/documentation/ClashingDriIdentifier;
public fun equals (Ljava/lang/Object;)Z
public fun getKey ()Lorg/jetbrains/dokka/model/properties/ExtraProperty$Key;
public final fun getValue ()Ljava/util/Set;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class org/jetbrains/dokka/transformers/documentation/ClashingDriIdentifier$Companion : org/jetbrains/dokka/model/properties/ExtraProperty$Key {
public synthetic fun mergeStrategyFor (Ljava/lang/Object;Ljava/lang/Object;)Lorg/jetbrains/dokka/model/properties/MergeStrategy;
public fun mergeStrategyFor (Lorg/jetbrains/dokka/transformers/documentation/ClashingDriIdentifier;Lorg/jetbrains/dokka/transformers/documentation/ClashingDriIdentifier;)Lorg/jetbrains/dokka/model/properties/MergeStrategy;
}

public final class org/jetbrains/dokka/transformers/documentation/DefaultDocumentableMerger : org/jetbrains/dokka/transformers/documentation/DocumentableMerger {
public fun <init> (Lorg/jetbrains/dokka/plugability/DokkaContext;)V
public fun invoke (Ljava/util/Collection;)Lorg/jetbrains/dokka/model/DModule;
public final fun mergeWith (Lorg/jetbrains/dokka/model/DFunction;Lorg/jetbrains/dokka/model/DFunction;)Lorg/jetbrains/dokka/model/DFunction;
public final fun mergeWith (Lorg/jetbrains/dokka/model/DPackage;Lorg/jetbrains/dokka/model/DPackage;)Lorg/jetbrains/dokka/model/DPackage;
public final fun mergeWith (Lorg/jetbrains/dokka/model/DProperty;Lorg/jetbrains/dokka/model/DProperty;)Lorg/jetbrains/dokka/model/DProperty;
}

public abstract interface class org/jetbrains/dokka/transformers/documentation/DocumentableMerger {
public abstract fun invoke (Ljava/util/Collection;)Lorg/jetbrains/dokka/model/DModule;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,27 @@
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

package org.jetbrains.dokka.base.transformers.documentables
package org.jetbrains.dokka.transformers.documentation

import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.base.utils.firstNotNullOfOrNull
import org.jetbrains.dokka.InternalDokkaApi
import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.model.properties.ExtraProperty
import org.jetbrains.dokka.model.properties.MergeStrategy
import org.jetbrains.dokka.model.properties.mergeExtras
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.transformers.documentation.DocumentableMerger
import org.jetbrains.dokka.CoreExtensions

internal class DefaultDocumentableMerger(val context: DokkaContext) : DocumentableMerger {
/**
* Should NOT be used outside of Dokka itself, there are no guarantees
* this class will continue to exist in future releases.
*
* This class resides in core because it is a non-trivial implementation
* for a core extension [CoreExtensions.documentableMerger], which is needed
* in modules that only have access to `dokka-core`.
*/
@InternalDokkaApi
public class DefaultDocumentableMerger(context: DokkaContext) : DocumentableMerger {
private val dependencyInfo = context.getDependencyInfo()

override fun invoke(modules: Collection<DModule>): DModule? =
Expand Down Expand Up @@ -123,7 +132,7 @@ internal class DefaultDocumentableMerger(val context: DokkaContext) : Documentab
}
}

fun DPackage.mergeWith(other: DPackage): DPackage = copy(
public fun DPackage.mergeWith(other: DPackage): DPackage = copy(
functions = mergeExpectActual(functions + other.functions) { f1, f2 -> f1.mergeWith(f2) },
properties = mergeExpectActual(properties + other.properties) { p1, p2 -> p1.mergeWith(p2) },
classlikes = mergeExpectActual(classlikes + other.classlikes) { c1, c2 -> c1.mergeWith(c2) },
Expand All @@ -133,7 +142,7 @@ internal class DefaultDocumentableMerger(val context: DokkaContext) : Documentab
sourceSets = sourceSets + other.sourceSets
).mergeExtras(this, other)

fun DFunction.mergeWith(other: DFunction): DFunction = copy(
public fun DFunction.mergeWith(other: DFunction): DFunction = copy(
parameters = merge(this.parameters + other.parameters) { p1, p2 -> p1.mergeWith(p2) },
receiver = receiver?.let { r -> other.receiver?.let { r.mergeWith(it) } ?: r } ?: other.receiver,
documentation = documentation + other.documentation,
Expand All @@ -145,7 +154,7 @@ internal class DefaultDocumentableMerger(val context: DokkaContext) : Documentab
generics = merge(generics + other.generics) { tp1, tp2 -> tp1.mergeWith(tp2) },
).mergeExtras(this, other)

fun DProperty.mergeWith(other: DProperty): DProperty = copy(
public fun DProperty.mergeWith(other: DProperty): DProperty = copy(
receiver = receiver?.let { r -> other.receiver?.let { r.mergeWith(it) } ?: r } ?: other.receiver,
documentation = documentation + other.documentation,
expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet,
Expand All @@ -158,7 +167,7 @@ internal class DefaultDocumentableMerger(val context: DokkaContext) : Documentab
generics = merge(generics + other.generics) { tp1, tp2 -> tp1.mergeWith(tp2) },
).mergeExtras(this, other)

fun DClasslike.mergeWith(other: DClasslike): DClasslike = when {
private fun DClasslike.mergeWith(other: DClasslike): DClasslike = when {
this is DClass && other is DClass -> mergeWith(other)
this is DEnum && other is DEnum -> mergeWith(other)
this is DInterface && other is DInterface -> mergeWith(other)
Expand All @@ -167,7 +176,7 @@ internal class DefaultDocumentableMerger(val context: DokkaContext) : Documentab
else -> throw IllegalStateException("${this::class.qualifiedName} ${this.name} cannot be merged with ${other::class.qualifiedName} ${other.name}")
}

fun DClass.mergeWith(other: DClass): DClass = copy(
private fun DClass.mergeWith(other: DClass): DClass = copy(
constructors = mergeExpectActual(
constructors + other.constructors
) { f1, f2 -> f1.mergeWith(f2) },
Expand All @@ -185,7 +194,7 @@ internal class DefaultDocumentableMerger(val context: DokkaContext) : Documentab
sourceSets = sourceSets + other.sourceSets
).mergeExtras(this, other)

fun DEnum.mergeWith(other: DEnum): DEnum = copy(
private fun DEnum.mergeWith(other: DEnum): DEnum = copy(
entries = merge(entries + other.entries) { ee1, ee2 -> ee1.mergeWith(ee2) },
constructors = mergeExpectActual(
constructors + other.constructors
Expand All @@ -202,7 +211,7 @@ internal class DefaultDocumentableMerger(val context: DokkaContext) : Documentab
sourceSets = sourceSets + other.sourceSets
).mergeExtras(this, other)

fun DEnumEntry.mergeWith(other: DEnumEntry): DEnumEntry = copy(
private fun DEnumEntry.mergeWith(other: DEnumEntry): DEnumEntry = copy(
functions = mergeExpectActual(functions + other.functions) { f1, f2 -> f1.mergeWith(f2) },
properties = mergeExpectActual(properties + other.properties) { p1, p2 -> p1.mergeWith(p2) },
classlikes = mergeExpectActual(classlikes + other.classlikes) { c1, c2 -> c1.mergeWith(c2) },
Expand All @@ -211,7 +220,7 @@ internal class DefaultDocumentableMerger(val context: DokkaContext) : Documentab
sourceSets = sourceSets + other.sourceSets
).mergeExtras(this, other)

fun DObject.mergeWith(other: DObject): DObject = copy(
private fun DObject.mergeWith(other: DObject): DObject = copy(
functions = mergeExpectActual(functions + other.functions) { f1, f2 -> f1.mergeWith(f2) },
properties = mergeExpectActual(properties + other.properties) { p1, p2 -> p1.mergeWith(p2) },
classlikes = mergeExpectActual(classlikes + other.classlikes) { c1, c2 -> c1.mergeWith(c2) },
Expand All @@ -223,7 +232,7 @@ internal class DefaultDocumentableMerger(val context: DokkaContext) : Documentab
sourceSets = sourceSets + other.sourceSets
).mergeExtras(this, other)

fun DInterface.mergeWith(other: DInterface): DInterface = copy(
private fun DInterface.mergeWith(other: DInterface): DInterface = copy(
functions = mergeExpectActual(functions + other.functions) { f1, f2 -> f1.mergeWith(f2) },
properties = mergeExpectActual(properties + other.properties) { p1, p2 -> p1.mergeWith(p2) },
classlikes = mergeExpectActual(classlikes + other.classlikes) { c1, c2 -> c1.mergeWith(c2) },
Expand All @@ -237,7 +246,7 @@ internal class DefaultDocumentableMerger(val context: DokkaContext) : Documentab
sourceSets = sourceSets + other.sourceSets
).mergeExtras(this, other)

fun DAnnotation.mergeWith(other: DAnnotation): DAnnotation = copy(
private fun DAnnotation.mergeWith(other: DAnnotation): DAnnotation = copy(
constructors = mergeExpectActual(
constructors + other.constructors
) { f1, f2 -> f1.mergeWith(f2) },
Expand All @@ -253,19 +262,19 @@ internal class DefaultDocumentableMerger(val context: DokkaContext) : Documentab
generics = merge(generics + other.generics) { tp1, tp2 -> tp1.mergeWith(tp2) }
).mergeExtras(this, other)

fun DParameter.mergeWith(other: DParameter): DParameter = copy(
private fun DParameter.mergeWith(other: DParameter): DParameter = copy(
documentation = documentation + other.documentation,
expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet,
sourceSets = sourceSets + other.sourceSets
).mergeExtras(this, other)

fun DTypeParameter.mergeWith(other: DTypeParameter): DTypeParameter = copy(
private fun DTypeParameter.mergeWith(other: DTypeParameter): DTypeParameter = copy(
documentation = documentation + other.documentation,
expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet,
sourceSets = sourceSets + other.sourceSets
).mergeExtras(this, other)

fun DTypeAlias.mergeWith(other: DTypeAlias): DTypeAlias = copy(
private fun DTypeAlias.mergeWith(other: DTypeAlias): DTypeAlias = copy(
documentation = documentation + other.documentation,
expectPresentInSet = expectPresentInSet ?: other.expectPresentInSet,
underlyingType = underlyingType + other.underlyingType,
Expand All @@ -285,3 +294,14 @@ public data class ClashingDriIdentifier(val value: Set<DokkaConfiguration.DokkaS

override val key: ExtraProperty.Key<Documentable, *> = ClashingDriIdentifier
}

// TODO [beresnev] remove this copy-paste and use the same method from stdlib instead after updating to 1.5
private inline fun <T, R : Any> Iterable<T>.firstNotNullOfOrNull(transform: (T) -> R?): R? {
for (element in this) {
val result = transform(element)
if (result != null) {
return result
}
}
return null
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public abstract class AbstractTest<M : TestMethods, T : TestBuilder<M>, D : Dokk
block(tempDir)
} finally {
if (cleanUpAfterUse) {
tempDir.delete()
tempDir.deleteRecursively()
}
}
}
Expand Down
18 changes: 0 additions & 18 deletions plugins/base/api/base.api
Original file line number Diff line number Diff line change
Expand Up @@ -1103,24 +1103,6 @@ public final class org/jetbrains/dokka/base/transformers/documentables/CallableE
public fun mergeStrategyFor (Lorg/jetbrains/dokka/base/transformers/documentables/CallableExtensions;Lorg/jetbrains/dokka/base/transformers/documentables/CallableExtensions;)Lorg/jetbrains/dokka/model/properties/MergeStrategy;
}

public final class org/jetbrains/dokka/base/transformers/documentables/ClashingDriIdentifier : org/jetbrains/dokka/model/properties/ExtraProperty {
public static final field Companion Lorg/jetbrains/dokka/base/transformers/documentables/ClashingDriIdentifier$Companion;
public fun <init> (Ljava/util/Set;)V
public final fun component1 ()Ljava/util/Set;
public final fun copy (Ljava/util/Set;)Lorg/jetbrains/dokka/base/transformers/documentables/ClashingDriIdentifier;
public static synthetic fun copy$default (Lorg/jetbrains/dokka/base/transformers/documentables/ClashingDriIdentifier;Ljava/util/Set;ILjava/lang/Object;)Lorg/jetbrains/dokka/base/transformers/documentables/ClashingDriIdentifier;
public fun equals (Ljava/lang/Object;)Z
public fun getKey ()Lorg/jetbrains/dokka/model/properties/ExtraProperty$Key;
public final fun getValue ()Ljava/util/Set;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class org/jetbrains/dokka/base/transformers/documentables/ClashingDriIdentifier$Companion : org/jetbrains/dokka/model/properties/ExtraProperty$Key {
public synthetic fun mergeStrategyFor (Ljava/lang/Object;Ljava/lang/Object;)Lorg/jetbrains/dokka/model/properties/MergeStrategy;
public fun mergeStrategyFor (Lorg/jetbrains/dokka/base/transformers/documentables/ClashingDriIdentifier;Lorg/jetbrains/dokka/base/transformers/documentables/ClashingDriIdentifier;)Lorg/jetbrains/dokka/model/properties/MergeStrategy;
}

public final class org/jetbrains/dokka/base/transformers/documentables/DeprecatedDocumentableFilterTransformer : org/jetbrains/dokka/base/transformers/documentables/SuppressedByConditionDocumentableFilterTransformer {
public fun <init> (Lorg/jetbrains/dokka/plugability/DokkaContext;)V
public fun shouldBeSuppressed (Lorg/jetbrains/dokka/model/Documentable;)Z
Expand Down
5 changes: 1 addition & 4 deletions plugins/base/src/main/kotlin/DokkaBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ import org.jetbrains.dokka.base.translators.documentables.DefaultDocumentableToP
import org.jetbrains.dokka.generation.Generation
import org.jetbrains.dokka.plugability.*
import org.jetbrains.dokka.renderers.Renderer
import org.jetbrains.dokka.transformers.documentation.DocumentableMerger
import org.jetbrains.dokka.transformers.documentation.DocumentableToPageTranslator
import org.jetbrains.dokka.transformers.documentation.DocumentableTransformer
import org.jetbrains.dokka.transformers.documentation.PreMergeDocumentableTransformer
import org.jetbrains.dokka.transformers.documentation.*
import org.jetbrains.dokka.transformers.pages.PageTransformer

@Suppress("unused")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

package org.jetbrains.dokka.base.transformers.documentables

@Deprecated(
message = "Declaration was moved to dokka-core",
replaceWith = ReplaceWith("org.jetbrains.dokka.transformers.documentation.ClashingDriIdentifier"),
level = DeprecationLevel.WARNING // TODO change to error after Kotlin 1.9.20
)
public typealias ClashingDriIdentifier = org.jetbrains.dokka.transformers.documentation.ClashingDriIdentifier
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.jetbrains.dokka.base.DokkaBaseConfiguration
import org.jetbrains.dokka.base.resolvers.anchors.SymbolAnchorHint
import org.jetbrains.dokka.base.signatures.SignatureProvider
import org.jetbrains.dokka.base.transformers.documentables.CallableExtensions
import org.jetbrains.dokka.base.transformers.documentables.ClashingDriIdentifier
import org.jetbrains.dokka.transformers.documentation.ClashingDriIdentifier
import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter
import org.jetbrains.dokka.base.transformers.pages.tags.CustomTagContentProvider
import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder.DocumentableContentBuilder
Expand Down
20 changes: 20 additions & 0 deletions subprojects/analysis-kotlin-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,30 @@ import org.jetbrains.registerDokkaArtifactPublication
plugins {
id("org.jetbrains.conventions.kotlin-jvm")
id("org.jetbrains.conventions.maven-publish")
`java-test-fixtures`
}

dependencies {
compileOnly(projects.core)

testFixturesApi(projects.core)

testImplementation(kotlin("test"))
testImplementation(projects.subprojects.analysisKotlinDescriptors)
}

disableTestFixturesPublishing()

/**
* Test fixtures are automatically published by default, which at this moment in time is unwanted
* as the test api is unstable and is internal to the Dokka project, so it shouldn't be used outside of it.
*
* @see https://docs.gradle.org/current/userguide/java_testing.html#ex-disable-publishing-of-test-fixtures-variants
*/
fun disableTestFixturesPublishing() {
val javaComponent = components["java"] as AdhocComponentWithVariants
javaComponent.withVariantsFromConfiguration(configurations["testFixturesApiElements"]) { skip() }
javaComponent.withVariantsFromConfiguration(configurations["testFixturesRuntimeElements"]) { skip() }
}

registerDokkaArtifactPublication("analysisKotlinApi") {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

package org.jetbrains.dokka.analysis.test.jvm.java

import org.jetbrains.dokka.analysis.test.api.javaTestProject
import org.jetbrains.dokka.analysis.test.api.parse
import kotlin.test.Test
import kotlin.test.assertEquals

class JavaAnalysisTest {

@Test
fun javaTestProject() {
val testProject = javaTestProject {
dokkaConfiguration {
moduleName = "java-module-name-for-unit-test"
}
javaFile(pathFromSrc = "org/jetbrains/dokka/test/java/Bar.java") {
+"""
public class Bar {
public static void bar() {
System.out.println("Bar");
}
}
"""
}
}

val module = testProject.parse()
assertEquals("java-module-name-for-unit-test", module.name)
assertEquals(1, module.packages.size)

val pckg = module.packages[0]
assertEquals("org.jetbrains.dokka.test.java", pckg.name)
assertEquals(1, pckg.classlikes.size)

val fooClass = pckg.classlikes[0]
assertEquals("Bar", fooClass.name)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

package org.jetbrains.dokka.analysis.test.jvm.kotlin

import org.jetbrains.dokka.analysis.test.api.kotlinJvmTestProject
import org.jetbrains.dokka.analysis.test.api.parse
import kotlin.test.Test
import kotlin.test.assertEquals

class KotlinJvmAnalysisTest {

@Test
fun kotlinJvmTestProject() {
val testProject = kotlinJvmTestProject {
ktFile(pathFromSrc = "org/jetbrains/dokka/test/kotlin/MyFile.kt") {
+"public class Foo {}"
}
}

val module = testProject.parse()
assertEquals(1, module.packages.size)

val pckg = module.packages[0]
assertEquals("org.jetbrains.dokka.test.kotlin", pckg.name)
assertEquals(1, pckg.classlikes.size)

val fooClass = pckg.classlikes[0]
assertEquals("Foo", fooClass.name)
}
}
Loading

0 comments on commit b6a6ca8

Please sign in to comment.