diff options
| author | Ignat Beresnev <ignat.beresnev@jetbrains.com> | 2023-11-10 11:46:54 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-10 11:46:54 +0100 |
| commit | 8e5c63d035ef44a269b8c43430f43f5c8eebfb63 (patch) | |
| tree | 1b915207b2b9f61951ddbf0ff2e687efd053d555 /subprojects/analysis-kotlin-symbols | |
| parent | a44efd4ba0c2e4ab921ff75e0f53fc9335aa79db (diff) | |
| download | dokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.tar.gz dokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.tar.bz2 dokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.zip | |
Restructure the project to utilize included builds (#3174)
* Refactor and simplify artifact publishing
* Update Gradle to 8.4
* Refactor and simplify convention plugins and build scripts
Fixes #3132
---------
Co-authored-by: Adam <897017+aSemy@users.noreply.github.com>
Co-authored-by: Oleg Yukhnevich <whyoleg@gmail.com>
Diffstat (limited to 'subprojects/analysis-kotlin-symbols')
41 files changed, 0 insertions, 3545 deletions
diff --git a/subprojects/analysis-kotlin-symbols/README.md b/subprojects/analysis-kotlin-symbols/README.md deleted file mode 100644 index 12e3041c..00000000 --- a/subprojects/analysis-kotlin-symbols/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# Analysis: Kotlin symbols - -An internal symbols-based implementation for [analysis-kotlin-api](../analysis-kotlin-api), also known as K2 or -"the new compiler". - -Contains no stable public API and must not be used by anyone directly, only via [analysis-kotlin-api](../analysis-kotlin-api). - -Can be added as a runtime dependency by the runner. diff --git a/subprojects/analysis-kotlin-symbols/api/analysis-kotlin-symbols.api b/subprojects/analysis-kotlin-symbols/api/analysis-kotlin-symbols.api deleted file mode 100644 index 4bddfcf1..00000000 --- a/subprojects/analysis-kotlin-symbols/api/analysis-kotlin-symbols.api +++ /dev/null @@ -1,19 +0,0 @@ -public final class org/jetbrains/dokka/analysis/kotlin/symbols/plugin/SymbolsAnalysisPlugin : org/jetbrains/dokka/plugability/DokkaPlugin { - public fun <init> ()V -} - -public class org/jetbrains/dokka/analysis/kotlin/symbols/services/KotlinSampleProvider : org/jetbrains/dokka/analysis/kotlin/internal/SampleProvider { - public fun <init> (Lorg/jetbrains/dokka/plugability/DokkaContext;)V - public fun close ()V - public final fun getContext ()Lorg/jetbrains/dokka/plugability/DokkaContext; - public fun getSample (Lorg/jetbrains/dokka/DokkaConfiguration$DokkaSourceSet;Ljava/lang/String;)Lorg/jetbrains/dokka/analysis/kotlin/internal/SampleProvider$SampleSnippet; - protected fun processBody (Lcom/intellij/psi/PsiElement;)Ljava/lang/String; - protected fun processImports (Lcom/intellij/psi/PsiElement;)Ljava/lang/String; -} - -public final class org/jetbrains/dokka/analysis/kotlin/symbols/services/KotlinSampleProviderFactory : org/jetbrains/dokka/analysis/kotlin/internal/SampleProviderFactory { - public fun <init> (Lorg/jetbrains/dokka/plugability/DokkaContext;)V - public fun build ()Lorg/jetbrains/dokka/analysis/kotlin/internal/SampleProvider; - public final fun getContext ()Lorg/jetbrains/dokka/plugability/DokkaContext; -} - diff --git a/subprojects/analysis-kotlin-symbols/build.gradle.kts b/subprojects/analysis-kotlin-symbols/build.gradle.kts deleted file mode 100644 index 610462a3..00000000 --- a/subprojects/analysis-kotlin-symbols/build.gradle.kts +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -import org.jetbrains.DokkaPublicationBuilder -import org.jetbrains.registerDokkaArtifactPublication - -plugins { - id("org.jetbrains.conventions.kotlin-jvm") - id("org.jetbrains.conventions.maven-publish") - id("com.github.johnrengelman.shadow") -} - -dependencies { - compileOnly(projects.core) - compileOnly(projects.subprojects.analysisKotlinApi) - - implementation(projects.subprojects.analysisMarkdownJb) - implementation(projects.subprojects.analysisJavaPsi) - - - // ----------- IDE dependencies ---------------------------------------------------------------------------- - - listOf( - libs.intellij.platform.util.rt, - libs.intellij.platform.util.api, - libs.intellij.java.psi.api, - libs.intellij.java.psi.impl - ).forEach { - runtimeOnly(it) { isTransitive = false } - } - - implementation(libs.intellij.java.psi.api) { isTransitive = false } - - - // TODO move to toml - listOf( - "com.jetbrains.intellij.platform:util-class-loader", - "com.jetbrains.intellij.platform:util-text-matching", - "com.jetbrains.intellij.platform:util-base", - "com.jetbrains.intellij.platform:util-xml-dom", - "com.jetbrains.intellij.platform:core-impl", - "com.jetbrains.intellij.platform:extensions", - ).forEach { - runtimeOnly("$it:213.7172.25") { isTransitive = false } - } - - implementation("com.jetbrains.intellij.platform:core:213.7172.25") { - isTransitive = false - } // for Standalone prototype - - // ----------- Analysis dependencies ---------------------------------------------------------------------------- - - listOf( - libs.kotlin.high.level.api.api, - libs.kotlin.analysis.api.standalone, - ).forEach { - implementation(it) { - isTransitive = false // see KTIJ-19820 - } - } - listOf( - libs.kotlin.high.level.api.impl, - libs.kotlin.high.level.api.fir, - libs.kotlin.high.level.api.fe10, - libs.kotlin.low.level.api.fir, - libs.kotlin.analysis.project.structure, - libs.kotlin.analysis.api.providers, - libs.kotlin.symbol.light.classes, - ).forEach { - runtimeOnly(it) { - isTransitive = false // see KTIJ-19820 - } - } - // copy-pasted from Analysis API https://github.com/JetBrains/kotlin/blob/a10042f9099e20a656dec3ecf1665eea340a3633/analysis/low-level-api-fir/build.gradle.kts#L37 - runtimeOnly("com.github.ben-manes.caffeine:caffeine:2.9.3") - - runtimeOnly(libs.kotlinx.collections.immutable) - implementation(libs.kotlin.compiler.k2) { - isTransitive = false - } - - // TODO [beresnev] get rid of it - compileOnly(libs.kotlinx.coroutines.core) -} - -tasks { - shadowJar { - val dokka_version: String by project - - // cannot be named exactly like the artifact (i.e analysis-kotlin-symbols-VER.jar), - // otherwise leads to obscure test failures when run via CLI, but not via IJ - archiveFileName.set("analysis-kotlin-symbols-all-$dokka_version.jar") - archiveClassifier.set("") - - // service files are merged to make sure all Dokka plugins - // from the dependencies are loaded, and not just a single one. - mergeServiceFiles() - } -} - -registerDokkaArtifactPublication("analysisKotlinSymbols") { - artifactId = "analysis-kotlin-symbols" - component = DokkaPublicationBuilder.Component.Shadow -} diff --git a/subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/kdoc/KDocProvider.kt b/subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/kdoc/KDocProvider.kt deleted file mode 100644 index d8a4e476..00000000 --- a/subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/kdoc/KDocProvider.kt +++ /dev/null @@ -1,174 +0,0 @@ -/* - * 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.kotlin.symbols.kdoc - -import com.intellij.psi.PsiNamedElement -import com.intellij.psi.util.PsiTreeUtil -import org.jetbrains.dokka.analysis.java.parsers.JavadocParser -import org.jetbrains.dokka.model.doc.DocumentationNode -import org.jetbrains.dokka.utilities.DokkaLogger -import org.jetbrains.kotlin.analysis.api.KtAnalysisSession -import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol -import org.jetbrains.kotlin.analysis.api.symbols.KtClassOrObjectSymbol -import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol -import org.jetbrains.kotlin.analysis.api.symbols.KtSymbolOrigin -import org.jetbrains.kotlin.analysis.api.symbols.markers.KtNamedSymbol -import org.jetbrains.kotlin.kdoc.parser.KDocKnownTag -import org.jetbrains.kotlin.kdoc.psi.api.KDoc -import org.jetbrains.kotlin.kdoc.psi.impl.KDocSection -import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag -import org.jetbrains.kotlin.psi.* -import org.jetbrains.kotlin.psi.psiUtil.findDescendantOfType -import org.jetbrains.kotlin.psi.psiUtil.getChildOfType -import org.jetbrains.kotlin.psi.psiUtil.getChildrenOfType -import org.jetbrains.kotlin.psi.psiUtil.isPropertyParameter -import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly - -internal fun KtAnalysisSession.getJavaDocDocumentationFrom( - symbol: KtSymbol, - javadocParser: JavadocParser -): DocumentationNode? { - if (symbol.origin == KtSymbolOrigin.JAVA) { - return (symbol.psi as? PsiNamedElement)?.let { - javadocParser.parseDocumentation(it) - } - } else if (symbol.origin == KtSymbolOrigin.SOURCE && symbol is KtCallableSymbol) { - // Note: javadocParser searches in overridden JAVA declarations for JAVA method, not Kotlin - symbol.getAllOverriddenSymbols().forEach { overrider -> - if (overrider.origin == KtSymbolOrigin.JAVA) - return@getJavaDocDocumentationFrom (overrider.psi as? PsiNamedElement)?.let { - javadocParser.parseDocumentation(it) - } - } - } - return null -} - -internal fun KtAnalysisSession.getKDocDocumentationFrom(symbol: KtSymbol, logger: DokkaLogger) = findKDoc(symbol)?.let { kDocContent -> - - val ktElement = symbol.psi - val kdocLocation = ktElement?.containingFile?.name?.let { - val name = when(symbol) { - is KtCallableSymbol -> symbol.callableIdIfNonLocal?.toString() - is KtClassOrObjectSymbol -> symbol.classIdIfNonLocal?.toString() - is KtNamedSymbol -> symbol.name.asString() - else -> null - }?.replace('/', '.') // replace to be compatible with K1 - - if (name != null) "$it/$name" - else it - } - - - parseFromKDocTag( - kDocTag = kDocContent.contentTag, - externalDri = { link -> resolveKDocLink(link).ifUnresolved { logger.logUnresolvedLink(link.getLinkText(), kdocLocation) } }, - kdocLocation = kdocLocation - ) -} - - - - -// ----------- copy-paste from IDE ---------------------------------------------------------------------------- - -internal data class KDocContent( - val contentTag: KDocTag, - val sections: List<KDocSection> -) - -internal fun KtAnalysisSession.findKDoc(symbol: KtSymbol): KDocContent? { - // for generated function (e.g. `copy`) psi returns class, see test `data class kdocs over generated methods` - if (symbol.origin != KtSymbolOrigin.SOURCE) return null - val ktElement = symbol.psi as? KtElement - ktElement?.findKDoc()?.let { - return it - } - - if (symbol is KtCallableSymbol) { - symbol.getAllOverriddenSymbols().forEach { overrider -> - findKDoc(overrider)?.let { - return it - } - } - } - return null -} - - -internal fun KtElement.findKDoc(): KDocContent? = this.lookupOwnedKDoc() - ?: this.lookupKDocInContainer() - - - -private fun KtElement.lookupOwnedKDoc(): KDocContent? { - // KDoc for primary constructor is located inside of its class KDoc - val psiDeclaration = when (this) { - is KtPrimaryConstructor -> getContainingClassOrObject() - else -> this - } - - if (psiDeclaration is KtDeclaration) { - val kdoc = psiDeclaration.docComment - if (kdoc != null) { - if (this is KtConstructor<*>) { - // ConstructorDescriptor resolves to the same JetDeclaration - val constructorSection = kdoc.findSectionByTag(KDocKnownTag.CONSTRUCTOR) - if (constructorSection != null) { - // if annotated with @constructor tag and the caret is on constructor definition, - // then show @constructor description as the main content, and additional sections - // that contain @param tags (if any), as the most relatable ones - // practical example: val foo = Fo<caret>o("argument") -- show @constructor and @param content - val paramSections = kdoc.findSectionsContainingTag(KDocKnownTag.PARAM) - return KDocContent(constructorSection, paramSections) - } - } - return KDocContent(kdoc.getDefaultSection(), kdoc.getAllSections()) - } - } - - return null -} - -/** - * Looks for sections that have a deeply nested [tag], - * as opposed to [KDoc.findSectionByTag], which only looks among the top level - */ -private fun KDoc.findSectionsContainingTag(tag: KDocKnownTag): List<KDocSection> { - return getChildrenOfType<KDocSection>() - .filter { it.findTagByName(tag.name.toLowerCaseAsciiOnly()) != null } -} - -private fun KtElement.lookupKDocInContainer(): KDocContent? { - val subjectName = name - val containingDeclaration = - PsiTreeUtil.findFirstParent(this, true) { - it is KtDeclarationWithBody && it !is KtPrimaryConstructor - || it is KtClassOrObject - } - - val containerKDoc = containingDeclaration?.getChildOfType<KDoc>() - if (containerKDoc == null || subjectName == null) return null - val propertySection = containerKDoc.findSectionByTag(KDocKnownTag.PROPERTY, subjectName) - val paramTag = - containerKDoc.findDescendantOfType<KDocTag> { it.knownTag == KDocKnownTag.PARAM && it.getSubjectName() == subjectName } - - val primaryContent = when { - // class Foo(val <caret>s: String) - this is KtParameter && this.isPropertyParameter() -> propertySection ?: paramTag - // fun some(<caret>f: String) || class Some<<caret>T: Base> || Foo(<caret>s = "argument") - this is KtParameter || this is KtTypeParameter -> paramTag - // if this property is declared separately (outside primary constructor), but it's for some reason - // annotated as @property in class's description, instead of having its own KDoc - this is KtProperty && containingDeclaration is KtClassOrObject -> propertySection - else -> null - } - return primaryContent?.let { - // makes little sense to include any other sections, since we found - // documentation for a very specific element, like a property/param - KDocContent(it, sections = emptyList()) - } -} - diff --git a/subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/kdoc/KdocMarkdownParser.kt b/subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/kdoc/KdocMarkdownParser.kt deleted file mode 100644 index ad29f5f0..00000000 --- a/subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/kdoc/KdocMarkdownParser.kt +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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.kotlin.symbols.kdoc - -import com.intellij.psi.PsiElement -import org.jetbrains.dokka.analysis.markdown.jb.MarkdownParser -import org.jetbrains.dokka.analysis.markdown.jb.MarkdownParser.Companion.fqDeclarationName -import org.jetbrains.dokka.links.DRI -import org.jetbrains.dokka.model.doc.* -import org.jetbrains.dokka.model.doc.Suppress -import org.jetbrains.kotlin.kdoc.parser.KDocKnownTag -import org.jetbrains.kotlin.kdoc.psi.impl.KDocLink -import org.jetbrains.kotlin.kdoc.psi.impl.KDocSection -import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag -import org.jetbrains.kotlin.psi.psiUtil.allChildren - -internal fun parseFromKDocTag( - kDocTag: KDocTag?, - externalDri: (KDocLink) -> DRI?, - kdocLocation: String?, - parseWithChildren: Boolean = true -): DocumentationNode { - return if (kDocTag == null) { - DocumentationNode(emptyList()) - } else { - fun parseStringToDocNode(text: String, externalDRIProvider: (String) -> DRI?) = - MarkdownParser(externalDRIProvider, kdocLocation).parseStringToDocNode(text) - - fun pointedLink(tag: KDocTag): DRI? = tag.getSubjectLink()?.let(externalDri) - - val allTags = - listOf(kDocTag) + if (kDocTag.canHaveParent() && parseWithChildren) getAllKDocTags(findParent(kDocTag)) else emptyList() - DocumentationNode( - allTags.map { tag -> - val links = tag.allChildren.filterIsInstance<KDocLink>().associate { it.getLinkText() to externalDri(it) } - val externalDRIProvider = { linkText: String -> links[linkText] } - - when (tag.knownTag) { - null -> if (tag.name == null) Description(parseStringToDocNode(tag.getContent(), externalDRIProvider)) else CustomTagWrapper( - parseStringToDocNode(tag.getContent(), externalDRIProvider), - tag.name!! - ) - KDocKnownTag.AUTHOR -> Author(parseStringToDocNode(tag.getContent(), externalDRIProvider)) - KDocKnownTag.THROWS -> { - val dri = pointedLink(tag) - Throws( - parseStringToDocNode(tag.getContent(), externalDRIProvider), - dri?.fqDeclarationName() ?: tag.getSubjectName().orEmpty(), - dri, - ) - } - KDocKnownTag.EXCEPTION -> { - val dri = pointedLink(tag) - Throws( - parseStringToDocNode(tag.getContent(), externalDRIProvider), - dri?.fqDeclarationName() ?: tag.getSubjectName().orEmpty(), - dri - ) - } - KDocKnownTag.PARAM -> Param( - parseStringToDocNode(tag.getContent(), externalDRIProvider), - tag.getSubjectName().orEmpty() - ) - KDocKnownTag.RECEIVER -> Receiver(parseStringToDocNode(tag.getContent(), externalDRIProvider)) - KDocKnownTag.RETURN -> Return(parseStringToDocNode(tag.getContent(), externalDRIProvider)) - KDocKnownTag.SEE -> { - val dri = pointedLink(tag) - See( - parseStringToDocNode(tag.getContent(), externalDRIProvider), - dri?.fqDeclarationName() ?: tag.getSubjectName().orEmpty(), - dri, - ) - } - KDocKnownTag.SINCE -> Since(parseStringToDocNode(tag.getContent(), externalDRIProvider)) - KDocKnownTag.CONSTRUCTOR -> Constructor(parseStringToDocNode(tag.getContent(), externalDRIProvider)) - KDocKnownTag.PROPERTY -> Property( - parseStringToDocNode(tag.getContent(), externalDRIProvider), - tag.getSubjectName().orEmpty() - ) - KDocKnownTag.SAMPLE -> Sample( - parseStringToDocNode(tag.getContent(), externalDRIProvider), - tag.getSubjectName().orEmpty() - ) - KDocKnownTag.SUPPRESS -> Suppress(parseStringToDocNode(tag.getContent(), externalDRIProvider)) - } - } - ) - } -} - -private fun findParent(kDoc: PsiElement): PsiElement = - if (kDoc.canHaveParent()) findParent(kDoc.parent) else kDoc - -private fun PsiElement.canHaveParent(): Boolean = this is KDocSection && knownTag != KDocKnownTag.PROPERTY - -private fun getAllKDocTags(kDocImpl: PsiElement): List<KDocTag> = - kDocImpl.children.filterIsInstance<KDocTag>().filterNot { it is KDocSection } + kDocImpl.children.flatMap { - getAllKDocTags(it) - } diff --git a/subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/kdoc/ResolveKDocLink.kt b/subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/kdoc/ResolveKDocLink.kt deleted file mode 100644 index 9a0b81bd..00000000 --- a/subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/kdoc/ResolveKDocLink.kt +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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.kotlin.symbols.kdoc - -import com.intellij.psi.PsiElement -import org.jetbrains.dokka.analysis.kotlin.symbols.translators.getDRIFromSymbol -import org.jetbrains.dokka.links.DRI -import org.jetbrains.dokka.utilities.DokkaLogger -import org.jetbrains.kotlin.analysis.api.KtAnalysisSession -import org.jetbrains.kotlin.idea.references.mainReference -import org.jetbrains.kotlin.kdoc.psi.api.KDoc -import org.jetbrains.kotlin.kdoc.psi.impl.KDocLink -import org.jetbrains.kotlin.kdoc.psi.impl.KDocName -import org.jetbrains.kotlin.psi.KtPsiFactory - -/** - * Util to print a message about unresolved [link] - */ -internal fun DokkaLogger.logUnresolvedLink(link: String, location: String?) { - warn("Couldn't resolve link for $link" + if (location != null) " in $location" else "") -} - -internal inline fun DRI?.ifUnresolved(action: () -> Unit): DRI? = this ?: run { - action() - null -} - -/** - * Resolves KDoc link via creating PSI. - * If the [link] is ambiguous, i.e. leads to more than one declaration, - * it returns deterministically any declaration. - * - * @return [DRI] or null if the [link] is unresolved - */ -internal fun KtAnalysisSession.resolveKDocTextLink(link: String, context: PsiElement? = null): DRI? { - val psiFactory = co |
