Skip to content

Commit

Permalink
Polish code
Browse files Browse the repository at this point in the history
  • Loading branch information
vmishenev committed Aug 24, 2023
1 parent 8da7ce2 commit c169487
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 98 deletions.
Original file line number Diff line number Diff line change
@@ -1,31 +1,11 @@
public abstract interface class org/jetbrains/dokka/analysis/kotlin/symbols/plugin/AnalysisContext : java/io/Closeable {
public abstract fun getMainModule ()Lorg/jetbrains/kotlin/analysis/project/structure/KtSourceModule;
public abstract fun getProject ()Lcom/intellij/openapi/project/Project;
}

public abstract class org/jetbrains/dokka/analysis/kotlin/symbols/plugin/KotlinAnalysis : java/io/Closeable {
public fun <init> ()V
public fun <init> (Lorg/jetbrains/dokka/analysis/kotlin/symbols/plugin/KotlinAnalysis;)V
public synthetic fun <init> (Lorg/jetbrains/dokka/analysis/kotlin/symbols/plugin/KotlinAnalysis;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun get (Lorg/jetbrains/dokka/DokkaConfiguration$DokkaSourceSet;)Lorg/jetbrains/dokka/analysis/kotlin/symbols/plugin/AnalysisContext;
}

public final class org/jetbrains/dokka/analysis/kotlin/symbols/plugin/SymbolsAnalysisPlugin : org/jetbrains/dokka/plugability/DokkaPlugin {
public fun <init> ()V
public final fun getKotlinAnalysis ()Lorg/jetbrains/dokka/plugability/ExtensionPoint;
public final fun getSymbolToDocumentableTranslator ()Lorg/jetbrains/dokka/plugability/Extension;
}

public final class org/jetbrains/dokka/analysis/kotlin/symbols/services/KotlinAnalysisSourceRootsExtractor : org/jetbrains/dokka/analysis/java/SourceRootsExtractor {
public fun <init> ()V
public fun extract (Lorg/jetbrains/dokka/DokkaConfiguration$DokkaSourceSet;Lorg/jetbrains/dokka/plugability/DokkaContext;)Ljava/util/List;
}

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 final fun getKotlinAnalysis ()Lorg/jetbrains/dokka/analysis/kotlin/symbols/plugin/KotlinAnalysis;
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;
Expand All @@ -37,14 +17,3 @@ public final class org/jetbrains/dokka/analysis/kotlin/symbols/services/KotlinSa
public final fun getContext ()Lorg/jetbrains/dokka/plugability/DokkaContext;
}

