From 71b03f6d311c6ebfdf67c593e97a7483a64844f4 Mon Sep 17 00:00:00 2001 From: Andrzej Ratajczak Date: Thu, 1 Oct 2020 16:15:14 +0200 Subject: Add parsing of package-info in java sources --- .../psi/DefaultPsiToDocumentableTranslator.kt | 39 ++++++++++++++-------- .../main/kotlin/translators/psi/JavadocParser.kt | 3 +- 2 files changed, 26 insertions(+), 16 deletions(-) (limited to 'plugins/base/src/main') diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt index d67bd9f5..39cb3c89 100644 --- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt @@ -7,6 +7,7 @@ import com.intellij.openapi.vfs.VirtualFileManager import com.intellij.psi.* import com.intellij.psi.impl.source.PsiClassReferenceType import com.intellij.psi.impl.source.PsiImmediateClassType +import com.intellij.psi.javadoc.PsiDocComment import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet import org.jetbrains.dokka.analysis.KotlinAnalysis import org.jetbrains.dokka.analysis.PsiDocumentableSource @@ -35,6 +36,7 @@ import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.psiUtil.getChildOfType import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments +import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance import org.jetbrains.kotlin.utils.addToStdlib.safeAs import java.io.File @@ -72,19 +74,7 @@ class DefaultPsiToDocumentableTranslator( return DModule( context.configuration.moduleName, psiFiles.mapNotNull { it.safeAs() }.groupBy { it.packageName }.map { (packageName, psiFiles) -> - val dri = DRI(packageName = packageName) - DPackage( - dri, - emptyList(), - emptyList(), - psiFiles.flatMap { psiFile -> - psiFile.classes.map { docParser.parseClasslike(it, dri) } - }, - emptyList(), - emptyMap(), - null, - setOf(sourceSet) - ) + docParser.parsePackage(packageName, psiFiles) }, emptyMap(), null, @@ -127,7 +117,28 @@ class DefaultPsiToDocumentableTranslator( private fun T.toSourceSetDependent() = mapOf(sourceSetData to this) - fun parseClasslike(psi: PsiClass, parent: DRI): DClasslike = with(psi) { + fun parsePackage(packageName: String, psiFiles: List): DPackage { + val dri = DRI(packageName = packageName) + val documentation = psiFiles.firstOrNull { it.name == "package-info.java" }?.let { + javadocParser.parseDocumentation(it).toSourceSetDependent() + } ?: emptyMap() + + return DPackage( + dri, + emptyList(), + emptyList(), + psiFiles.flatMap { psiFile -> + psiFile.classes.map { parseClasslike(it, dri) } + }, + emptyList(), + documentation, + null, + setOf(sourceSetData) + ) + } + + + private fun parseClasslike(psi: PsiClass, parent: DRI): DClasslike = with(psi) { val dri = parent.withClass(name.toString()) val ancestryTree = mutableListOf() val superMethodsKeys = hashSetOf() diff --git a/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt b/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt index 5baaf35a..b4663b20 100644 --- a/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt +++ b/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt @@ -88,8 +88,7 @@ class JavadocParser( return if (indexOfSuperClass >= 0) superMethodDocumentation[indexOfSuperClass] else superMethodDocumentation.first() } - - return null + return element.children.firstIsInstanceOrNull() } /** -- cgit