aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/translators/psi
diff options
context:
space:
mode:
authorBłażej Kardyś <bkardys@virtuslab.com>2020-05-05 17:45:12 +0200
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-05-14 13:30:33 +0200
commit3f2a790190da4f40ea6d8a976aa1929b2a1b002b (patch)
tree752ee84451954e9ea5e6d4133e18e41aaee2f7b1 /plugins/base/src/main/kotlin/translators/psi
parenta440f0cb8756019131a2c15389e747aea3c585e7 (diff)
downloaddokka-3f2a790190da4f40ea6d8a976aa1929b2a1b002b.tar.gz
dokka-3f2a790190da4f40ea6d8a976aa1929b2a1b002b.tar.bz2
dokka-3f2a790190da4f40ea6d8a976aa1929b2a1b002b.zip
Changing approach from platform-driven to source-set-driven
Diffstat (limited to 'plugins/base/src/main/kotlin/translators/psi')
-rw-r--r--plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt57
1 files changed, 36 insertions, 21 deletions
diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
index e5fa4bfc..ca8055c8 100644
--- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
+++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
@@ -9,7 +9,6 @@ import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.links.withClass
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.sources.SourceToDocumentableTranslator
import org.jetbrains.dokka.utilities.DokkaLogger
@@ -23,16 +22,21 @@ 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
+import java.io.File
object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator {
- override fun invoke(platformData: PlatformData, context: DokkaContext): DModule {
+ override fun invoke(sourceSetData: SourceSetData, context: DokkaContext): DModule {
- val (environment, _) = context.platforms.getValue(platformData)
+ fun isFileInSourceRoots(file: File) : Boolean {
+ return sourceSetData.sourceRoots.any { root -> file.path.startsWith(File(root.path).absolutePath) }
+ }
+
+ val (environment, _) = context.platforms.getValue(sourceSetData)
val sourceRoots = environment.configuration.get(CLIConfigurationKeys.CONTENT_ROOTS)
?.filterIsInstance<JavaSourceRoot>()
- ?.map { it.file }
+ ?.mapNotNull { it.file.takeIf(::isFileInSourceRoots) }
?: listOf()
val localFileSystem = VirtualFileManager.getInstance().getFileSystem("file")
@@ -46,11 +50,11 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator {
val docParser =
DokkaPsiParser(
- platformData,
+ sourceSetData,
context.logger
)
return DModule(
- platformData.name,
+ sourceSetData.moduleName,
psiFiles.mapNotNull { it.safeAs<PsiJavaFile>() }.groupBy { it.packageName }.map { (packageName, psiFiles) ->
val dri = DRI(packageName = packageName)
DPackage(
@@ -61,17 +65,19 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator {
psiFile.classes.map { docParser.parseClasslike(it, dri) }
},
emptyList(),
- PlatformDependent.empty(),
- listOf(platformData)
+ emptyMap(),
+ null,
+ listOf(sourceSetData)
)
},
- PlatformDependent.empty(),
- listOf(platformData)
+ emptyMap(),
+ null,
+ listOf(sourceSetData)
)
}
class DokkaPsiParser(
- private val platformData: PlatformData,
+ private val sourceSetData: SourceSetData,
private val logger: DokkaLogger
) {
@@ -104,7 +110,7 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator {
}
private fun <T> T.toPlatformDependant() =
- PlatformDependent(mapOf(platformData to this))
+ mapOf(sourceSetData to this)
fun parseClasslike(psi: PsiClass, parent: DRI): DClasslike = with(psi) {
val dri = parent.withClass(name.toString())
@@ -145,6 +151,7 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator {
name.orEmpty(),
dri,
documentation,
+ null,
source,
allFunctions,
fields.mapNotNull { parseField(it, accessors[it].orEmpty()) },
@@ -152,7 +159,7 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator {
visibility,
null,
constructors.map { parseFunction(it, true) },
- listOf(platformData),
+ listOf(sourceSetData),
PropertyContainer.empty<DAnnotation>() + annotations.toList().toExtra()
)
isEnum -> DEnum(
@@ -163,14 +170,16 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator {
dri.withClass("$name.${entry.name}"),
entry.name.orEmpty(),
javadocParser.parseDocumentation(entry).toPlatformDependant(),
+ null,
emptyList(),
emptyList(),
emptyList(),
- listOf(platformData),
+ listOf(sourceSetData),
PropertyContainer.empty<DEnumEntry>() + entry.annotations.toList().toExtra()
)
},
documentation,
+ null,
source,
allFunctions,
fields.filter { it !is PsiEnumConstant }.map { parseField(it, accessors[it].orEmpty()) },
@@ -179,13 +188,14 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator {
null,
constructors.map { parseFunction(it, true) },
ancestors,
- listOf(platformData),
+ listOf(sourceSetData),
PropertyContainer.empty<DEnum>() + annotations.toList().toExtra()
)
isInterface -> DInterface(
dri,
name.orEmpty(),
documentation,
+ null,
source,
allFunctions,
fields.mapNotNull { parseField(it, accessors[it].orEmpty()) },
@@ -194,7 +204,7 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator {
null,
mapTypeParameters(dri),
ancestors,
- listOf(platformData),
+ listOf(sourceSetData),
PropertyContainer.empty<DInterface>() + annotations.toList().toExtra()
)
else -> DClass(
@@ -210,8 +220,9 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator {
mapTypeParameters(dri),
ancestors,
documentation,
+ null,
modifiers,
- listOf(platformData),
+ listOf(sourceSetData),
PropertyContainer.empty<DClass>() + annotations.toList().toExtra()
)
}
@@ -232,18 +243,20 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator {
dri.copy(target = index + 1),
psiParameter.name,
javadocParser.parseDocumentation(psiParameter).toPlatformDependant(),
+ null,
getBound(psiParameter.type),
- listOf(platformData)
+ listOf(sourceSetData)
)
},
javadocParser.parseDocumentation(psi).toPlatformDependant(),
+ null,
PsiDocumentableSource(psi).toPlatformDependant(),
psi.getVisibility().toPlatformDependant(),
psi.returnType?.let { getBound(type = it) } ?: Void,
psi.mapTypeParameters(dri),
null,
psi.getModifier().toPlatformDependant(),
- listOf(platformData),
+ listOf(sourceSetData),
PropertyContainer.withAll(
InheritedFunction(isInherited),
psi.annotations.toList().toExtra(),
@@ -313,8 +326,9 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator {
dri.copy(genericTarget = index),
type.name.orEmpty(),
javadocParser.parseDocumentation(type).toPlatformDependant(),
+ null,
mapBounds(type.bounds),
- listOf(platformData)
+ listOf(sourceSetData)
)
}
}
@@ -349,6 +363,7 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator {
dri,
psi.name!!, // TODO: Investigate if this is indeed nullable
javadocParser.parseDocumentation(psi).toPlatformDependant(),
+ null,
PsiDocumentableSource(psi).toPlatformDependant(),
psi.getVisibility().toPlatformDependant(),
getBound(psi.type),
@@ -356,7 +371,7 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator {
accessors.firstOrNull { it.hasParameters() }?.let { parseFunction(it) },
accessors.firstOrNull { it.returnType == psi.type }?.let { parseFunction(it) },
psi.getModifier().toPlatformDependant(),
- listOf(platformData),
+ listOf(sourceSetData),
emptyList(),
PropertyContainer.empty<DProperty>() + psi.annotations.toList().toExtra()
)