aboutsummaryrefslogtreecommitdiff
path: root/plugins/base
diff options
context:
space:
mode:
authorBłażej Kardyś <bkardys@virtuslab.com>2020-03-06 13:20:19 +0100
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-03-10 12:03:34 +0100
commit35f56d1a1f38b6bc357e171dfa188962038a4a46 (patch)
tree08580ba10856310958770096a775889f597accfc /plugins/base
parent2abdfd45a8c3d39745b38629153d83871b8ceae6 (diff)
downloaddokka-35f56d1a1f38b6bc357e171dfa188962038a4a46.tar.gz
dokka-35f56d1a1f38b6bc357e171dfa188962038a4a46.tar.bz2
dokka-35f56d1a1f38b6bc357e171dfa188962038a4a46.zip
Psi parsing optimization
Diffstat (limited to 'plugins/base')
-rw-r--r--plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt20
1 files changed, 13 insertions, 7 deletions
diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
index 81de12eb..28391741 100644
--- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
+++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
@@ -38,13 +38,15 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator {
)
return Module(
moduleName,
- psiFiles.map { psiFile ->
- val dri = DRI(packageName = psiFile.packageName)
+ psiFiles.groupBy { it.packageName }.map { (packageName, psiFiles) ->
+ val dri = DRI(packageName = packageName)
Package(
dri,
emptyList(),
emptyList(),
- psiFile.classes.map { docParser.parseClasslike(it, dri) },
+ psiFiles.flatMap { psFile ->
+ psFile.classes.map { docParser.parseClasslike(it, dri) }
+ },
emptyList(),
PlatformDependent.empty(),
listOf(platformData)
@@ -62,6 +64,8 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator {
private val javadocParser: JavaDocumentationParser = JavadocParser(logger)
+ private val typeWrappers = hashMapOf<String, TypeWrapper>()
+
private fun PsiModifierListOwner.getVisibility() = modifierList?.children?.toList()?.let { ml ->
when {
ml.any { it.text == PsiKeyword.PUBLIC } -> JavaVisibility.Public
@@ -223,14 +227,14 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator {
dri.copy(target = index + 1),
psiParameter.name,
javadocParser.parseDocumentation(psiParameter).toPlatformDependant(),
- JavaTypeWrapper(psiParameter.type),
+ getTypeWrapper(psiParameter.type),
listOf(platformData)
)
},
javadocParser.parseDocumentation(psi).toPlatformDependant(),
PsiDocumentableSource(psi).toPlatformDependant(),
psi.getVisibility().toPlatformDependant(),
- psi.returnType?.let { JavaTypeWrapper(type = it) } ?: JavaTypeWrapper.VOID,
+ psi.returnType?.let { getTypeWrapper(type = it) } ?: JavaTypeWrapper.VOID,
psi.mapTypeParameters(dri),
null,
psi.getModifier(),
@@ -238,10 +242,12 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator {
PropertyContainer.empty<Function>() + InheritedFunction(
isInherited
)
-
)
}
+ private fun getTypeWrapper(type: PsiType) : TypeWrapper =
+ typeWrappers.getOrPut(type.canonicalText, { JavaTypeWrapper(type) })
+
private fun PsiModifierListOwner.getModifier() = when {
hasModifier(JvmModifier.ABSTRACT) -> JavaModifier.Abstract
hasModifier(JvmModifier.FINAL) -> JavaModifier.Final
@@ -306,7 +312,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator {
javadocParser.parseDocumentation(psi).toPlatformDependant(),
PsiDocumentableSource(psi).toPlatformDependant(),
psi.getVisibility().toPlatformDependant(),
- JavaTypeWrapper(psi.type),
+ getTypeWrapper(psi.type),
null,
accessors.firstOrNull { it.hasParameters() }?.let { parseFunction(it, parent) },
accessors.firstOrNull { it.returnType == psi.type }?.let { parseFunction(it, parent) },