public final class org/jetbrains/dokka/analysis/kotlin/symbols/services/SymbolFullClassHierarchyBuilder : org/jetbrains/dokka/analysis/kotlin/internal/FullClassHierarchyBuilder {
public fun <init> ()V
public fun build (Lorg/jetbrains/dokka/model/DModule;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

public final class org/jetbrains/dokka/analysis/kotlin/symbols/translators/DefaultSymbolToDocumentableTranslator : org/jetbrains/dokka/transformers/sources/AsyncSourceToDocumentableTranslator {
public fun <init> (Lorg/jetbrains/dokka/plugability/DokkaContext;)V
public fun invoke (Lorg/jetbrains/dokka/DokkaConfiguration$DokkaSourceSet;Lorg/jetbrains/dokka/plugability/DokkaContext;)Lorg/jetbrains/dokka/model/DModule;
public fun invokeSuspending (Lorg/jetbrains/dokka/DokkaConfiguration$DokkaSourceSet;Lorg/jetbrains/dokka/plugability/DokkaContext;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal fun KtAnalysisSession.getJavaDocDocumentationFrom(
return null
}

internal fun KtAnalysisSession.getKDocDocumentationFrom(symbol: KtSymbol, logger: DokkaLogger) = findKDoc(symbol)?.let {
internal fun KtAnalysisSession.getKDocDocumentationFrom(symbol: KtSymbol, logger: DokkaLogger) = findKDoc(symbol)?.let { kDocContent ->

val ktElement = symbol.psi
val kdocLocation = ktElement?.containingFile?.name?.let {
Expand All @@ -51,15 +51,15 @@ internal fun KtAnalysisSession.getKDocDocumentationFrom(symbol: KtSymbol, logger
is KtClassOrObjectSymbol -> symbol.classIdIfNonLocal?.toString()
is KtNamedSymbol -> symbol.name.asString()
else -> null
}?.replace('/', '.')
}?.replace('/', '.') // replace to be compatible with K1

if (name != null) "$it/$name"
else it
}


parseFromKDocTag(
kDocTag = it.contentTag,
kDocTag = kDocContent.contentTag,
externalDri = { link -> resolveKDocLink(link).logIfNotResolved(link.getLinkText(), logger) },
kdocLocation = kdocLocation
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,69 +29,63 @@ internal fun parseFromKDocTag(
val allTags =
listOf(kDocTag) + if (kDocTag.canHaveParent() && parseWithChildren) getAllKDocTags(findParent(kDocTag)) else emptyList()
DocumentationNode(
allTags.map {
val links = it.allChildren.filterIsInstance<KDocLink>().associate { it.getLinkText() to externalDri(it) }
allTags.map { tag ->
val links = tag.allChildren.filterIsInstance<KDocLink>().associate { it.getLinkText() to externalDri(it) }
val externalDRIProvider = { linkText: String -> links[linkText] }

when (it.knownTag) {
null -> if (it.name == null) Description(parseStringToDocNode(it.getContent(), externalDRIProvider)) else CustomTagWrapper(
parseStringToDocNode(it.getContent(), externalDRIProvider),
it.name!!
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(it.getContent(), externalDRIProvider))
KDocKnownTag.AUTHOR -> Author(parseStringToDocNode(tag.getContent(), externalDRIProvider))
KDocKnownTag.THROWS -> {
val dri = pointedLink(it)
val dri = pointedLink(tag)
Throws(
parseStringToDocNode(it.getContent(), externalDRIProvider),
dri?.fqDeclarationName() ?: it.getSubjectName().orEmpty(),
parseStringToDocNode(tag.getContent(), externalDRIProvider),
dri?.fqDeclarationName() ?: tag.getSubjectName().orEmpty(),
dri,
)
}
KDocKnownTag.EXCEPTION -> {
val dri = pointedLink(it)
val dri = pointedLink(tag)
Throws(
parseStringToDocNode(it.getContent(), externalDRIProvider),
dri?.fqDeclarationName() ?: it.getSubjectName().orEmpty(),
parseStringToDocNode(tag.getContent(), externalDRIProvider),
dri?.fqDeclarationName() ?: tag.getSubjectName().orEmpty(),
dri
)
}
KDocKnownTag.PARAM -> Param(
parseStringToDocNode(it.getContent(), externalDRIProvider),
it.getSubjectName().orEmpty()
parseStringToDocNode(tag.getContent(), externalDRIProvider),
tag.getSubjectName().orEmpty()
)
KDocKnownTag.RECEIVER -> Receiver(parseStringToDocNode(it.getContent(), externalDRIProvider))
KDocKnownTag.RETURN -> Return(parseStringToDocNode(it.getContent(), externalDRIProvider))
KDocKnownTag.RECEIVER -> Receiver(parseStringToDocNode(tag.getContent(), externalDRIProvider))
KDocKnownTag.RETURN -> Return(parseStringToDocNode(tag.getContent(), externalDRIProvider))
KDocKnownTag.SEE -> {
val dri = pointedLink(it)
val dri = pointedLink(tag)
See(
parseStringToDocNode(it.getContent(), externalDRIProvider),
dri?.fqDeclarationName() ?: it.getSubjectName().orEmpty(),
parseStringToDocNode(tag.getContent(), externalDRIProvider),
dri?.fqDeclarationName() ?: tag.getSubjectName().orEmpty(),
dri,
)
}
KDocKnownTag.SINCE -> Since(parseStringToDocNode(it.getContent(), externalDRIProvider))
KDocKnownTag.CONSTRUCTOR -> Constructor(parseStringToDocNode(it.getContent(), externalDRIProvider))
KDocKnownTag.SINCE -> Since(parseStringToDocNode(tag.getContent(), externalDRIProvider))
KDocKnownTag.CONSTRUCTOR -> Constructor(parseStringToDocNode(tag.getContent(), externalDRIProvider))
KDocKnownTag.PROPERTY -> Property(
parseStringToDocNode(it.getContent(), externalDRIProvider),
it.getSubjectName().orEmpty()
parseStringToDocNode(tag.getContent(), externalDRIProvider),
tag.getSubjectName().orEmpty()
)
KDocKnownTag.SAMPLE -> Sample(
parseStringToDocNode(it.getContent(), externalDRIProvider),
it.getSubjectName().orEmpty()
parseStringToDocNode(tag.getContent(), externalDRIProvider),
tag.getSubjectName().orEmpty()
)
KDocKnownTag.SUPPRESS -> Suppress(parseStringToDocNode(it.getContent(), externalDRIProvider))
KDocKnownTag.SUPPRESS -> Suppress(parseStringToDocNode(tag.getContent(), externalDRIProvider))
}
}
)
}
}

//Horrible hack but since link resolution is passed as a function i am not able to resolve them otherwise
@kotlin.Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("This function makes wrong assumptions and is missing a lot of corner cases related to generics, " +
"parameters and static members. This is not supposed to be public API and will not be supported in the future")
internal fun DRI.fqName(): String? = "$packageName.$classNames".takeIf { packageName != null && classNames != null }

private fun findParent(kDoc: PsiElement): PsiElement =
if (kDoc.canHaveParent()) findParent(kDoc.parent) else kDoc

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Disposer
import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.DokkaSourceSetID
import org.jetbrains.dokka.InternalDokkaApi
import org.jetbrains.dokka.model.SourceSetDependent
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.kotlin.analysis.api.standalone.StandaloneAnalysisAPISession
Expand Down Expand Up @@ -89,8 +88,7 @@ internal fun createAnalysisContext(
/**
* First child delegation. It does not close [parent].
*/
@InternalDokkaApi
abstract class KotlinAnalysis(
internal abstract class KotlinAnalysis(
private val parent: KotlinAnalysis? = null
) : Closeable {

Expand Down Expand Up @@ -120,8 +118,7 @@ internal open class EnvironmentKotlinAnalysis(
}
}

@InternalDokkaApi
interface AnalysisContext: Closeable {
internal interface AnalysisContext: Closeable {
val project: Project
val mainModule: KtSourceModule
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import org.jetbrains.dokka.renderers.PostAction
import org.jetbrains.kotlin.asJava.elements.KtLightAbstractAnnotation

@Suppress("unused")
class SymbolsAnalysisPlugin : DokkaPlugin() {
public class SymbolsAnalysisPlugin : DokkaPlugin() {

val kotlinAnalysis by extensionPoint<KotlinAnalysis>()
internal val kotlinAnalysis by extensionPoint<KotlinAnalysis>()

internal val defaultKotlinAnalysis by extending {
kotlinAnalysis providing { ctx ->
Expand All @@ -40,7 +40,7 @@ class SymbolsAnalysisPlugin : DokkaPlugin() {
CoreExtensions.postActions with PostAction { querySingle { kotlinAnalysis }.close() }
}

val symbolToDocumentableTranslator by extending {
internal val symbolToDocumentableTranslator by extending {
CoreExtensions.sourceToDocumentableTranslator providing ::DefaultSymbolToDocumentableTranslator
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.jetbrains.dokka.analysis.java.SourceRootsExtractor
import org.jetbrains.dokka.plugability.DokkaContext
import java.io.File

class KotlinAnalysisSourceRootsExtractor : SourceRootsExtractor {
internal class KotlinAnalysisSourceRootsExtractor : SourceRootsExtractor {
override fun extract(sourceSet: DokkaConfiguration.DokkaSourceSet, context: DokkaContext): List<File> {
return sourceSet.sourceRoots.filter { directory -> directory.isDirectory || directory.extension == "java" }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class KotlinSampleProviderFactory(val context: DokkaContext): SampleProviderFact
*/
@InternalDokkaApi
open class KotlinSampleProvider(val context: DokkaContext): SampleProvider {
val kotlinAnalysis = SamplesKotlinAnalysis(
private val kotlinAnalysis = SamplesKotlinAnalysis(
sourceSets = context.configuration.sourceSets,
context = context,
projectKotlinAnalysis = context.plugin<SymbolsAnalysisPlugin>().querySingle { kotlinAnalysis }
Expand All @@ -38,7 +38,7 @@ open class KotlinSampleProvider(val context: DokkaContext): SampleProvider {
protected open fun processBody(psiElement: PsiElement): String {
val text = processSampleBody(psiElement).trim { it == '\n' || it == '\r' }.trimEnd()
val lines = text.split("\n")
val indent = lines.filter(String::isNotBlank).map { it.takeWhile(Char::isWhitespace).count() }.minOrNull() ?: 0
val indent = lines.filter(String::isNotBlank).minOfOrNull { it.takeWhile(Char::isWhitespace).count() } ?: 0
return lines.joinToString("\n") { it.drop(indent) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import org.jetbrains.kotlin.psi.KtClassOrObject
import java.util.concurrent.ConcurrentHashMap


class SymbolFullClassHierarchyBuilder : FullClassHierarchyBuilder {
internal class SymbolFullClassHierarchyBuilder : FullClassHierarchyBuilder {
override suspend fun build(module: DModule): ClassHierarchy {
val map = module.sourceSets.associateWith { ConcurrentHashMap<DRI, List<DRI>>() }
module.packages.forEach { visitDocumentable(it, map) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,12 @@ internal class AnnotationTranslator {
annotationValue.classId.createDRI()
)

is KtKClassAnnotationValue.KtLocalKClassAnnotationValue -> TODO()
is KtKClassAnnotationValue.KtErrorClassAnnotationValue -> TODO()
is KtKClassAnnotationValue.KtLocalKClassAnnotationValue -> throw IllegalStateException("Unexpected a local class in annotation")
is KtKClassAnnotationValue.KtErrorClassAnnotationValue -> ClassValue(
annotationValue.unresolvedQualifierName ?: "",
DRI(packageName = "", classNames = ERROR_CLASS_NAME)
)

KtUnsupportedAnnotationValue -> TODO()
}

Expand All @@ -112,10 +116,6 @@ internal class AnnotationTranslator {
return DRI(
packageName = callableId.packageName.asString(),
classNames = callableId.className?.asString() + "." + callableId.callableName.asString(),
/*callable = Callable(
callableId.callableName.asString(),
params = emptyList(),
)*/
).withEnumEntryExtra()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import org.jetbrains.kotlin.psi.psiUtil.hasActualModifier
import org.jetbrains.kotlin.psi.psiUtil.hasExpectModifier
import java.nio.file.Paths

class DefaultSymbolToDocumentableTranslator(context: DokkaContext) : AsyncSourceToDocumentableTranslator {
internal class DefaultSymbolToDocumentableTranslator(context: DokkaContext) : AsyncSourceToDocumentableTranslator {
private val kotlinAnalysis = context.plugin<SymbolsAnalysisPlugin>().querySingle { kotlinAnalysis }
private val javadocParser = JavadocParser(
docCommentParsers = context.plugin<JavaAnalysisPlugin>().query { docCommentParsers },
Expand Down

This file was deleted.

0 comments on commit c169487

Please sign in to comment.