aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt27
-rw-r--r--plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt162
-rw-r--r--plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt4
-rw-r--r--plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt154
-rw-r--r--plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt117
-rw-r--r--plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt2
-rw-r--r--plugins/base/src/test/kotlin/model/ClassesTest.kt38
-rw-r--r--plugins/base/src/test/kotlin/model/FunctionsTest.kt62
-rw-r--r--plugins/base/src/test/kotlin/model/JavaTest.kt10
-rw-r--r--plugins/base/src/test/kotlin/model/PropertyTest.kt12
-rw-r--r--plugins/base/src/test/kotlin/utils/contentUtils.kt154
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt29
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt8
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureUtils.kt4
14 files changed, 411 insertions, 372 deletions
diff --git a/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt b/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt
index 0cf085b8..7f0e985e 100644
--- a/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt
+++ b/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt
@@ -3,6 +3,7 @@ package org.jetbrains.dokka.base.signatures
import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder
import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.model.properties.WithExtraProperties
+import org.jetbrains.dokka.pages.*
interface JvmSignatureUtils {
@@ -10,7 +11,7 @@ interface JvmSignatureUtils {
fun PageContentBuilder.DocumentableContentBuilder.annotationsInline(d: Documentable)
- fun <T : Documentable> WithExtraProperties<T>.modifiers(): Set<ExtraModifiers>
+ fun <T : Documentable> WithExtraProperties<T>.modifiers(): SourceSetDependent<Set<ExtraModifiers>>
fun Set<ExtraModifiers>.toSignatureString(): String =
joinToString("") { it.name.toLowerCase() + " " }
@@ -40,9 +41,11 @@ interface JvmSignatureUtils {
else -> null
}?.let {
it.entries.forEach {
- group(sourceSets = setOf(it.key)) {
- it.value.filter { it !in ignored }.forEach {
- operation(it)
+ it.value.filter { it !in ignored }.takeIf { it.isNotEmpty() }?.let { annotations ->
+ group(sourceSets = setOf(it.key), styles = setOf(TextStyle.Block)) {
+ annotations.forEach {
+ operation(it)
+ }
}
}
}
@@ -62,14 +65,16 @@ interface JvmSignatureUtils {
link(a.dri.classNames!!, a.dri)
text("(")
a.params.entries.forEachIndexed { i, it ->
- text(it.key + " = ")
- when (renderAtStrategy) {
- is All -> All
- is Never, is OnlyOnce -> Never
- }.let { strategy ->
- valueToSignature(it.value, strategy, listBrackets, classExtension)
+ group(styles = setOf(TextStyle.Span)) {
+ text(it.key + " = ")
+ when (renderAtStrategy) {
+ is All -> All
+ is Never, is OnlyOnce -> Never
+ }.let { strategy ->
+ valueToSignature(it.value, strategy, listBrackets, classExtension)
+ }
+ if (i != a.params.entries.size - 1) text(", ")
}
- if (i != a.params.entries.size - 1) text(", ")
}
text(")")
}
diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
index 5514f9e5..542f6a1a 100644
--- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
+++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
@@ -67,34 +67,34 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
private fun regularSignature(c: DClasslike, sourceSets: Set<SourceSetData> = c.sourceSets.toSet()) =
contentBuilder.contentFor(c, ContentKind.Symbol, setOf(TextStyle.Monospace), sourceSets = sourceSets) {
- group(styles = setOf(TextStyle.Block)) {
- annotationsBlock(c)
- platformText(
- c.visibility,
- sourceSets
- ) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" }
- if (c is DClass) {
- platformText(c.modifier, sourceSets) {
- if (it !in ignoredModifiers)
- if (c.extra[AdditionalModifiers]?.content?.contains(ExtraModifiers.KotlinOnlyModifiers.Data) == true) ""
- else (if (it is JavaModifier.Empty) KotlinModifier.Open else it).let { it.name + " " }
- else
- ""
- }
- }
- when (c) {
- is DClass -> text("class ")
- is DInterface -> text("interface ")
- is DEnum -> text("enum ")
- is DObject -> text("object ")
- is DAnnotation -> text("annotation class ")
+ annotationsBlock(c)
+ platformText(
+ c.visibility,
+ sourceSets
+ ) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" }
+ if (c is DClass) {
+ platformText(c.modifier, sourceSets) {
+ if (it !in ignoredModifiers)
+ if (c.extra[AdditionalModifiers]?.content?.contains(ExtraModifiers.KotlinOnlyModifiers.Data) == true) ""
+ else (if (it is JavaModifier.Empty) KotlinModifier.Open else it).let { it.name + " " }
+ else
+ ""
}
- link(c.name!!, c.dri)
- if (c is WithGenerics) {
- list(c.generics, prefix = "<", suffix = "> ") {
- +buildSignature(it)
- }
+ }
+ when (c) {
+ is DClass -> text("class ")
+ is DInterface -> text("interface ")
+ is DEnum -> text("enum ")
+ is DObject -> text("object ")
+ is DAnnotation -> text("annotation class ")
+ }
+ link(c.name!!, c.dri)
+ if (c is WithGenerics) {
+ list(c.generics, prefix = "<", suffix = "> ") {
+ +buildSignature(it)
}
+ }
+ if (c is DClass) {
if (c is WithConstructors) {
val pConstructor = c.constructors.singleOrNull { it.extra[PrimaryConstructorExtra] != null }
if (pConstructor?.annotations()?.isNotEmpty() == true) {
@@ -115,11 +115,11 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
signatureForProjection(it.type)
}
}
- if (c is WithSupertypes) {
- c.supertypes.filter { it.key in sourceSets }.map { (s, dris) ->
- list(dris, prefix = " : ", sourceSets = setOf(s)) {
- link(it.sureClassNames, it, sourceSets = setOf(s))
- }
+ }
+ if (c is WithSupertypes) {
+ c.supertypes.filter { it.key in sourceSets }.map { (s, dris) ->
+ list(dris, prefix = " : ", sourceSets = setOf(s)) {
+ link(it.sureClassNames, it, sourceSets = setOf(s))
}
}
}
@@ -128,62 +128,58 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
private fun propertySignature(p: DProperty, sourceSets: Set<SourceSetData> = p.sourceSets.toSet()) =
contentBuilder.contentFor(p, ContentKind.Symbol, setOf(TextStyle.Monospace), sourceSets = sourceSets) {
- group(styles = setOf(TextStyle.Block)) {
- annotationsBlock(p)
- platformText(p.visibility) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" }
- platformText(p.modifier) {
- it.takeIf { it !in ignoredModifiers }?.let {
- if (it is JavaModifier.Empty) KotlinModifier.Open else it
- }?.name?.let { "$it " } ?: ""
- }
- text(p.modifiers().toSignatureString())
- p.setter?.let { text("var ") } ?: text("val ")
- list(p.generics, prefix = "<", suffix = "> ") {
- +buildSignature(it)
- }
- p.receiver?.also {
- signatureForProjection(it.type)
- text(".")
- }
- link(p.name, p.dri)
- text(": ")
- signatureForProjection(p.type)
+ annotationsBlock(p)
+ platformText(p.visibility) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" }
+ platformText(p.modifier) {
+ it.takeIf { it !in ignoredModifiers }?.let {
+ if (it is JavaModifier.Empty) KotlinModifier.Open else it
+ }?.name?.let { "$it " } ?: ""
+ }
+ platformText(p.modifiers()) { it.toSignatureString() }
+ p.setter?.let { text("var ") } ?: text("val ")
+ list(p.generics, prefix = "<", suffix = "> ") {
+ +buildSignature(it)
+ }
+ p.receiver?.also {
+ signatureForProjection(it.type)
+ text(".")
}
+ link(p.name, p.dri)
+ text(": ")
+ signatureForProjection(p.type)
}
private fun functionSignature(f: DFunction, sourceSets: Set<SourceSetData> = f.sourceSets.toSet()) =
contentBuilder.contentFor(f, ContentKind.Symbol, setOf(TextStyle.Monospace), sourceSets = sourceSets) {
- group(styles = setOf(TextStyle.Block)) {
- annotationsBlock(f)
- platformText(f.visibility) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" }
- platformText(f.modifier) {
- it.takeIf { it !in ignoredModifiers }?.let {
- if (it is JavaModifier.Empty) KotlinModifier.Open else it
- }?.name?.let { "$it " } ?: ""
- }
- text(f.modifiers().toSignatureString())
- text("fun ")
- list(f.generics, prefix = "<", suffix = "> ") {
- +buildSignature(it)
- }
- f.receiver?.also {
- signatureForProjection(it.type)
- text(".")
- }
- link(f.name, f.dri)
- text("(")
- list(f.parameters) {
- annotationsInline(it)
- text(it.modifiers().toSignatureString())
- text(it.name!!)
- text(": ")
- signatureForProjection(it.type)
- }
- text(")")
- if (f.documentReturnType()) {
- text(": ")
- signatureForProjection(f.type)
- }
+ annotationsBlock(f)
+ platformText(f.visibility) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" }
+ platformText(f.modifier) {
+ it.takeIf { it !in ignoredModifiers }?.let {
+ if (it is JavaModifier.Empty) KotlinModifier.Open else it
+ }?.name?.let { "$it " } ?: ""
+ }
+ platformText(f.modifiers()) { it.toSignatureString() }
+ text("fun ")
+ list(f.generics, prefix = "<", suffix = "> ") {
+ +buildSignature(it)
+ }
+ f.receiver?.also {
+ signatureForProjection(it.type)
+ text(".")
+ }
+ link(f.name, f.dri)
+ text("(")
+ list(f.parameters) {
+ annotationsInline(it)
+ platformText(it.modifiers()) { it.toSignatureString() }
+ text(it.name!!)
+ text(": ")
+ signatureForProjection(it.type)
+ }
+ text(")")
+ if (f.documentReturnType()) {
+ text(": ")
+ signatureForProjection(f.type)
}
}
@@ -204,7 +200,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
sourceSets = platforms.toSet()
) {
platformText(t.visibility) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" }
- text(t.modifiers().toSignatureString())
+ platformText(t.modifiers()) { it.toSignatureString() }
text("typealias ")
signatureForProjection(t.type)
text(" = ")
diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt
index 48cfe304..1f323473 100644
--- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt
+++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt
@@ -19,5 +19,7 @@ object KotlinSignatureUtils : JvmSignatureUtils {
annotationsInlineWithIgnored(d, emptySet(), strategy, listBrackets, classExtension)
override fun <T : Documentable> WithExtraProperties<T>.modifiers() =
- extra[AdditionalModifiers]?.content?.filterIsInstance<ExtraModifiers.KotlinOnlyModifiers>()?.toSet() ?: emptySet()
+ extra[AdditionalModifiers]?.content?.entries?.map {
+ it.key to it.value.filterIsInstance<ExtraModifiers.KotlinOnlyModifiers>().toSet()
+ }?.toMap() ?: emptyMap()
} \ No newline at end of file
diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
index a8175405..bf92c849 100644
--- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
+++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
@@ -146,7 +146,10 @@ private class DokkaDescriptorVisitor(
generics = descriptor.declaredTypeParameters.map { it.toTypeParameter() },
companion = descriptor.companion(driWithPlatform),
sourceSets = listOf(sourceSet),
- extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations())
+ extra = PropertyContainer.withAll(
+ descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(),
+ descriptor.getAnnotations().toSourceSetDependent().toAnnotations()
+ )
)
}
@@ -169,7 +172,10 @@ private class DokkaDescriptorVisitor(
supertypes = info.supertypes.toSourceSetDependent(),
documentation = info.docs,
sourceSets = listOf(sourceSet),
- extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations())
+ extra = PropertyContainer.withAll(
+ descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(),
+ descriptor.getAnnotations().toSourceSetDependent().toAnnotations()
+ )
)
}
@@ -194,7 +200,10 @@ private class DokkaDescriptorVisitor(
documentation = info.docs,
companion = descriptor.companion(driWithPlatform),
sourceSets = listOf(sourceSet),
- extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations())
+ extra = PropertyContainer.withAll(
+ descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(),
+ descriptor.getAnnotations().toSourceSetDependent().toAnnotations()
+ )
)
}
@@ -213,8 +222,8 @@ private class DokkaDescriptorVisitor(
sourceSets = listOf(sourceSet),
expectPresentInSet = sourceSet.takeIf { isExpect },
extra = PropertyContainer.withAll(
- descriptor.additionalExtras(),
- descriptor.getAnnotations(),
+ descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(),
+ descriptor.getAnnotations().toSourceSetDependent().toAnnotations(),
ConstructorValues(descriptor.getAppliedConstructorParameters().toSourceSetDependent())
)
)
@@ -233,7 +242,10 @@ private class DokkaDescriptorVisitor(
properties = scope.properties(driWithPlatform),
expectPresentInSet = null,
sourceSets = listOf(sourceSet),
- extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations()),
+ extra = PropertyContainer.withAll(
+ descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(),
+ descriptor.getAnnotations().toSourceSetDependent().toAnnotations()
+ ),
companion = descriptor.companionObjectDescriptor?.let { objectDescriptor(it, driWithPlatform) },
visibility = descriptor.visibility.toDokkaVisibility().toSourceSetDependent(),
generics = descriptor.declaredTypeParameters.map { it.toTypeParameter() },
@@ -271,7 +283,10 @@ private class DokkaDescriptorVisitor(
modifier = descriptor.modifier().toSourceSetDependent(),
companion = descriptor.companion(driWithPlatform),
sourceSets = listOf(sourceSet),
- extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations())
+ extra = PropertyContainer.withAll(
+ descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(),
+ descriptor.getAnnotations().toSourceSetDependent().toAnnotations()
+ )
)
}
@@ -301,9 +316,9 @@ private class DokkaDescriptorVisitor(
sourceSets = listOf(sourceSet),
generics = descriptor.typeParameters.map { it.toTypeParameter() },
extra = PropertyContainer.withAll(
- (descriptor.additionalExtras() + (descriptor.backingField?.getAnnotationsAsExtraModifiers()?.entries?.single()?.value
- ?: emptyList())).toProperty(),
- descriptor.getAllAnnotations()
+ (descriptor.additionalExtras() + descriptor.getAnnotationsWithBackingField()
+ .toAdditionalExtras()).toSet().toSourceSetDependent().toAdditionalModifiers(),
+ descriptor.getAnnotationsWithBackingField().toSourceSetDependent().toAnnotations()
)
)
}
@@ -339,7 +354,8 @@ private class DokkaDescriptorVisitor(
sourceSets = listOf(sourceSet),
extra = PropertyContainer.withAll(
InheritedFunction(isInherited),
- descriptor.additionalExtras(), descriptor.getAnnotations()
+ descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(),
+ descriptor.getAnnotations().toSourceSetDependent().toAnnotations()
)
)
}
@@ -379,12 +395,14 @@ private class DokkaDescriptorVisitor(
modifier = descriptor.modifier().toSourceSetDependent(),
generics = descriptor.typeParameters.map { it.toTypeParameter() },
sourceSets = listOf(sourceSet),
- extra = PropertyContainer.withAll<DFunction>(descriptor.additionalExtras(), descriptor.getAnnotations())
- .let {
- if (descriptor.isPrimary) {
- it + PrimaryConstructorExtra
- } else it
- }
+ extra = PropertyContainer.withAll<DFunction>(
+ descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(),
+ descriptor.getAnnotations().toSourceSetDependent().toAnnotations()
+ ).let {
+ if (descriptor.isPrimary) {
+ it + PrimaryConstructorExtra
+ } else it
+ }
)
}
@@ -398,7 +416,7 @@ private class DokkaDescriptorVisitor(
expectPresentInSet = null,
documentation = descriptor.resolveDescriptorData(),
sourceSets = listOf(sourceSet),
- extra = PropertyContainer.withAll(descriptor.getAnnotations())
+ extra = PropertyContainer.withAll(descriptor.getAnnotations().toSourceSetDependent().toAnnotations())
)
private fun visitPropertyAccessorDescriptor(
@@ -418,7 +436,10 @@ private class DokkaDescriptorVisitor(
expectPresentInSet = sourceSet.takeIf { isExpect },
documentation = descriptor.resolveDescriptorData(),
sourceSets = listOf(sourceSet),
- extra = PropertyContainer.withAll(descriptor.additionalExtras(), getAllAnnotations())
+ extra = PropertyContainer.withAll(
+ descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(),
+ getAnnotationsWithBackingField().toSourceSetDependent().toAnnotations()
+ )
)
val name = run {
@@ -453,7 +474,10 @@ private class DokkaDescriptorVisitor(
},
sources = descriptor.createSources(),
sourceSets = listOf(sourceSet),
- extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations())
+ extra = PropertyContainer.withAll(
+ descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(),
+ descriptor.getAnnotations().toSourceSetDependent().toAnnotations()
+ )
)
}
@@ -479,12 +503,11 @@ private class DokkaDescriptorVisitor(
expectPresentInSet = null,
documentation = descriptor.resolveDescriptorData(),
sourceSets = listOf(sourceSet),
- extra = PropertyContainer.withAll(
- listOfNotNull(
- descriptor.additionalExtras(),
- descriptor.getAnnotations(),
- descriptor.getDefaultValue()?.let { DefaultValue(it) })
- )
+ extra = PropertyContainer.withAll(listOfNotNull(
+ descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(),
+ descriptor.getAnnotations().toSourceSetDependent().toAnnotations(),
+ descriptor.getDefaultValue()?.let { DefaultValue(it) }
+ ))
)
private fun MemberScope.getContributedDescriptors(kindFilter: DescriptorKindFilter, shouldFilter: Boolean) =
@@ -542,7 +565,7 @@ private class DokkaDescriptorVisitor(
null,
upperBounds.map { it.toBound() },
listOf(sourceSet),
- extra = PropertyContainer.withAll(additionalExtras())
+ extra = PropertyContainer.withAll(additionalExtras().toSourceSetDependent().toAdditionalModifiers())
)
private fun KotlinType.toBound(): Bound = when (this) {
@@ -606,28 +629,26 @@ private class DokkaDescriptorVisitor(
ExtraModifiers.KotlinOnlyModifiers.TailRec.takeIf { isTailrec },
ExtraModifiers.KotlinOnlyModifiers.External.takeIf { isExternal },
ExtraModifiers.KotlinOnlyModifiers.Override.takeIf { DescriptorUtils.isOverride(this) }
- ).toProperty()
+ ).toSet()
private fun ClassDescriptor.additionalExtras() = listOfNotNull(
ExtraModifiers.KotlinOnlyModifiers.Inline.takeIf { isInline },
ExtraModifiers.KotlinOnlyModifiers.External.takeIf { isExternal },
ExtraModifiers.KotlinOnlyModifiers.Inner.takeIf { isInner },
ExtraModifiers.KotlinOnlyModifiers.Data.takeIf { isData }
- ).toProperty()
-
- private fun ValueParameterDescriptor.additionalExtras() =
- listOfNotNull(
- ExtraModifiers.KotlinOnlyModifiers.NoInline.takeIf { isNoinline },
- ExtraModifiers.KotlinOnlyModifiers.CrossInline.takeIf { isCrossinline },
- ExtraModifiers.KotlinOnlyModifiers.Const.takeIf { isConst },
- ExtraModifiers.KotlinOnlyModifiers.LateInit.takeIf { isLateInit },
- ExtraModifiers.KotlinOnlyModifiers.VarArg.takeIf { isVararg }
- ).toProperty()
-
- private fun TypeParameterDescriptor.additionalExtras() =
- listOfNotNull(
- ExtraModifiers.KotlinOnlyModifiers.Reified.takeIf { isReified }
- ).toProperty()
+ ).toSet()
+
+ private fun ValueParameterDescriptor.additionalExtras() = listOfNotNull(
+ ExtraModifiers.KotlinOnlyModifiers.NoInline.takeIf { isNoinline },
+ ExtraModifiers.KotlinOnlyModifiers.CrossInline.takeIf { isCrossinline },
+ ExtraModifiers.KotlinOnlyModifiers.Const.takeIf { isConst },
+ ExtraModifiers.KotlinOnlyModifiers.LateInit.takeIf { isLateInit },
+ ExtraModifiers.KotlinOnlyModifiers.VarArg.takeIf { isVararg }
+ ).toSet()
+
+ private fun TypeParameterDescriptor.additionalExtras() = listOfNotNull(
+ ExtraModifiers.KotlinOnlyModifiers.Reified.takeIf { isReified }
+ ).toSet()
private fun PropertyDescriptor.additionalExtras() = listOfNotNull(
ExtraModifiers.KotlinOnlyModifiers.Const.takeIf { isConst },
@@ -637,13 +658,7 @@ private class DokkaDescriptorVisitor(
ExtraModifiers.KotlinOnlyModifiers.Override.takeIf { DescriptorUtils.isOverride(this) }
)
- private fun List<ExtraModifiers>.toProperty() =
- AdditionalModifiers(this.toSet())
-
- private fun Annotated.getAnnotations() = getListOfSourceSetDependentAnnotations().let(::Annotations)
-
- private fun Annotated.getListOfSourceSetDependentAnnotations() =
- mapOf(sourceSet to annotations.mapNotNull { it.toAnnotation() })
+ private fun Annotated.getAnnotations() = annotations.mapNotNull { it.toAnnotation() }
private fun ConstantValue<*>.toValue(): AnnotationParameterValue? = when (this) {
is ConstantsAnnotationValue -> value.toAnnotation()?.let { AnnotationValue(it) }
@@ -670,30 +685,31 @@ private class DokkaDescriptorVisitor(
}
private fun AnnotationDescriptor.toAnnotation(): Annotations.Annotation? =
- DRI.from(annotationClass as DeclarationDescriptor)
- .takeIf { it.classNames != "<ERROR CLASS>" }?.let {
- Annotations.Annotation(
- it,
- allValueArguments.map { it.key.asString() to it.value.toValue() }.filter {
- it.second != null
- }.toMap() as Map<String, AnnotationParameterValue>
- )
- }
+ if(annotationClass?.visibility == Visibilities.PUBLIC)
+ DRI.from(annotationClass as DeclarationDescriptor)
+ .takeIf { it.classNames != "<ERROR CLASS>" }?.let {
+ Annotations.Annotation(
+ it,
+ allValueArguments.map { it.key.asString() to it.value.toValue() }.filter {
+ it.second != null
+ }.toMap() as Map<String, AnnotationParameterValue>
+ )
+ }
+ else
+ null
- private fun PropertyDescriptor.getAllAnnotations(): Annotations =
- (getListOfSourceSetDependentAnnotations() + (backingField?.getListOfSourceSetDependentAnnotations()
- ?: emptyMap())).let(::Annotations)
+ private fun PropertyDescriptor.getAnnotationsWithBackingField(): List<Annotations.Annotation> =
+ getAnnotations() + (backingField?.getAnnotations() ?: emptyList())
- private fun FieldDescriptor.getAnnotationsAsExtraModifiers() = getAnnotations().content.mapValues {
- it.value.mapNotNull {
- try {
- ExtraModifiers.valueOf(it.dri.classNames?.toLowerCase() ?: "")
- } catch (e: IllegalArgumentException) {
- null
- }
+ private fun List<Annotations.Annotation>.toAdditionalExtras() = mapNotNull {
+ try {
+ ExtraModifiers.valueOf(it.dri.classNames?.toLowerCase() ?: "")
+ } catch (e: IllegalArgumentException) {
+ null
}
}
+
private fun ValueParameterDescriptor.getDefaultValue(): String? =
(source as? KotlinSourceElement)?.psi?.children?.find { it is KtExpression }?.text
diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
index 1f52b2d9..d68f0e01 100644
--- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
+++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
@@ -116,8 +116,7 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator {
return false
}
- private fun <T> T.toPlatformDependant() =
- mapOf(sourceSetData to this)
+ private fun <T> T.toSourceSetDependent() = mapOf(sourceSetData to this)
fun parseClasslike(psi: PsiClass, parent: DRI): DClasslike = with(psi) {
val dri = parent.withClass(name.toString())
@@ -144,14 +143,14 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator {
}
parseSupertypes(superTypes)
val (regularFunctions, accessors) = splitFunctionsAndAccessors()
- val documentation = javadocParser.parseDocumentation(this).toPlatformDependant()
+ val documentation = javadocParser.parseDocumentation(this).toSourceSetDependent()
val allFunctions = regularFunctions.mapNotNull { if (!it.isConstructor) parseFunction(it) else null } +
superMethods.map { parseFunction(it, isInherited = true) }
- val source = PsiDocumentableSource(this).toPlatformDependant()
+ val source = PsiDocumentableSource(this).toSourceSetDependent()
val classlikes = innerClasses.map { parseClasslike(it, dri) }
- val visibility = getVisibility().toPlatformDependant()
- val ancestors = ancestorsSet.toList().toPlatformDependant()
- val modifiers = getModifier().toPlatformDependant()
+ val visibility = getVisibility().toSourceSetDependent()
+ val ancestors = ancestorsSet.toList().toSourceSetDependent()
+ val modifiers = getModifier().toSourceSetDependent()
return when {
isAnnotationType ->
DAnnotation(
@@ -168,8 +167,8 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator {
constructors.map { parseFunction(it, true) },
mapTypeParameters(dri),
listOf(sourceSetData),
- PropertyContainer.empty<DAnnotation>() + annotations.toList().toListOfAnnotations()
- .let(::Annotations)
+ PropertyContainer.empty<DAnnotation>() + annotations.toList().getAnnotations()
+ .toSourceSetDependent().toAnnotations()
)
isEnum -> DEnum(
dri,
@@ -178,14 +177,14 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator {
DEnumEntry(
dri.withClass("$name.${entry.name}"),
entry.name.orEmpty(),
- javadocParser.parseDocumentation(entry).toPlatformDependant(),
+ javadocParser.parseDocumentation(entry).toSourceSetDependent(),
null,
emptyList(),
emptyList(),
emptyList(),
listOf(sourceSetData),
- PropertyContainer.empty<DEnumEntry>() + entry.annotations.toList().toListOfAnnotations()
- .let(::Annotations)
+ PropertyContainer.empty<DEnumEntry>() + entry.annotations.toList().getAnnotations()
+ .toSourceSetDependent().toAnnotations()
)
},
documentation,
@@ -199,7 +198,8 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator {
constructors.map { parseFunction(it, true) },
ancestors,
listOf(sourceSetData),
- PropertyContainer.empty<DEnum>() + annotations.toList().toListOfAnnotations().let(::Annotations)
+ PropertyContainer.empty<DEnum>() + annotations.toList().getAnnotations().toSourceSetDependent()
+ .toAnnotations()
)
isInterface -> DInterface(
dri,
@@ -215,8 +215,8 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator {
mapTypeParameters(dri),
ancestors,
listOf(sourceSetData),
- PropertyContainer.empty<DInterface>() + annotations.toList().toListOfAnnotations()
- .let(::Annotations)
+ PropertyContainer.empty<DInterface>() + annotations.toList().getAnnotations().toSourceSetDependent()
+ .toAnnotations()
)
else -> DClass(
dri,
@@ -234,7 +234,8 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator {
null,
modifiers,
listOf(sourceSetData),
- PropertyContainer.empty<DClass>() + annotations.toList().toListOfAnnotations().let(::Annotations)
+ PropertyContainer.empty<DClass>() + annotations.toList().getAnnotations().toSourceSetDependent()
+ .toAnnotations()
)
}
}
@@ -253,49 +254,49 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator {
DParameter(
dri.copy(target = dri.target.nextTarget()),
psiParameter.name,
- javadocParser.parseDocumentation(psiParameter).toPlatformDependant(),
+ javadocParser.parseDocumentation(psiParameter).toSourceSetDependent(),
null,
getBound(psiParameter.type),
listOf(sourceSetData)
)
},
- javadocParser.parseDocumentation(psi).toPlatformDependant(),
+ javadocParser.parseDocumentation(psi).toSourceSetDependent(),
null,
- PsiDocumentableSource(psi).toPlatformDependant(),
- psi.getVisibility().toPlatformDependant(),
+ PsiDocumentableSource(psi).toSourceSetDependent(),
+ psi.getVisibility().toSourceSetDependent(),
psi.returnType?.let { getBound(type = it) } ?: Void,
psi.mapTypeParameters(dri),
null,
- psi.getModifier().toPlatformDependant(),
+ psi.getModifier().toSourceSetDependent(),
listOf(sourceSetData),
psi.additionalExtras().let {
PropertyContainer.withAll(
InheritedFunction(isInherited),
- it,
- (psi.annotations.toList().toListOfAnnotations() + it.toListOfAnnotations()).let(::Annotations)
+ it.toSourceSetDependent().toAdditionalModifiers(),
+ (psi.annotations.toList().getAnnotations() + it.getAnnotations()).toSourceSetDependent()
+ .toAnnotations()
)
}
)
}
- private fun PsiModifierListOwner.additionalExtras() = AdditionalModifiers(
- listOfNotNull(
- ExtraModifiers.JavaOnlyModifiers.Static.takeIf { hasModifier(JvmModifier.STATIC) },
- ExtraModifiers.JavaOnlyModifiers.Native.takeIf { hasModifier(JvmModifier.NATIVE) },
- ExtraModifiers.JavaOnlyModifiers.Synchronized.takeIf { hasModifier(JvmModifier.SYNCHRONIZED) },
- ExtraModifiers.JavaOnlyModifiers.StrictFP.takeIf { hasModifier(JvmModifier.STRICTFP) },
- ExtraModifiers.JavaOnlyModifiers.Transient.takeIf { hasModifier(JvmModifier.TRANSIENT) },
- ExtraModifiers.JavaOnlyModifiers.Volatile.takeIf { hasModifier(JvmModifier.VOLATILE) },
- ExtraModifiers.JavaOnlyModifiers.Transitive.takeIf { hasModifier(JvmModifier.TRANSITIVE) }
- ).toSet()
- )
+ private fun PsiModifierListOwner.additionalExtras() = listOfNotNull(
+ ExtraModifiers.JavaOnlyModifiers.Static.takeIf { hasModifier(JvmModifier.STATIC) },
+ ExtraModifiers.JavaOnlyModifiers.Native.takeIf { hasModifier(JvmModifier.NATIVE) },
+ ExtraModifiers.JavaOnlyModifiers.Synchronized.takeIf { hasModifier(JvmModifier.SYNCHRONIZED) },
+ ExtraModifiers.JavaOnlyModifiers.StrictFP.takeIf { hasModifier(JvmModifier.STRICTFP) },
+ ExtraModifiers.JavaOnlyModifiers.Transient.takeIf { hasModifier(JvmModifier.TRANSIENT) },
+ ExtraModifiers.JavaOnlyModifiers.Volatile.takeIf { hasModifier(JvmModifier.VOLATILE) },
+ ExtraModifiers.JavaOnlyModifiers.Transitive.takeIf { hasModifier(JvmModifier.TRANSITIVE) }
+ ).toSet()
+
- private fun AdditionalModifiers.toListOfAnnotations() = mapOf(sourceSetData to this.content.map {
+ private fun Set<ExtraModifiers>.getAnnotations() = map {
if (it !is ExtraModifiers.JavaOnlyModifiers.Static)
Annotations.Annotation(DRI("kotlin.jvm", it.name.toLowerCase().capitalize()), emptyMap())
else
Annotations.Annotation(DRI("kotlin.jvm", "JvmStatic"), emptyMap())
- })
+ }
private fun getBound(type: PsiType): Bound =
cachedBounds.getOrPut(type.canonicalText) {
@@ -346,7 +347,7 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator {
DTypeParameter(
dri.copy(target = dri.target.nextTarget()),
type.name.orEmpty(),
- javadocParser.parseDocumentation(type).toPlatformDependant(),
+ javadocParser.parseDocumentation(type).toSourceSetDependent(),
null,
mapBounds(type.bounds),
listOf(sourceSetData)
@@ -383,41 +384,39 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator {
return DProperty(
dri,
psi.name!!, // TODO: Investigate if this is indeed nullable
- javadocParser.parseDocumentation(psi).toPlatformDependant(),
+ javadocParser.parseDocumentation(psi).toSourceSetDependent(),
null,
- PsiDocumentableSource(psi).toPlatformDependant(),
- psi.getVisibility().toPlatformDependant(),
+ PsiDocumentableSource(psi).toSourceSetDependent(),
+ psi.getVisibility().toSourceSetDependent(),
getBound(psi.type),
null,
accessors.firstOrNull { it.hasParameters() }?.let { parseFunction(it) },
accessors.firstOrNull { it.returnType == psi.type }?.let { parseFunction(it) },
- psi.getModifier().toPlatformDependant(),
+ psi.getModifier().toSourceSetDependent(),
listOf(sourceSetData),
emptyList(),
psi.additionalExtras().let {
PropertyContainer.withAll<DProperty>(
- it,
- (psi.annotations.toList().toListOfAnnotations() + it.toListOfAnnotations()).let(::Annotations)
+ it.toSourceSetDependent().toAdditionalModifiers(),
+ (psi.annotations.toList().getAnnotations() + it.getAnnotations()).toSourceSetDependent()
+ .toAnnotations()
)
}
)
}
- private fun Collection<PsiAnnotation>.toListOfAnnotations() =
- mapOf(sourceSetData to filter { it !is KtLightAbstractAnnotation }.mapNotNull { it.toAnnotation() })
+ private fun Collection<PsiAnnotation>.getAnnotations() =
+ filter { it !is KtLightAbstractAnnotation }.mapNotNull { it.toAnnotation() }
private fun JvmAnnotationAttribute.toValue(): AnnotationParameterValue = when (this) {
is PsiNameValuePair -> value?.toValue() ?: StringValue("")
else -> StringValue(this.attributeName)
}
- private fun PsiAnnotationMemberValue.toValue(): AnnotationParameterValue = when (this) {
- is PsiAnnotation -> AnnotationValue(toAnnotation())
- is PsiArrayInitializerMemberValue -> ArrayValue(initializers.map { it.toValue() })
- is PsiReferenceExpression -> EnumValue(
- text ?: "",
- driOfReference()
- )
+ private fun PsiAnnotationMemberValue.toValue(): AnnotationParameterValue? = when (this) {
+ is PsiAnnotation -> toAnnotation()?.let { AnnotationValue(it) }
+ is PsiArrayInitializerMemberValue -> ArrayValue(initializers.mapNotNull { it.toValue() })
+ is PsiReferenceExpression -> driOfReference()?.let { EnumValue(text ?: "", it) }
is PsiClassObjectAccessExpression -> ClassValue(
text ?: "",
DRI.from(((type as PsiImmediateClassType).parameters.single() as PsiClassReferenceType).resolve()!!)
@@ -425,16 +424,16 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator {
else -> StringValue(text ?: "")
}
- private fun PsiAnnotation.toAnnotation() = Annotations.Annotation(
- driOfReference(),
- attributes.filter { it !is KtLightAbstractAnnotation }.mapNotNull { it.attributeName to it.toValue() }
- .toMap()
- )
+ private fun PsiAnnotation.toAnnotation() = driOfReference()?.let {
+ Annotations.Annotation(
+ it,
+ attributes.filter { it !is KtLightAbstractAnnotation }.mapNotNull { it.attributeName to it.toValue() }
+ .toMap()
+ )
+ }
private fun PsiElement.driOfReference() = getChildOfType<PsiJavaCodeReferenceElement>()?.resolve()?.let {
DRI.from(it)
- } ?: DRI("", getChildOfType<PsiJavaCodeReferenceElement>()?.qualifiedName ?: "").also {
- logger.error("$this cannot be resolved to symbol!")
}
}
}
diff --git a/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt b/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt
index 98f572b4..d10bd151 100644
--- a/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt
+++ b/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt
@@ -149,6 +149,4 @@ class ContentForAnnotationsTest : AbstractCoreTest() {
}
}
}
-
-
} \ No newline at end of file
diff --git a/plugins/base/src/test/kotlin/model/ClassesTest.kt b/plugins/base/src/test/kotlin/model/ClassesTest.kt
index 4ca34b00..5616a6c3 100644
--- a/plugins/base/src/test/kotlin/model/ClassesTest.kt
+++ b/plugins/base/src/test/kotlin/model/ClassesTest.kt
@@ -1,5 +1,6 @@
package model
+import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.model.KotlinModifier.*
import org.junit.jupiter.api.Assertions.assertNull
@@ -150,9 +151,9 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class
with((this / "classes" / "Klass").cast<DClass>()) {
name equals "Klass"
visibility.values allEquals KotlinVisibility.Public
- with(extra[AdditionalModifiers].assertNotNull("Extras")) {
- content counts 1
- content.first() equals ExtraModifiers.KotlinOnlyModifiers.Data
+ with(extra[AdditionalModifiers]!!.content.entries.single().value.assertNotNull("Extras")) {
+ this counts 1
+ first() equals ExtraModifiers.KotlinOnlyModifiers.Data
}
}
}
@@ -180,9 +181,9 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class
"""
) {
with((this / "classes" / "Foo").cast<DClass>()) {
- with(extra[Annotations].assertNotNull("Annotations")) {
- this.content counts 1
- with(content.first()) {
+ with(extra[Annotations]!!.content.entries.single().value.assertNotNull("Annotations")) {
+ this counts 1
+ with(first()) {
dri.classNames equals "Deprecated"
params.entries counts 1
(params["message"].assertNotNull("message") as StringValue).value equals "\"should no longer be used\""
@@ -273,9 +274,9 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class
with((this / "classes" / "C").cast<DClass>()) {
with((this / "D").cast<DClass>()) {
- with(extra[AdditionalModifiers].assertNotNull("AdditionalModifiers")) {
- content counts 1
- content.first() equals ExtraModifiers.KotlinOnlyModifiers.Inner
+ with(extra[AdditionalModifiers]!!.content.entries.single().value.assertNotNull("AdditionalModifiers")) {
+ this counts 1
+ first() equals ExtraModifiers.KotlinOnlyModifiers.Inner
}
}
}
@@ -359,9 +360,9 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class
"""
) {
with((this / "classes" / "C").cast<DClass>()) {
- with(extra[Annotations].assertNotNull("Annotations")) {
- this.content counts 1
- with(content.first()) {
+ with(extra[Annotations]!!.content.entries.single().value.assertNotNull("Annotations")) {
+ this counts 1
+ with(first()) {
dri.classNames equals "SinceKotlin"
params.entries counts 1
(params["version"].assertNotNull("version") as StringValue).value equals "\"1.1\""
@@ -424,7 +425,7 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class
"""@Suppress("abc") class Foo() {}"""
) {
with((this / "classes" / "Foo").cast<DClass>()) {
- with(extra[Annotations]?.content?.firstOrNull().assertNotNull("annotations")) {
+ with(extra[Annotations]!!.content.entries.single().value.firstOrNull().assertNotNull("annotations")) {
dri.toString() equals "kotlin/Suppress///PointingToDeclaration/"
(params["names"].assertNotNull("param") as ArrayValue).value equals listOf(StringValue("\"abc\""))
}
@@ -444,11 +445,14 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class
"""
) {
with((this / "classes" / "throws").cast<DAnnotation>()) {
- with(extra[Annotations].assertNotNull("Annotations")) {
- content counts 1
- with(content.first()) {
+ with(extra[Annotations]!!.content.entries.single().value.assertNotNull("Annotations")) {
+ this counts 1
+ with(first()) {
dri.classNames equals "Retention"
-// params["value"].assertNotNull("value") equals "(java/lang/annotation/RetentionPolicy, SOURCE)"
+ params["value"].assertNotNull("value") equals EnumValue(
+ "RetentionPolicy.SOURCE",
+ DRI("java.lang.annotation", "RetentionPolicy.SOURCE")
+ )
}
}
}
diff --git a/plugins/base/src/test/kotlin/model/FunctionsTest.kt b/plugins/base/src/test/kotlin/model/FunctionsTest.kt
index 38f64df5..c96e7df6 100644
--- a/plugins/base/src/test/kotlin/model/FunctionsTest.kt
+++ b/plugins/base/src/test/kotlin/model/FunctionsTest.kt
@@ -141,9 +141,9 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun
"""
) {
with((this / "function" / "f").cast<DFunction>()) {
- with(extra[Annotations].assertNotNull("Annotations")) {
- content counts 1
- with(content.first()) {
+ with(extra[Annotations]!!.content.entries.single().value.assertNotNull("Annotations")) {
+ this counts 1
+ with(first()) {
dri.classNames equals "Suppress"
params.entries counts 1
(params["names"].assertNotNull("param") as ArrayValue).value equals listOf(StringValue("\"FOO\""))
@@ -161,8 +161,8 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun
"""
) {
with((this / "function" / "f").cast<DFunction>()) {
- extra[AdditionalModifiers]?.content counts 1
- extra[AdditionalModifiers]?.content exists ExtraModifiers.KotlinOnlyModifiers.Inline
+ extra[AdditionalModifiers]!!.content.entries.single().value counts 1
+ extra[AdditionalModifiers]!!.content.entries.single().value exists ExtraModifiers.KotlinOnlyModifiers.Inline
}
}
}
@@ -175,8 +175,8 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun
"""
) {
with((this / "function" / "f").cast<DFunction>()) {
- extra[AdditionalModifiers]?.content counts 1
- extra[AdditionalModifiers]?.content exists ExtraModifiers.KotlinOnlyModifiers.Suspend
+ extra[AdditionalModifiers]!!.content.entries.single().value counts 1
+ extra[AdditionalModifiers]!!.content.entries.single().value exists ExtraModifiers.KotlinOnlyModifiers.Suspend
}
}
}
@@ -189,9 +189,9 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun
"""
) {
with((this / "function" / "f").cast<DFunction>()) {
- extra[AdditionalModifiers]?.content counts 2
- extra[AdditionalModifiers]?.content exists ExtraModifiers.KotlinOnlyModifiers.Suspend
- extra[AdditionalModifiers]?.content exists ExtraModifiers.KotlinOnlyModifiers.Inline
+ extra[AdditionalModifiers]!!.content.entries.single().value counts 2
+ extra[AdditionalModifiers]!!.content.entries.single().value exists ExtraModifiers.KotlinOnlyModifiers.Suspend
+ extra[AdditionalModifiers]!!.content.entries.single().value exists ExtraModifiers.KotlinOnlyModifiers.Inline
}
}
}
@@ -204,10 +204,10 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun
"""
) {
with((this / "function" / "f").cast<DFunction>()) {
- with(extra[AdditionalModifiers].assertNotNull("AdditionalModifiers")) {
- content counts 2
- content exists ExtraModifiers.KotlinOnlyModifiers.Suspend
- content exists ExtraModifiers.KotlinOnlyModifiers.Inline
+ with(extra[AdditionalModifiers]!!.content.entries.single().value.assertNotNull("AdditionalModifiers")) {
+ this counts 2
+ this exists ExtraModifiers.KotlinOnlyModifiers.Suspend
+ this exists ExtraModifiers.KotlinOnlyModifiers.Inline
}
}
}
@@ -226,9 +226,9 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun
"""
) {
with((this / "function" / "Fancy").cast<DAnnotation>()) {
- with(extra[Annotations].assertNotNull("Annotations")) {
- content counts 3
- with(content.map { it.dri.classNames to it }.toMap()) {
+ with(extra[Annotations]!!.content.entries.single().value.assertNotNull("Annotations")) {
+ this counts 3
+ with(map { it.dri.classNames to it }.toMap()) {
with(this["Target"].assertNotNull("Target")) {
(params["allowedTargets"].assertNotNull("allowedTargets") as ArrayValue).value equals listOf(
EnumValue(
@@ -249,9 +249,9 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun
}
with((this / "function" / "function" / "notInlined").cast<DParameter>()) {
- with(this.extra[Annotations].assertNotNull("Annotations")) {
- content counts 1
- with(content.first()) {
+ with(this.extra[Annotations]!!.content.entries.single().value.assertNotNull("Annotations")) {
+ this counts 1
+ with(first()) {
dri.classNames equals "Fancy"
params.entries counts 0
}
@@ -268,8 +268,8 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun
"""
) {
with((this / "function" / "f" / "notInlined").cast<DParameter>()) {
- extra[AdditionalModifiers]?.content counts 1
- extra[AdditionalModifiers]?.content exists ExtraModifiers.KotlinOnlyModifiers.NoInline
+ extra[AdditionalModifiers]!!.content.entries.single().value counts 1
+ extra[AdditionalModifiers]!!.content.entries.single().value exists ExtraModifiers.KotlinOnlyModifiers.NoInline
}
}
}
@@ -296,9 +296,9 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun
}
}
- with(extra[Annotations].assertNotNull("Annotations")) {
- content counts 3
- with(content.map { it.dri.classNames to it }.toMap()) {
+ with(extra[Annotations]!!.content.entries.single().value.assertNotNull("Annotations")) {
+ this counts 3
+ with(map { it.dri.classNames to it }.toMap()) {
with(this["Target"].assertNotNull("Target")) {
(params["allowedTargets"].assertNotNull("allowedTargets") as ArrayValue).value equals listOf(
EnumValue(
@@ -319,9 +319,9 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun
}
with((this / "function" / "f").cast<DFunction>()) {
- with(this.extra[Annotations].assertNotNull("Annotations")) {
- content counts 1
- with(content.first()) {
+ with(this.extra[Annotations]!!.content.entries.single().value.assertNotNull("Annotations")) {
+ this counts 1
+ with(this.first()) {
dri.classNames equals "Fancy"
params.entries counts 1
(params["size"] as StringValue).value equals "1"
@@ -381,9 +381,9 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun
"""
) {
with((this / "function" / "f").cast<DFunction>()) {
- with(extra[Annotations].assertNotNull("Annotations")) {
- this.content counts 1
- with(content.first()) {
+ with(extra[Annotations]!!.content.entries.single().value.assertNotNull("Annotations")) {
+ this counts 1
+ with(first()) {
dri.classNames equals "SinceKotlin"
params.entries counts 1
(params["version"].assertNotNull("version") as StringValue).value equals "\"1.1\""
diff --git a/plugins/base/src/test/kotlin/model/JavaTest.kt b/plugins/base/src/test/kotlin/model/JavaTest.kt
index fd293b5c..8f52fcc8 100644
--- a/plugins/base/src/test/kotlin/model/JavaTest.kt
+++ b/plugins/base/src/test/kotlin/model/JavaTest.kt
@@ -295,9 +295,9 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") {
"""
) {
with((this / "java" / "C" / "foo").cast<DFunction>()) {
- with(extra[AdditionalModifiers].assertNotNull("AdditionalModifiers")) {
- content counts 1
- content.first() equals ExtraModifiers.JavaOnlyModifiers.Static
+ with(extra[AdditionalModifiers]!!.content.entries.single().value.assertNotNull("AdditionalModifiers")) {
+ this counts 1
+ first() equals ExtraModifiers.JavaOnlyModifiers.Static
}
}
}
@@ -335,8 +335,8 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") {
"""
) {
with((this / "java" / "Attribute").cast<DAnnotation>()) {
- with(extra[Annotations].assertNotNull("Annotations")) {
- with(content.single()) {
+ with(extra[Annotations]!!.content.entries.single().value.assertNotNull("Annotations")) {
+ with(single()) {
dri.classNames equals "Target"
(params["value"].assertNotNull("value") as ArrayValue).value equals listOf(
EnumValue("ElementType.FIELD", DRI("java.lang.annotation", "ElementType")),
diff --git a/plugins/base/src/test/kotlin/model/PropertyTest.kt b/plugins/base/src/test/kotlin/model/PropertyTest.kt
index 90a9d782..e384b920 100644
--- a/plugins/base/src/test/kotlin/model/PropertyTest.kt
+++ b/plugins/base/src/test/kotlin/model/PropertyTest.kt
@@ -150,9 +150,9 @@ class PropertyTest : AbstractModelTest("/src/main/kotlin/property/Test.kt", "pro
"""
) {
with((this / "property" / "prop").cast<DProperty>()) {
- with(extra[Annotations].assertNotNull("Annotations")) {
- this.content counts 1
- with(content.first()) {
+ with(extra[Annotations]!!.content.entries.single().value.assertNotNull("Annotations")) {
+ this counts 1
+ with(first()) {
dri.classNames equals "SinceKotlin"
params.entries counts 1
(params["version"].assertNotNull("version") as StringValue).value equals "\"1.1\""
@@ -178,9 +178,9 @@ class PropertyTest : AbstractModelTest("/src/main/kotlin/property/Test.kt", "pro
}
) {
with((this / "property" / "property").cast<DProperty>()) {
- with(extra[Annotations].assertNotNull("Annotations")) {
- this.content counts 1
- with(content.first()) {
+ with(extra[Annotations]!!.content.entries.single().value.assertNotNull("Annotations")) {
+ this counts 1
+ with(first()) {
dri.classNames equals "Strictfp"
params.entries counts 0
}
diff --git a/plugins/base/src/test/kotlin/utils/contentUtils.kt b/plugins/base/src/test/kotlin/utils/contentUtils.kt
index 7e1b8bf4..c7cea1f1 100644
--- a/plugins/base/src/test/kotlin/utils/contentUtils.kt
+++ b/plugins/base/src/test/kotlin/utils/contentUtils.kt
@@ -28,36 +28,34 @@ fun ContentMatcherBuilder<*>.bareSignature(
returnType: String? = null,
vararg params: Pair<String, ParamAttributes>
) = group { // TODO: remove it when double wrapping for signatures will be resolved
- group {
- annotations.entries.forEach {
- group {
- unwrapAnnotation(it)
- }
+ annotations.entries.forEach {
+ group {
+ unwrapAnnotation(it)
}
- +("$visibility $modifier ${keywords.joinToString("") { "$it " }} fun")
- link { +name }
- +"("
- params.forEachIndexed { id, (n, t) ->
-
- t.annotations.forEach {
- unwrapAnnotation(it)
- }
- t.keywords.forEach {
- +it
- }
+ }
+ +("$visibility $modifier ${keywords.joinToString("") { "$it " }} fun")
+ link { +name }
+ +"("
+ params.forEachIndexed { id, (n, t) ->
- +"$n:"
- group { link { +(t.type) } }
- if (id != params.lastIndex)
- +", "
+ t.annotations.forEach {
+ unwrapAnnotation(it)
}
- +")"
- if (returnType != null) {
- +(": ")
- group {
- link {
- +(returnType)
- }
+ t.keywords.forEach {
+ +it
+ }
+
+ +"$n:"
+ group { link { +(t.type) } }
+ if (id != params.lastIndex)
+ +", "
+ }
+ +")"
+ if (returnType != null) {
+ +(": ")
+ group {
+ link {
+ +(returnType)
}
}
}
@@ -87,40 +85,38 @@ fun ContentMatcherBuilder<*>.bareSignatureWithReceiver(
returnType: String? = null,
vararg params: Pair<String, ParamAttributes>
) = group { // TODO: remove it when double wrapping for signatures will be resolved
- group {
- annotations.entries.forEach {
- group {
- unwrapAnnotation(it)
- }
- }
- +("$visibility $modifier ${keywords.joinToString("") { "$it " }} fun")
+ annotations.entries.forEach {
group {
- link { +receiver }
+ unwrapAnnotation(it)
}
- +"."
- link { +name }
- +"("
- params.forEachIndexed { id, (n, t) ->
-
- t.annotations.forEach {
- unwrapAnnotation(it)
- }
- t.keywords.forEach {
- +it
- }
+ }
+ +("$visibility $modifier ${keywords.joinToString("") { "$it " }} fun")
+ group {
+ link { +receiver }
+ }
+ +"."
+ link { +name }
+ +"("
+ params.forEachIndexed { id, (n, t) ->
- +"$n:"
- group { link { +(t.type) } }
- if (id != params.lastIndex)
- +", "
+ t.annotations.forEach {
+ unwrapAnnotation(it)
}
- +")"
- if (returnType != null) {
- +(": ")
- group {
- link {
- +(returnType)
- }
+ t.keywords.forEach {
+ +it
+ }
+
+ +"$n:"
+ group { link { +(t.type) } }
+ if (id != params.lastIndex)
+ +", "
+ }
+ +")"
+ if (returnType != null) {
+ +(": ")
+ group {
+ link {
+ +(returnType)
}
}
}
@@ -148,20 +144,18 @@ fun ContentMatcherBuilder<*>.propertySignature(
link { +name }
platformHinted {
group {
- group {
- annotations.entries.forEach {
- group {
- unwrapAnnotation(it)
- }
+ annotations.entries.forEach {
+ group {
+ unwrapAnnotation(it)
}
- +("$visibility $modifier ${keywords.joinToString("") { "$it " }} $preposition")
- link { +name }
- if (type != null) {
- +(": ")
- group {
- link {
- +(type)
- }
+ }
+ +("$visibility $modifier ${keywords.joinToString("") { "$it " }} $preposition")
+ link { +name }
+ if (type != null) {
+ +(": ")
+ group {
+ link {
+ +(type)
}
}
}
@@ -184,15 +178,19 @@ fun ContentMatcherBuilder<*>.unnamedTag(tag: String, content: ContentMatcherBuil
group { content() }
}
-fun ContentMatcherBuilder<*>.unwrapAnnotation(elem: Map.Entry<String, Set<String>>) {
- +"@"
- link { +elem.key }
- +"("
- elem.value.forEach {
- +("$it = ")
- skipAllNotMatching()
+private fun ContentMatcherBuilder<*>.unwrapAnnotation(elem: Map.Entry<String, Set<String>>) {
+ group {
+ +"@"
+ link { +elem.key }
+ +"("
+ elem.value.forEach {
+ group {
+ +("$it = ")
+ skipAllNotMatching()
+ }
+ }
+ +")"
}
- +")"
}
data class ParamAttributes(
diff --git a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt
index 8f20f942..693fffac 100644
--- a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt
+++ b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt
@@ -76,7 +76,13 @@ internal fun DProperty.asJava(isTopLevel: Boolean = false, relocateToClass: Stri
type = type.asJava(), // TODO: check
setter = null,
getter = null, // Removing getters and setters as they will be available as functions
- extra = if (isTopLevel) extra.plus(extra.mergeAdditionalModifiers(setOf(ExtraModifiers.JavaOnlyModifiers.Static))) else extra
+ extra = if (isTopLevel) extra +
+ extra.mergeAdditionalModifiers(
+ sourceSets.map {
+ it to setOf(ExtraModifiers.JavaOnlyModifiers.Static)
+ }.toMap()
+ )
+ else extra
)
internal fun DProperty.javaAccessors(isTopLevel: Boolean = false, relocateToClass: String? = null): List<DFunction> =
@@ -95,7 +101,13 @@ internal fun DProperty.javaAccessors(isTopLevel: Boolean = false, relocateToClas
},
visibility = visibility.mapValues { JavaVisibility.Public },
type = type.asJava(), // TODO: check
- extra = if (isTopLevel) getter!!.extra.plus(getter!!.extra.mergeAdditionalModifiers(setOf(ExtraModifiers.JavaOnlyModifiers.Static))) else getter!!.extra
+ extra = if (isTopLevel) getter!!.extra +
+ getter!!.extra.mergeAdditionalModifiers(
+ sourceSets.map {
+ it to setOf(ExtraModifiers.JavaOnlyModifiers.Static)
+ }.toMap()
+ )
+ else getter!!.extra
),
setter?.copy(
dri = if (relocateToClass.isNullOrBlank()) {
@@ -111,7 +123,12 @@ internal fun DProperty.javaAccessors(isTopLevel: Boolean = false, relocateToClas
},
visibility = visibility.mapValues { JavaVisibility.Public },
type = type.asJava(), // TODO: check
- extra = if (isTopLevel) setter!!.extra.plus(setter!!.extra.mergeAdditionalModifiers(setOf(ExtraModifiers.JavaOnlyModifiers.Static))) else setter!!.extra
+ extra = if (isTopLevel) setter!!.extra + setter!!.extra.mergeAdditionalModifiers(
+ sourceSets.map {
+ it to setOf(ExtraModifiers.JavaOnlyModifiers.Static)
+ }.toMap()
+ )
+ else setter!!.extra
)
)
@@ -203,7 +220,9 @@ internal fun DObject.asJava(): DObject = copy(
receiver = null,
generics = emptyList(),
expectPresentInSet = expectPresentInSet,
- extra = PropertyContainer.empty<DProperty>() + AdditionalModifiers(setOf(ExtraModifiers.JavaOnlyModifiers.Static))
+ extra = PropertyContainer.withAll(sourceSets.map {
+ mapOf(it to setOf(ExtraModifiers.JavaOnlyModifiers.Static)).toAdditionalModifiers()
+ })
),
classlikes = classlikes.map { it.asJava() },
supertypes = supertypes.mapValues { it.value.map { it.possiblyAsJava() } }
@@ -248,7 +267,7 @@ internal fun ClassId.toDRI(dri: DRI?): DRI = DRI(
target = PointingToDeclaration
)
-private fun PropertyContainer<out Documentable>.mergeAdditionalModifiers(second: Set<ExtraModifiers>) =
+private fun PropertyContainer<out Documentable>.mergeAdditionalModifiers(second: SourceSetDependent<Set<ExtraModifiers>>) =
this[AdditionalModifiers]?.squash(AdditionalModifiers(second)) ?: AdditionalModifiers(second)
private fun AdditionalModifiers.squash(second: AdditionalModifiers) =
diff --git a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt
index a55f9339..5c4985ac 100644
--- a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt
+++ b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt
@@ -41,7 +41,7 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge
if (c is DClass) {
platformText(c.modifier) { it.takeIf { it !in ignoredModifiers }?.name.orEmpty() + " " }
- text(c.modifiers().toSignatureString())
+ platformText(c.modifiers()) { it.toSignatureString() }
}
when (c) {
@@ -71,7 +71,7 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge
annotationsBlock(p)
platformText(p.visibility) { (it.takeIf { it !in ignoredVisibilities }?.name ?: "") + " " }
platformText(p.modifier) { it.name + " " }
- text(p.modifiers().toSignatureString())
+ platformText(p.modifiers()) { it.toSignatureString() }
signatureForProjection(p.type)
text(nbsp.toString())
link(p.name, p.dri)
@@ -82,7 +82,7 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge
group(styles = setOf(TextStyle.Block)) {
annotationsBlock(f)
platformText(f.modifier) { it.takeIf { it !in ignoredModifiers }?.name.orEmpty() + " " }
- text(f.modifiers().toSignatureString())
+ platformText(f.modifiers()) { it.toSignatureString() }
val returnType = f.type
signatureForProjection(returnType)
text(nbsp.toString())
@@ -92,7 +92,7 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge
}
list(f.parameters, "(", ")") {
annotationsInline(it)
- text(it.modifiers().toSignatureString())
+ platformText(it.modifiers()) { it.toSignatureString() }
signatureForProjection(it.type)
text(nbsp.toString())
link(it.name!!, it.dri)
diff --git a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureUtils.kt b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureUtils.kt
index e2f73bf9..b4245834 100644
--- a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureUtils.kt
+++ b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureUtils.kt
@@ -28,6 +28,8 @@ object JavaSignatureUtils : JvmSignatureUtils {
annotationsInlineWithIgnored(d, ignoredAnnotations, strategy, listBrackets, classExtension)
override fun <T : Documentable> WithExtraProperties<T>.modifiers() =
- extra[AdditionalModifiers]?.content?.filterIsInstance<ExtraModifiers.JavaOnlyModifiers>()?.toSet() ?: emptySet()
+ extra[AdditionalModifiers]?.content?.entries?.map {
+ it.key to it.value.filterIsInstance<ExtraModifiers.JavaOnlyModifiers>().toSet()
+ }?.toMap() ?: emptyMap()
} \ No newline at end of file