aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/translators/psi
diff options
context:
space:
mode:
authorAndrzej Ratajczak <andrzej.ratajczak98@gmail.com>2020-04-08 13:10:28 +0200
committerBarkingBad <32793002+BarkingBad@users.noreply.github.com>2020-04-22 10:37:59 +0200
commita5557f43c004d34026807d2d25b39fe1144bae94 (patch)
treecc65cf97e9d6b2ead623cab6a0f6da196ddf6f9c /plugins/base/src/main/kotlin/translators/psi
parentacc2670f6d641880325bb9826a202486a9410c24 (diff)
downloaddokka-a5557f43c004d34026807d2d25b39fe1144bae94.tar.gz
dokka-a5557f43c004d34026807d2d25b39fe1144bae94.tar.bz2
dokka-a5557f43c004d34026807d2d25b39fe1144bae94.zip
Refactors sources to documentables translation
Diffstat (limited to 'plugins/base/src/main/kotlin/translators/psi')
-rw-r--r--plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt40
1 files changed, 28 insertions, 12 deletions
diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
index 33100e3e..c0e1b4af 100644
--- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
+++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
@@ -2,6 +2,7 @@ package org.jetbrains.dokka.base.translators.psi
import com.intellij.lang.jvm.JvmModifier
import com.intellij.lang.jvm.types.JvmReferenceType
+import com.intellij.openapi.vfs.VirtualFileManager
import com.intellij.psi.*
import com.intellij.psi.impl.source.PsiClassReferenceType
import org.jetbrains.dokka.links.DRI
@@ -10,8 +11,10 @@ import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.model.properties.PropertyContainer
import org.jetbrains.dokka.pages.PlatformData
import org.jetbrains.dokka.plugability.DokkaContext
-import org.jetbrains.dokka.transformers.psi.PsiToDocumentableTranslator
+import org.jetbrains.dokka.transformers.sources.SourceToDocumentableTranslator
import org.jetbrains.dokka.utilities.DokkaLogger
+import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
+import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.load.java.propertyNameByGetMethodName
@@ -19,30 +22,43 @@ import org.jetbrains.kotlin.load.java.propertyNamesBySetMethodName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.psiUtil.getChildOfType
import org.jetbrains.kotlin.resolve.DescriptorUtils
+import org.jetbrains.kotlin.utils.addToStdlib.safeAs
-object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator {
+object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator {
+
+ override fun invoke(platformData: PlatformData, context: DokkaContext): DModule {
+
+ val (environment, _) = context.platforms.getValue(platformData)
+
+ val sourceRoots = environment.configuration.get(CLIConfigurationKeys.CONTENT_ROOTS)
+ ?.filterIsInstance<JavaSourceRoot>()
+ ?.map { it.file }
+ ?: listOf()
+ val localFileSystem = VirtualFileManager.getInstance().getFileSystem("file")
+
+ val psiFiles = sourceRoots.map { sourceRoot ->
+ sourceRoot.absoluteFile.walkTopDown().mapNotNull {
+ localFileSystem.findFileByPath(it.path)?.let { vFile ->
+ PsiManager.getInstance(environment.project).findFile(vFile) as? PsiJavaFile
+ }
+ }.toList()
+ }.flatten()
- override fun invoke(
- moduleName: String,
- psiFiles: List<PsiJavaFile>,
- platformData: PlatformData,
- context: DokkaContext
- ): DModule {
val docParser =
DokkaPsiParser(
platformData,
context.logger
)
return DModule(
- moduleName,
- psiFiles.groupBy { it.packageName }.map { (packageName, psiFiles) ->
+ platformData.name,
+ psiFiles.mapNotNull { it.safeAs<PsiJavaFile>() }.groupBy { it.packageName }.map { (packageName, psiFiles) ->
val dri = DRI(packageName = packageName)
DPackage(
dri,
emptyList(),
emptyList(),
- psiFiles.flatMap { psFile ->
- psFile.classes.map { docParser.parseClasslike(it, dri) }
+ psiFiles.flatMap { psiFile ->
+ psiFile.classes.map { docParser.parseClasslike(it, dri) }
},
emptyList(),
PlatformDependent.empty(),