Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decompose Kotlin/Java analysis #3034

Merged
merged 3 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 0 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ apiValidation {
// NAME PATH
"frontend", // :plugins:base:frontend

"kotlin-analysis", // :kotlin-analysis
"compiler-dependency", // :kotlin-analysis:compiler-dependency
"intellij-dependency", // :kotlin-analysis:intellij-dependency

"integration-tests", // :integration-tests
"gradle", // :integration-tests:gradle
"cli", // :integration-tests:cli
Expand Down
20 changes: 20 additions & 0 deletions core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,7 @@ public final class org/jetbrains/dokka/model/DocumentableKt {
}

public abstract interface class org/jetbrains/dokka/model/DocumentableSource {
public abstract fun computeLineNumber ()Ljava/lang/Integer;
public abstract fun getPath ()Ljava/lang/String;
}

Expand Down Expand Up @@ -1782,6 +1783,24 @@ public final class org/jetbrains/dokka/model/Invariance : org/jetbrains/dokka/mo
public fun toString ()Ljava/lang/String;
}

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

public final class org/jetbrains/dokka/model/IsAlsoParameter$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/model/IsAlsoParameter;Lorg/jetbrains/dokka/model/IsAlsoParameter;)Lorg/jetbrains/dokka/model/properties/MergeStrategy;
}

public final class org/jetbrains/dokka/model/IsVar : org/jetbrains/dokka/model/properties/ExtraProperty, org/jetbrains/dokka/model/properties/ExtraProperty$Key {
public static final field INSTANCE Lorg/jetbrains/dokka/model/IsVar;
public fun getKey ()Lorg/jetbrains/dokka/model/properties/ExtraProperty$Key;
Expand Down Expand Up @@ -4400,6 +4419,7 @@ public abstract class org/jetbrains/dokka/plugability/DokkaPlugin {
protected final fun extending (Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/dokka/plugability/DokkaPlugin$ExtensionProvider;
protected final fun extensionPoint ()Lkotlin/properties/ReadOnlyProperty;
public final fun getContext ()Lorg/jetbrains/dokka/plugability/DokkaContext;
protected final fun getLogger ()Lorg/jetbrains/dokka/utilities/DokkaLogger;
protected abstract fun pluginApiPreviewAcknowledgement ()Lorg/jetbrains/dokka/plugability/PluginApiPreviewAcknowledgement;
public final fun setContext (Lorg/jetbrains/dokka/plugability/DokkaContext;)V
protected final fun unsafeInstall (Lkotlin/Lazy;)V
Expand Down
7 changes: 1 addition & 6 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ plugins {
}

dependencies {
api(libs.jetbrains.markdown)
implementation(kotlin("reflect"))

implementation(libs.jsoup)

implementation(libs.kotlinx.coroutines.core)
implementation(libs.jackson.kotlin)
implementation(libs.jackson.xml)
constraints {
Expand All @@ -20,8 +17,6 @@ dependencies {
}
}

implementation(libs.kotlinx.coroutines.core)

testImplementation(projects.core.testApi)
testImplementation(kotlin("test-junit"))
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/kotlin/CoreExtensions.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.jetbrains.dokka

import org.jetbrains.dokka.generation.Generation
import org.jetbrains.dokka.plugability.*
import org.jetbrains.dokka.plugability.ExtensionPoint
import org.jetbrains.dokka.renderers.PostAction
import org.jetbrains.dokka.renderers.Renderer
import org.jetbrains.dokka.transformers.documentation.DocumentableMerger
Expand All @@ -28,4 +28,4 @@ object CoreExtensions {
operator fun provideDelegate(thisRef: CoreExtensions, property: KProperty<*>): Lazy<ExtensionPoint<T>> =
lazy { ExtensionPoint(thisRef::class.qualifiedName!!, property.name) }
}
}
}
1 change: 0 additions & 1 deletion core/src/main/kotlin/DokkaBootstrap.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.jetbrains.dokka

import java.util.function.BiConsumer
import kotlin.jvm.Throws

interface DokkaBootstrap {
@Throws(Throwable::class)
Expand Down
5 changes: 4 additions & 1 deletion core/src/main/kotlin/InternalDokkaApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ package org.jetbrains.dokka
level = RequiresOptIn.Level.ERROR,
message = "This is an internal Dokka API not intended for public use"
)
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.FIELD)
@Target(
AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.FIELD,
AnnotationTarget.PROPERTY, AnnotationTarget.TYPEALIAS
)
@Retention(AnnotationRetention.BINARY)
public annotation class InternalDokkaApi()
11 changes: 10 additions & 1 deletion core/src/main/kotlin/model/Documentable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,15 @@ fun <T> SourceSetDependent<T>?.orEmpty(): SourceSetDependent<T> = this ?: emptyM

interface DocumentableSource {
val path: String

/**
* Computes the first line number of the documentable's declaration/signature/identifier.
*
* Numbering is always 1-based.
*
* May return null if the sources could not be found - for example, for synthetic/generated declarations.
*/
fun computeLineNumber(): Int?
}

data class TypeConstructorWithKind(val typeConstructor: TypeConstructor, val kind: ClassKind)
data class TypeConstructorWithKind(val typeConstructor: TypeConstructor, val kind: ClassKind)
2 changes: 1 addition & 1 deletion core/src/main/kotlin/model/WithChildren.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ fun <T : WithChildren<T>> T.asPrintableTree(
}

return buildString { append(this@asPrintableTree, "", "") }
}
}
9 changes: 9 additions & 0 deletions core/src/main/kotlin/model/documentableProperties.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ object IsVar : ExtraProperty<DProperty>, ExtraProperty.Key<DProperty, IsVar> {
override val key: ExtraProperty.Key<DProperty, *> = this
}

