diff options
author | Andrzej Ratajczak <andrzej.ratajczak98@gmail.com> | 2020-10-01 16:15:14 +0200 |
---|---|---|
committer | Kamil Doległo <9080183+kamildoleglo@users.noreply.github.com> | 2020-10-01 17:01:21 +0200 |
commit | 71b03f6d311c6ebfdf67c593e97a7483a64844f4 (patch) | |
tree | 6409cea41bdcde2a56159de86e9610e94e72375e /plugins/base/src/main | |
parent | fbee5a49ee4c21bf0f31362bf1f9af46adba7a44 (diff) | |
download | dokka-71b03f6d311c6ebfdf67c593e97a7483a64844f4.tar.gz dokka-71b03f6d311c6ebfdf67c593e97a7483a64844f4.tar.bz2 dokka-71b03f6d311c6ebfdf67c593e97a7483a64844f4.zip |
Add parsing of package-info in java sources
Diffstat (limited to 'plugins/base/src/main')
-rw-r--r-- | plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt | 39 | ||||
-rw-r--r-- | plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt | 3 |
2 files changed, 26 insertions, 16 deletions
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<PsiJavaFile>() }.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> T.toSourceSetDependent() = mapOf(sourceSetData to this) - fun parseClasslike(psi: PsiClass, parent: DRI): DClasslike = with(psi) { + fun parsePackage(packageName: String, psiFiles: List<PsiJavaFile>): 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<AncestryLevel>() val superMethodsKeys = hashSetOf<Int>() 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<PsiDocComment>() } /** |