aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorSzymon Świstun <sswistun@virtuslab.com>2020-03-02 11:07:47 +0100
committerKamil Doległo <kamilok1965@interia.pl>2020-03-04 13:19:17 +0100
commit9b7a59cdc93a6dcd9ab0623f6f476abf92d9427d (patch)
tree4c6c0f730c6480f824d6e92949c77940929241a1 /plugins
parentac590359174995a16a116a96dbb9df5dafa042f5 (diff)
downloaddokka-9b7a59cdc93a6dcd9ab0623f6f476abf92d9427d.tar.gz
dokka-9b7a59cdc93a6dcd9ab0623f6f476abf92d9427d.tar.bz2
dokka-9b7a59cdc93a6dcd9ab0623f6f476abf92d9427d.zip
Add information about modifiers to Documentables' extra properties
Diffstat (limited to 'plugins')
-rw-r--r--plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt93
-rw-r--r--plugins/base/src/test/kotlin/model/ClassesTest.kt4
2 files changed, 84 insertions, 13 deletions
diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
index 531537a4..cea408d7 100644
--- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
+++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
@@ -8,17 +8,23 @@ import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.model.Enum
import org.jetbrains.dokka.model.Function
import org.jetbrains.dokka.model.doc.DocumentationNode
+import org.jetbrains.dokka.model.properties.PropertyContainer
import org.jetbrains.dokka.pages.PlatformData
import org.jetbrains.dokka.parsers.MarkdownParser
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.transformers.descriptors.DescriptorToDocumentableTranslator
+import org.jetbrains.kotlin.codegen.isJvmStaticInObjectOrClassOrInterface
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.impl.DeclarationDescriptorVisitorEmptyBodies
import org.jetbrains.kotlin.idea.kdoc.findKDoc
import org.jetbrains.kotlin.idea.refactoring.fqName.fqName
+import org.jetbrains.kotlin.resolve.DescriptorUtils
+import org.jetbrains.kotlin.resolve.calls.components.isVararg
+import org.jetbrains.kotlin.resolve.calls.tasks.isDynamic
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.resolve.descriptorUtil.getAllSuperclassesWithoutAny
+import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassNotAny
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperInterfaces
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.MemberScope
@@ -102,7 +108,8 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private
documentation = info.docs,
generics = descriptor.typeConstructor.parameters.map { it.toTypeParameter() },
companion = descriptor.companion(driWithPlatform),
- platformData = listOf(platformData)
+ platformData = listOf(platformData),
+ extra = descriptor.additionalExtras()
)
}
@@ -121,7 +128,8 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private
visibility = PlatformDependent(mapOf(platformData to descriptor.visibility)),
supertypes = PlatformDependent.from(platformData, info.supertypes),
documentation = info.docs,
- platformData = listOf(platformData)
+ platformData = listOf(platformData),
+ extra = descriptor.additionalExtras()
)
}
@@ -143,7 +151,8 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private
supertypes = PlatformDependent.from(platformData, info.supertypes),
documentation = info.docs,
companion = descriptor.companion(driWithPlatform),
- platformData = listOf(platformData)
+ platformData = listOf(platformData),
+ extra = descriptor.additionalExtras()
)
}
@@ -158,7 +167,8 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private
classlikes = scope.classlikes(driWithPlatform),
functions = scope.functions(driWithPlatform),
properties = scope.properties(driWithPlatform),
- platformData = listOf(platformData)
+ platformData = listOf(platformData),
+ extra = descriptor.additionalExtras()
)
}
@@ -188,7 +198,8 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private
modifier = descriptor.modifier(),
companion = descriptor.companion(driWithPlatform),
supertypes = PlatformDependent.from(platformData, info.supertypes),
- platformData = listOf(platformData)
+ platformData = listOf(platformData),
+ extra = descriptor.additionalExtras()
)
}
@@ -213,7 +224,8 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private
documentation = descriptor.resolveDescriptorData(platformData),
modifier = descriptor.modifier(),
type = KotlinTypeWrapper(descriptor.returnType!!),
- platformData = listOf(platformData)
+ platformData = listOf(platformData),
+ extra = descriptor.additionalExtras()
)
}
@@ -237,7 +249,8 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private
documentation = descriptor.resolveDescriptorData(platformData),
modifier = descriptor.modifier(),
type = KotlinTypeWrapper(descriptor.returnType!!),
- platformData = listOf(platformData)
+ platformData = listOf(platformData),
+ extra = descriptor.additionalExtras()
)
}
@@ -260,7 +273,8 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private
type = KotlinTypeWrapper(descriptor.returnType),
modifier = descriptor.modifier(),
generics = descriptor.typeParameters.map { it.toTypeParameter() },
- platformData = listOf(platformData)
+ platformData = listOf(platformData),
+ extra = descriptor.additionalExtras()
)
}
@@ -289,7 +303,8 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private
this.name.asString(),
type = KotlinTypeWrapper(this.type),
documentation = descriptor.resolveDescriptorData(platformData),
- platformData = listOf(platformData)
+ platformData = listOf(platformData),
+ extra = descriptor.additionalExtras()
)
val name = run {
@@ -322,7 +337,8 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private
)
},
sources = descriptor.createSources(),
- platformData = listOf(platformData)
+ platformData = listOf(platformData),
+ extra = descriptor.additionalExtras()
)
}
@@ -332,7 +348,8 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private
name = descriptor.name.asString(),
type = KotlinTypeWrapper(descriptor.type),
documentation = descriptor.resolveDescriptorData(platformData),
- platformData = listOf(platformData)
+ platformData = listOf(platformData),
+ extra = descriptor.additionalExtras()
)
private fun MemberScope.functions(parent: DRIWithPlatformInfo): List<Function> =
@@ -378,7 +395,8 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private
fqNameSafe.asString(),
PlatformDependent.from(platformData, getDocumentation()),
upperBounds.map { it.toProjection() },
- listOf(platformData)
+ listOf(platformData),
+ extra = additionalExtras()
)
private fun KotlinType.toProjection(): Projection = when (constructor.declarationDescriptor) {
@@ -419,5 +437,56 @@ open class DokkaDescriptorVisitor( // TODO: close this class and make it private
PlatformDependent(mapOf(platformData to DescriptorDocumentableSource(this)))
}
+ inline fun <reified D : Documentable> FunctionDescriptor.additionalExtras(): PropertyContainer<D> = listOfNotNull(
+ ExtraModifiers.DYNAMIC.takeIf { isDynamic() },
+ ExtraModifiers.INFIX.takeIf { isInfix },
+ ExtraModifiers.INLINE.takeIf { isInline },
+ ExtraModifiers.SUSPEND.takeIf { isSuspend },
+ ExtraModifiers.OPERATOR.takeIf { isOperator },
+ ExtraModifiers.STATIC.takeIf { isJvmStaticInObjectOrClassOrInterface() },
+ ExtraModifiers.TAILREC.takeIf { isTailrec },
+ ExtraModifiers.EXTERNAL.takeIf { isExternal },
+ ExtraModifiers.OVERRIDE.takeIf { DescriptorUtils.isOverride(this) }
+ ).toContainer()
+
+ inline fun <reified D : Documentable> ClassDescriptor.additionalExtras(): PropertyContainer<D> = listOfNotNull(
+ ExtraModifiers.DYNAMIC.takeIf { isDynamic() },
+ ExtraModifiers.INLINE.takeIf { isInline },
+ ExtraModifiers.EXTERNAL.takeIf { isExternal },
+ ExtraModifiers.INNER.takeIf { isInner },
+ ExtraModifiers.DATA.takeIf { isData },
+ ExtraModifiers.OVERRIDE.takeIf { getSuperInterfaces().isNotEmpty() || getSuperClassNotAny() != null }
+ ).toContainer()
+
+ fun ValueParameterDescriptor.additionalExtras(): PropertyContainer<Parameter> =
+ listOfNotNull(
+ ExtraModifiers.DYNAMIC.takeIf { isDynamic() },
+ ExtraModifiers.NOINLINE.takeIf { isNoinline },
+ ExtraModifiers.CROSSINLINE.takeIf { isCrossinline },
+ ExtraModifiers.CONST.takeIf { isConst },
+ ExtraModifiers.LATEINIT.takeIf { isLateInit },
+ ExtraModifiers.VARARG.takeIf { isVararg }
+ ).toContainer()
+
+ fun TypeParameterDescriptor.additionalExtras(): PropertyContainer<TypeParameter> =
+ listOfNotNull(
+ ExtraModifiers.DYNAMIC.takeIf { isDynamic() },
+ ExtraModifiers.REIFIED.takeIf { isReified }
+ ).toContainer()
+
+ fun PropertyDescriptor.additionalExtras(): PropertyContainer<Property> = listOfNotNull(
+ ExtraModifiers.DYNAMIC.takeIf { isDynamic() },
+ ExtraModifiers.CONST.takeIf { isConst },
+ ExtraModifiers.LATEINIT.takeIf { isLateInit },
+ ExtraModifiers.STATIC.takeIf { isJvmStaticInObjectOrClassOrInterface() },
+ ExtraModifiers.EXTERNAL.takeIf { isExternal },
+ ExtraModifiers.OVERRIDE.takeIf { DescriptorUtils.isOverride(this) }
+ ).toContainer()
+
+ inline fun <reified D : Documentable> List<ExtraModifiers>.toContainer(
+ container: PropertyContainer<D> = PropertyContainer.empty()
+ ): PropertyContainer<D> =
+ container + AdditionalModifiers(this)
+
data class ClassInfo(val supertypes: List<DRI>, val docs: PlatformDependent<DocumentationNode>)
}
diff --git a/plugins/base/src/test/kotlin/model/ClassesTest.kt b/plugins/base/src/test/kotlin/model/ClassesTest.kt
index 2332df61..18288442 100644
--- a/plugins/base/src/test/kotlin/model/ClassesTest.kt
+++ b/plugins/base/src/test/kotlin/model/ClassesTest.kt
@@ -151,7 +151,9 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class
with((this / "classes" / "Klass").cast<Class>()) {
name equals "Klass"
visibility.values allEquals Visibilities.PUBLIC
- // TODO data modifier
+ with(extra[AdditionalModifiers.AdditionalKey].assertNotNull("Extras")) {
+ content.find{it == ExtraModifiers.DATA}.assertNotNull("data modifier")
+ }
}
}
}