Skip to content

Commit

Permalink
Stabilize ExternalDocumentableProvider (#3312)
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnatBeresnev authored Nov 22, 2023
1 parent 610b552 commit e63dad0
Show file tree
Hide file tree
Showing 17 changed files with 455 additions and 190 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
public final class org/jetbrains/dokka/analysis/kotlin/KotlinAnalysisPlugin : org/jetbrains/dokka/plugability/DokkaPlugin {
public fun <init> ()V
public final fun getExternalDocumentableProvider ()Lorg/jetbrains/dokka/plugability/ExtensionPoint;
public final fun getSampleAnalysisEnvironmentCreator ()Lorg/jetbrains/dokka/plugability/ExtensionPoint;
}

public abstract interface class org/jetbrains/dokka/analysis/kotlin/documentable/ExternalDocumentableProvider {
public abstract fun getClasslike (Lorg/jetbrains/dokka/links/DRI;Lorg/jetbrains/dokka/DokkaConfiguration$DokkaSourceSet;)Lorg/jetbrains/dokka/model/DClasslike;
}

public final class org/jetbrains/dokka/analysis/kotlin/internal/DocumentableLanguage : java/lang/Enum {
public static final field JAVA Lorg/jetbrains/dokka/analysis/kotlin/internal/DocumentableLanguage;
public static final field KOTLIN Lorg/jetbrains/dokka/analysis/kotlin/internal/DocumentableLanguage;
Expand All @@ -14,10 +19,6 @@ public abstract interface class org/jetbrains/dokka/analysis/kotlin/internal/Doc
public abstract fun getLanguage (Lorg/jetbrains/dokka/model/Documentable;Lorg/jetbrains/dokka/DokkaConfiguration$DokkaSourceSet;)Lorg/jetbrains/dokka/analysis/kotlin/internal/DocumentableLanguage;
}

public abstract interface class org/jetbrains/dokka/analysis/kotlin/internal/ExternalDocumentablesProvider {
public abstract fun findClasslike (Lorg/jetbrains/dokka/links/DRI;Lorg/jetbrains/dokka/DokkaConfiguration$DokkaSourceSet;)Lorg/jetbrains/dokka/model/DClasslike;
}

public abstract interface class org/jetbrains/dokka/analysis/kotlin/internal/FullClassHierarchyBuilder {
public abstract fun build (Lorg/jetbrains/dokka/model/DModule;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}
Expand Down Expand Up @@ -47,7 +48,6 @@ public final class org/jetbrains/dokka/analysis/kotlin/internal/InheritanceNode
public final class org/jetbrains/dokka/analysis/kotlin/internal/InternalKotlinAnalysisPlugin : org/jetbrains/dokka/plugability/DokkaPlugin {
public fun <init> ()V
public final fun getDocumentableSourceLanguageParser ()Lorg/jetbrains/dokka/plugability/ExtensionPoint;
public final fun getExternalDocumentablesProvider ()Lorg/jetbrains/dokka/plugability/ExtensionPoint;
public final fun getFullClassHierarchyBuilder ()Lorg/jetbrains/dokka/plugability/ExtensionPoint;
public final fun getInheritanceBuilder ()Lorg/jetbrains/dokka/plugability/ExtensionPoint;
public final fun getKotlinToJavaService ()Lorg/jetbrains/dokka/plugability/ExtensionPoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package org.jetbrains.dokka.analysis.kotlin

import org.jetbrains.dokka.analysis.kotlin.documentable.ExternalDocumentableProvider
import org.jetbrains.dokka.analysis.kotlin.sample.SampleAnalysisEnvironmentCreator
import org.jetbrains.dokka.analysis.kotlin.sample.SampleAnalysisEnvironment
import org.jetbrains.dokka.plugability.DokkaPlugin
Expand All @@ -20,6 +21,14 @@ public class KotlinAnalysisPlugin : DokkaPlugin() {
*/
public val sampleAnalysisEnvironmentCreator: ExtensionPoint<SampleAnalysisEnvironmentCreator> by extensionPoint()

/**
* An extension that helps to find external documentables that are not provided by Dokka by default,
* such as documentables that come from external dependencies.
*
* @see ExternalDocumentableProvider for more details
*/
public val externalDocumentableProvider: ExtensionPoint<ExternalDocumentableProvider> by extensionPoint()

@OptIn(DokkaPluginApiPreview::class)
override fun pluginApiPreviewAcknowledgement(): PluginApiPreviewAcknowledgement = PluginApiPreviewAcknowledgement
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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.documentable

import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.DClasslike
import org.jetbrains.dokka.model.DClass
import org.jetbrains.dokka.transformers.sources.SourceToDocumentableTranslator

/**
* Helps find external documentables that are not provided by Dokka by default.
*
* By default, Dokka parses and makes available only documentables of the declarations found
* in the user project itself. Meaning, if the project's source code contains a `fun foo()`,
* it must be returned by [SourceToDocumentableTranslator]. However, if the user project
* depends on an external library which has a `fun bar()`, it will __not__ be available and
* documented out of the box.
*
* This provider helps you find documentables for the declarations that are present in
* [DokkaSourceSet.classpath] during runtime, but are not necessarily from the user project itself.
*
* For example, it can help you find a class that comes from a dependency, which can be useful
* if you want to get more information about a supertype of the project's class,
* because [DClass.supertypes] only provides the supertype's DRI, but not its full documentable.
*
* It is expected to work with all languages supported by the analysis implementation,
* meaning it should return Java classes if Java as an input language is supported.
*
* If you query DRIs of local project declarations (not external), it should generally work, although
* it's not guaranteed that the returned value will be 100% equal to that provided by Dokka by default.
*
* Note: because classpath entries consist of compiled code, the returned documentables may have some
* properties set to null or empty, because some information cannot be extracted from it in any way.
* One such example is KDocs, they are present in source code, but not in compiled classes.
*/
public interface ExternalDocumentableProvider {

/**
* Returns a valid and fully initialized [DClasslike] if the [dri] points to a class-like
* declaration (annotation, class, enum, interface, object) that can be found among
* [DokkaSourceSet.classpath] entries.
*
* If the [dri] points to a non-class-like declaration (like a function),
* or the declaration cannot be found, it returns `null`.
*
* Note: the implementation is not expected to cache results or return pre-computed values, so
* it may need to analyze parts of the project and instantiate new documentables on every invocation.
* Use this function sparingly, and cache results on your side if you need to.
*/
public fun getClasslike(dri: DRI, sourceSet: DokkaSourceSet): DClasslike?
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public class InternalKotlinAnalysisPlugin : DokkaPlugin() {

public val inheritanceBuilder: ExtensionPoint<InheritanceBuilder> by extensionPoint()

public val externalDocumentablesProvider: ExtensionPoint<ExternalDocumentablesProvider> by extensionPoint()

public val documentableSourceLanguageParser: ExtensionPoint<DocumentableSourceLanguageParser> by extensionPoint()

@OptIn(DokkaPluginApiPreview::class)
Expand Down
Loading

0 comments on commit e63dad0

Please sign in to comment.