data class IsAlsoParameter(val inSourceSets: List<DokkaSourceSet>) : ExtraProperty<DProperty> {
companion object : ExtraProperty.Key<DProperty, IsAlsoParameter> {
override fun mergeStrategyFor(left: IsAlsoParameter, right: IsAlsoParameter): MergeStrategy<DProperty> =
MergeStrategy.Replace(IsAlsoParameter(left.inSourceSets + right.inSourceSets))
}

override val key: ExtraProperty.Key<DProperty, *> = IsAlsoParameter
}

data class CheckedExceptions(val exceptions: SourceSetDependent<List<DRI>>) : ExtraProperty<Documentable>, ExtraProperty.Key<Documentable, ObviousMember> {
companion object : ExtraProperty.Key<Documentable, CheckedExceptions> {
override fun mergeStrategyFor(left: CheckedExceptions, right: CheckedExceptions) =
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/kotlin/plugability/DokkaPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule
import com.fasterxml.jackson.dataformat.xml.XmlMapper
import com.fasterxml.jackson.module.kotlin.readValue
import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.utilities.DokkaLogger
import org.jetbrains.dokka.utilities.parseJson
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
Expand Down Expand Up @@ -33,6 +34,8 @@ abstract class DokkaPlugin {
@PublishedApi
internal var context: DokkaContext? = null

protected val logger: DokkaLogger get() = context?.logger ?: throw IllegalStateException("No logger found")

/**
* @see PluginApiPreviewAcknowledgement
*/
Expand Down
25 changes: 25 additions & 0 deletions core/src/main/kotlin/utilities/Collections.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.jetbrains.dokka.utilities

import org.jetbrains.dokka.InternalDokkaApi

/**
* This utility method was previously imported from `org.jetbrains.kotlin.utils.addToStdlib`,
* and there were a lot of usages. Since no replacement exists in stdlib, it was implemented
* locally for convenience.
*/
@InternalDokkaApi
inline fun <reified T : Any> Iterable<*>.firstIsInstanceOrNull(): T? {
for (element in this) if (element is T) return element
return null
}

/**
* This utility method was previously imported from `org.jetbrains.kotlin.utils.addToStdlib`,
* and there were a lot of usages. Since no replacement exists in stdlib, it was implemented
* locally for convenience.
*/
@InternalDokkaApi
inline fun <reified T : Any> Sequence<*>.firstIsInstanceOrNull(): T? {
for (element in this) if (element is T) return element
return null
}
2 changes: 1 addition & 1 deletion core/src/main/kotlin/utilities/Html.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.jetbrains.dokka.utilities

import org.jetbrains.dokka.*
import org.jetbrains.dokka.InternalDokkaApi
import java.net.URLEncoder


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.jetbrains.dokka.utilities

import org.jetbrains.dokka.*
import org.jetbrains.dokka.InternalDokkaApi

@InternalDokkaApi
interface SelfRepresentingSingletonSet<T : SelfRepresentingSingletonSet<T>> : Set<T> {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/utilities/ServiceLocator.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.jetbrains.dokka.utilities

import org.jetbrains.dokka.*
import org.jetbrains.dokka.InternalDokkaApi
import java.io.File
import java.net.URISyntaxException
import java.net.URL
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/utilities/Uri.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.jetbrains.dokka.utilities

import org.jetbrains.dokka.*
import org.jetbrains.dokka.InternalDokkaApi
import java.net.URI

@InternalDokkaApi
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/utilities/associateWithNotNull.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.jetbrains.dokka.utilities

import org.jetbrains.dokka.*
import org.jetbrains.dokka.InternalDokkaApi

@InternalDokkaApi
inline fun <K, V : Any> Iterable<K>.associateWithNotNull(valueSelector: (K) -> V?): Map<K, V> {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/utilities/cast.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.jetbrains.dokka.utilities

import org.jetbrains.dokka.*
import org.jetbrains.dokka.InternalDokkaApi

@InternalDokkaApi
inline fun <reified T> Any.cast(): T {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.jetbrains.dokka.utilities

import kotlinx.coroutines.*
import org.jetbrains.dokka.*
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import org.jetbrains.dokka.InternalDokkaApi

@InternalDokkaApi
suspend inline fun <A, B> Iterable<A>.parallelMap(crossinline f: suspend (A) -> B): List<B> = coroutineScope {
Expand Down
5 changes: 4 additions & 1 deletion core/src/test/kotlin/utilities/DokkaConfigurationJsonTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package utilities

import org.jetbrains.dokka.*
import org.jetbrains.dokka.DokkaConfigurationImpl
import org.jetbrains.dokka.DokkaSourceSetID
import org.jetbrains.dokka.DokkaSourceSetImpl
import org.jetbrains.dokka.toCompactJsonString
import java.io.File
import kotlin.test.Test
import kotlin.test.assertEquals
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/kotlin/utilities/JsonKtTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package utilities

import org.jetbrains.dokka.utilities.serializeAsCompactJson
import org.jetbrains.dokka.utilities.serializeAsPrettyJson
import kotlin.test.assertEquals
import kotlin.test.Test
import kotlin.test.assertEquals

class JsonTest {

Expand Down
2 changes: 1 addition & 1 deletion core/test-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {

dependencies {
api(projects.core)
implementation(projects.kotlinAnalysis)

implementation("junit:junit:4.13.2") // TODO: remove dependency to junit
implementation(kotlin("reflect"))
}
Expand Down
2 changes: 1 addition & 1 deletion core/test-api/src/main/kotlin/testApi/logger/TestLogger.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.jetbrains.dokka.testApi.logger

import org.jetbrains.dokka.utilities.DokkaLogger
import java.util.Collections
import java.util.*

/*
* Even in tests it be used in a concurrent environment, so needs to be thread safe
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package testApi.testRunner

import org.intellij.markdown.MarkdownElementTypes
import org.jetbrains.dokka.*
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.*
Expand Down Expand Up @@ -206,6 +205,5 @@ fun dPackage(
fun documentationNode(vararg texts: String): DocumentationNode {
return DocumentationNode(
texts.toList()
.map { Description(CustomDocTag(listOf(Text(it)), name = MarkdownElementTypes.MARKDOWN_FILE.name)) })
.map { Description(CustomDocTag(listOf(Text(it)), name = "MARKDOWN_FILE")) })
}

25 changes: 16 additions & 9 deletions core/test-api/src/main/kotlin/testApi/testRunner/TestRunner.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.jetbrains.dokka.testApi.testRunner

import com.intellij.openapi.application.PathManager
import org.jetbrains.dokka.*
import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.DokkaConfigurationImpl
import org.jetbrains.dokka.ExternalDocumentationLinkImpl
import org.jetbrains.dokka.model.DModule
import org.jetbrains.dokka.pages.RootPageNode
import org.jetbrains.dokka.plugability.DokkaContext
Expand Down Expand Up @@ -37,7 +38,7 @@ abstract class AbstractTest<M : TestMethods, T : TestBuilder<M>, D : DokkaTestGe
cleanupOutput: Boolean = true,
useOutputLocationFromConfig: Boolean = false,
pluginOverrides: List<DokkaPlugin> = emptyList(),
block: T.() -> Unit
block: T.() -> Unit,
) {
val testMethods = testBuilder().apply(block).build()
val configurationToUse =
Expand Down Expand Up @@ -65,7 +66,7 @@ abstract class AbstractTest<M : TestMethods, T : TestBuilder<M>, D : DokkaTestGe
cleanupOutput: Boolean = true,
pluginOverrides: List<DokkaPlugin> = emptyList(),
loggerForTest: DokkaLogger = logger,
block: T.() -> Unit
block: T.() -> Unit,
) {
val testMethods = testBuilder().apply(block).build()
val testDirPath = getTempDir(cleanupOutput).root.toPath().toAbsolutePath()
Expand Down Expand Up @@ -133,7 +134,7 @@ abstract class AbstractTest<M : TestMethods, T : TestBuilder<M>, D : DokkaTestGe

private fun Map<String, String>.materializeFiles(
root: Path = Paths.get("."),
charset: Charset = Charset.forName("utf-8")
charset: Charset = Charset.forName("utf-8"),
) = this.map { (path, content) ->
val file = root.resolve(path)
Files.createDirectories(file.parent)
Expand All @@ -160,11 +161,17 @@ abstract class AbstractTest<M : TestMethods, T : TestBuilder<M>, D : DokkaTestGe


protected val jvmStdlibPath: String? by lazy {
PathManager.getResourceRoot(Strictfp::class.java, "/kotlin/jvm/Strictfp.class")
ClassLoader.getSystemResource("kotlin/jvm/Strictfp.class")
?.file
?.replace("file:", "")
?.replaceAfter(".jar", "")
}

protected val jsStdlibPath: String? by lazy {
PathManager.getResourceRoot(Any::class.java, "/kotlin/jquery")
ClassLoader.getSystemResource("kotlin/jquery")
?.file
?.replace("file:", "")
?.replaceAfter(".jar", "")
}

protected val commonStdlibPath: String? by lazy {
Expand Down Expand Up @@ -195,7 +202,7 @@ open class CoreTestMethods(
open val documentablesTransformationStage: (DModule) -> Unit,
open val pagesGenerationStage: (RootPageNode) -> Unit,
open val pagesTransformationStage: (RootPageNode) -> Unit,
open val renderingStage: (RootPageNode, DokkaContext) -> Unit
open val renderingStage: (RootPageNode, DokkaContext) -> Unit,
) : TestMethods

abstract class TestBuilder<M : TestMethods> {
Expand All @@ -206,7 +213,7 @@ abstract class DokkaTestGenerator<T : TestMethods>(
protected val configuration: DokkaConfiguration,
protected val logger: DokkaLogger,
protected val testMethods: T,
protected val additionalPlugins: List<DokkaPlugin> = emptyList()
protected val additionalPlugins: List<DokkaPlugin> = emptyList(),
) {
abstract fun generate()
}
Loading