diff options
author | Andrzej Ratajczak <andrzej.ratajczak98@gmail.com> | 2020-05-21 11:29:22 +0200 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-05-26 11:32:03 +0200 |
commit | 77fa898e8abdc8e74169fa789f2ba0e32d8fa9d7 (patch) | |
tree | 9dde7add6b12ff8a366281787c7b7a9455c1d205 /plugins/base/src/main/kotlin | |
parent | d47d386ad8c0ff4a2c3b9d5b4450a773bdcba2dc (diff) | |
download | dokka-77fa898e8abdc8e74169fa789f2ba0e32d8fa9d7.tar.gz dokka-77fa898e8abdc8e74169fa789f2ba0e32d8fa9d7.tar.bz2 dokka-77fa898e8abdc8e74169fa789f2ba0e32d8fa9d7.zip |
Apply request changes
Diffstat (limited to 'plugins/base/src/main/kotlin')
-rw-r--r-- | plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt (renamed from plugins/base/src/main/kotlin/signatures/JvmSingatureUtils.kt) | 22 | ||||
-rw-r--r-- | plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt | 5 | ||||
-rw-r--r-- | plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt | 9 | ||||
-rw-r--r-- | plugins/base/src/main/kotlin/signatures/SignatureProvider.kt | 4 | ||||
-rw-r--r-- | plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt | 66 | ||||
-rw-r--r-- | plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt | 6 | ||||
-rw-r--r-- | plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt | 17 |
7 files changed, 62 insertions, 67 deletions
diff --git a/plugins/base/src/main/kotlin/signatures/JvmSingatureUtils.kt b/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt index dde553b9..0ae72109 100644 --- a/plugins/base/src/main/kotlin/signatures/JvmSingatureUtils.kt +++ b/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt @@ -1,11 +1,10 @@ package org.jetbrains.dokka.base.signatures -import javaslang.Tuple2 import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder import org.jetbrains.dokka.model.* import org.jetbrains.dokka.model.properties.WithExtraProperties -interface JvmSingatureUtils { +interface JvmSignatureUtils { fun PageContentBuilder.DocumentableContentBuilder.annotationsBlock(d: Documentable) @@ -20,7 +19,7 @@ interface JvmSingatureUtils { extra[Annotations]?.content ?: emptyList() private fun Annotations.Annotation.toSignatureString(): String = - "@${this.dri.classNames}(${this.params.entries.joinToString { it.key + "=" + it.value }})" + "@" + this.dri.classNames + "(" + this.params.entries.joinToString { it.key + "=" + it.value } + ")" private fun PageContentBuilder.DocumentableContentBuilder.annotations( d: Documentable, @@ -45,15 +44,10 @@ interface JvmSingatureUtils { } } ?: Unit - fun <T : Documentable> WithExtraProperties<T>.modifiersWithFilter( - filter: Set<ExtraModifiers> = ExtraModifiers.values().toSet() - ): Set<ExtraModifiers> = - extra[AdditionalModifiers]?.content?.filter { it in filter }?.toSet() ?: emptySet() - fun PageContentBuilder.DocumentableContentBuilder.toSignatureString( a: Annotations.Annotation, renderAtStrategy: AtStrategy, - listBrackets: Tuple2<Char, Char>, + listBrackets: Pair<Char, Char>, classExtension: String ) { when (renderAtStrategy) { @@ -78,17 +72,17 @@ interface JvmSingatureUtils { private fun PageContentBuilder.DocumentableContentBuilder.valueToSignature( a: AnnotationParameterValue, renderAtStrategy: AtStrategy, - listBrackets: Tuple2<Char, Char>, + listBrackets: Pair<Char, Char>, classExtension: String ): Unit = when (a) { is AnnotationValue -> toSignatureString(a.annotation, renderAtStrategy, listBrackets, classExtension) is ArrayValue -> { - text(listBrackets._1.toString()) + text(listBrackets.first.toString()) a.value.forEachIndexed { i, it -> valueToSignature(it, renderAtStrategy, listBrackets, classExtension) if (i != a.value.size - 1) text(", ") } - text(listBrackets._2.toString()) + text(listBrackets.second.toString()) } is EnumValue -> link(a.enumName, a.enumDri) is ClassValue -> link(a.className + classExtension, a.classDRI) @@ -99,7 +93,7 @@ interface JvmSingatureUtils { d: Documentable, ignored: Set<Annotations.Annotation>, renderAtStrategy: AtStrategy, - listBrackets: Tuple2<Char, Char>, + listBrackets: Pair<Char, Char>, classExtension: String ) { annotations(d, ignored) { @@ -113,7 +107,7 @@ interface JvmSingatureUtils { d: Documentable, ignored: Set<Annotations.Annotation>, renderAtStrategy: AtStrategy, - listBrackets: Tuple2<Char, Char>, + listBrackets: Pair<Char, Char>, classExtension: String ) { annotations(d, ignored) { diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt index 4c689abc..33c82458 100644 --- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt +++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt @@ -6,7 +6,6 @@ import org.jetbrains.dokka.links.* import org.jetbrains.dokka.model.* import org.jetbrains.dokka.model.Nullable import org.jetbrains.dokka.model.TypeConstructor -import org.jetbrains.dokka.model.properties.ExtraProperty import org.jetbrains.dokka.model.properties.WithExtraProperties import org.jetbrains.dokka.pages.ContentKind import org.jetbrains.dokka.pages.ContentNode @@ -15,7 +14,7 @@ import org.jetbrains.dokka.utilities.DokkaLogger import kotlin.text.Typography.nbsp class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogger) : SignatureProvider, - JvmSingatureUtils by KotlinSignatureUtils { + JvmSignatureUtils by KotlinSignatureUtils { private val contentBuilder = PageContentBuilder(ctcc, this, logger) private val ignoredVisibilities = setOf(JavaVisibility.Public, KotlinVisibility.Public) @@ -69,7 +68,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog if (c is DClass) { platformText(c.modifier, sourceSets) { if (it !in ignoredModifiers) - if (c.extra[AdditionalModifiers]?.content?.contains(ExtraModifiers.DATA) == true) "" + if (c.extra[AdditionalModifiers]?.content?.contains(ExtraModifiers.KotlinOnlyModifiers.Data) == true) "" else (if (it is JavaModifier.Empty) KotlinModifier.Open else it).let { it.name + " " } else "" diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt index 3ce4be0a..48cfe304 100644 --- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt +++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt @@ -1,16 +1,15 @@ package org.jetbrains.dokka.base.signatures -import javaslang.Tuple2 import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder +import org.jetbrains.dokka.model.AdditionalModifiers import org.jetbrains.dokka.model.Documentable import org.jetbrains.dokka.model.ExtraModifiers -import org.jetbrains.dokka.model.ExtraModifiers.Companion.kotlinOnlyModifiers import org.jetbrains.dokka.model.properties.WithExtraProperties -object KotlinSignatureUtils : JvmSingatureUtils { +object KotlinSignatureUtils : JvmSignatureUtils { private val strategy = OnlyOnce - private val listBrackets = Tuple2('[', ']') + private val listBrackets = Pair('[', ']') private val classExtension = "::class" override fun PageContentBuilder.DocumentableContentBuilder.annotationsBlock(d: Documentable) = @@ -20,5 +19,5 @@ object KotlinSignatureUtils : JvmSingatureUtils { annotationsInlineWithIgnored(d, emptySet(), strategy, listBrackets, classExtension) override fun <T : Documentable> WithExtraProperties<T>.modifiers() = - modifiersWithFilter(kotlinOnlyModifiers) + extra[AdditionalModifiers]?.content?.filterIsInstance<ExtraModifiers.KotlinOnlyModifiers>()?.toSet() ?: emptySet() }
\ No newline at end of file diff --git a/plugins/base/src/main/kotlin/signatures/SignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/SignatureProvider.kt index 7d7995b7..c04b6ecf 100644 --- a/plugins/base/src/main/kotlin/signatures/SignatureProvider.kt +++ b/plugins/base/src/main/kotlin/signatures/SignatureProvider.kt @@ -1,11 +1,7 @@ package org.jetbrains.dokka.base.signatures -import javaslang.Tuple2 -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.ContentNode -import org.jetbrains.dokka.pages.TextStyle interface SignatureProvider { fun signature(documentable: Documentable): ContentNode diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index c24a3384..65b83200 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -46,7 +46,7 @@ import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeProjection import org.jetbrains.kotlin.utils.addToStdlib.safeAs import java.nio.file.Paths -import java.lang.IllegalArgumentException +import kotlin.IllegalArgumentException import kotlin.reflect.jvm.internal.impl.resolve.constants.KClassValue object DefaultDescriptorToDocumentableTranslator : SourceToDocumentableTranslator { @@ -546,9 +546,7 @@ private class DokkaDescriptorVisitor( is TypeParameterDescriptor -> OtherParameter( declarationDRI = DRI.from(ctor.containingDeclaration), name = ctor.name.asString() - ).let { - if (isMarkedNullable) Nullable(it) else it - } + ) else -> TypeConstructor( DRI.from(constructor.declarationDescriptor!!), // TODO: remove '!!' arguments.map { it.toProjection() }, @@ -556,6 +554,8 @@ private class DokkaDescriptorVisitor( else if (isFunctionType) FunctionModifiers.FUNCTION else FunctionModifiers.NONE ) + }.let { + if (isMarkedNullable) Nullable(it) else it } } @@ -593,43 +593,43 @@ private class DokkaDescriptorVisitor( DescriptorDocumentableSource(this).toSourceSetDependent() private fun FunctionDescriptor.additionalExtras() = listOfNotNull( - 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) } + ExtraModifiers.KotlinOnlyModifiers.Infix.takeIf { isInfix }, + ExtraModifiers.KotlinOnlyModifiers.Inline.takeIf { isInline }, + ExtraModifiers.KotlinOnlyModifiers.Suspend.takeIf { isSuspend }, + ExtraModifiers.KotlinOnlyModifiers.Operator.takeIf { isOperator }, + ExtraModifiers.JavaOnlyModifiers.Static.takeIf { isJvmStaticInObjectOrClassOrInterface() }, + ExtraModifiers.KotlinOnlyModifiers.TailRec.takeIf { isTailrec }, + ExtraModifiers.KotlinOnlyModifiers.External.takeIf { isExternal }, + ExtraModifiers.KotlinOnlyModifiers.Override.takeIf { DescriptorUtils.isOverride(this) } ).toProperty() private fun ClassDescriptor.additionalExtras() = listOfNotNull( - ExtraModifiers.INLINE.takeIf { isInline }, - ExtraModifiers.EXTERNAL.takeIf { isExternal }, - ExtraModifiers.INNER.takeIf { isInner }, - ExtraModifiers.DATA.takeIf { isData } + 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.NOINLINE.takeIf { isNoinline }, - ExtraModifiers.CROSSINLINE.takeIf { isCrossinline }, - ExtraModifiers.CONST.takeIf { isConst }, - ExtraModifiers.LATEINIT.takeIf { isLateInit }, - ExtraModifiers.VARARG.takeIf { isVararg } + 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.REIFIED.takeIf { isReified } + ExtraModifiers.KotlinOnlyModifiers.Reified.takeIf { isReified } ).toProperty() private fun PropertyDescriptor.additionalExtras() = listOfNotNull( - ExtraModifiers.CONST.takeIf { isConst }, - ExtraModifiers.LATEINIT.takeIf { isLateInit }, - ExtraModifiers.STATIC.takeIf { isJvmStaticInObjectOrClassOrInterface() }, - ExtraModifiers.EXTERNAL.takeIf { isExternal }, - ExtraModifiers.OVERRIDE.takeIf { DescriptorUtils.isOverride(this) } + ExtraModifiers.KotlinOnlyModifiers.Const.takeIf { isConst }, + ExtraModifiers.KotlinOnlyModifiers.LateInit.takeIf { isLateInit }, + ExtraModifiers.JavaOnlyModifiers.Static.takeIf { isJvmStaticInObjectOrClassOrInterface() }, + ExtraModifiers.KotlinOnlyModifiers.External.takeIf { isExternal }, + ExtraModifiers.KotlinOnlyModifiers.Override.takeIf { DescriptorUtils.isOverride(this) } ) private fun List<ExtraModifiers>.toProperty() = @@ -640,11 +640,12 @@ private class DokkaDescriptorVisitor( private fun Annotated.getListOfAnnotations() = annotations.map { it.toAnnotation() } private fun ConstantValue<*>.toValue(): AnnotationParameterValue = when (this) { - is ConstantsAnnotationValue -> AnnotationValue(value.let { it.toAnnotation() }) + is ConstantsAnnotationValue -> AnnotationValue(value.toAnnotation()) is ConstantsArrayValue -> ArrayValue(value.map { it.toValue() }) is ConstantsEnumValue -> EnumValue( - enumEntryName.identifier, - enumClassId.let { DRI(it.packageFqName.asString(), it.relativeClassName.asString()) }) + fullEnumEntryName(), + DRI(enumClassId.packageFqName.asString(), fullEnumEntryName()) + ) is ConstantsKtClassValue -> when(value) { is NormalClass -> (value as NormalClass).value.classId.let { ClassValue( @@ -672,7 +673,7 @@ private class DokkaDescriptorVisitor( private fun FieldDescriptor.getAnnotationsAsExtraModifiers() = getAnnotations().content.mapNotNull { try { - ExtraModifiers.valueOf(it.dri.classNames?.toUpperCase() ?: "") + ExtraModifiers.valueOf(it.dri.classNames?.toLowerCase() ?: "") } catch (e: IllegalArgumentException) { null } @@ -690,4 +691,7 @@ private class DokkaDescriptorVisitor( Visibilities.PRIVATE -> KotlinVisibility.Private else -> KotlinVisibility.Public } + + private fun ConstantsEnumValue.fullEnumEntryName() = + "${this.enumClassId.relativeClassName.asString()}.${this.enumEntryName.identifier}" } diff --git a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt index 658a86f2..5ff5a954 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt @@ -338,8 +338,10 @@ open class PageContentBuilder( value: SourceSetDependent<T>, platforms: Set<SourceSetData> = value.keys, transform: (T) -> String - ) = value.entries.filter { it.key in platforms }.forEach { (p, v) -> - transform(v).takeIf { it.isNotBlank() }?.also { text(it, sourceSets = setOf(p)) } + ) = value.entries.filter { it.key in platforms }.mapNotNull { (p, v) -> + transform(v).takeIf { it.isNotBlank() }?.let { it to p } + }.groupBy({ it.first }) { it.second }.forEach { + text(it.key, sourceSets = it.value.toSet()) } } diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt index 0f8fc011..9c731528 100644 --- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt @@ -1,5 +1,6 @@ package org.jetbrains.dokka.base.translators.psi +import com.intellij.icons.AllIcons.Nodes.Static import com.intellij.lang.jvm.annotation.JvmAnnotationAttribute import com.intellij.lang.jvm.JvmModifier import com.intellij.lang.jvm.types.JvmReferenceType @@ -275,18 +276,18 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { private fun PsiModifierListOwner.additionalExtras() = AdditionalModifiers( listOfNotNull( - ExtraModifiers.STATIC.takeIf { hasModifier(JvmModifier.STATIC) }, - ExtraModifiers.NATIVE.takeIf { hasModifier(JvmModifier.NATIVE) }, - ExtraModifiers.SYNCHRONIZED.takeIf { hasModifier(JvmModifier.SYNCHRONIZED) }, - ExtraModifiers.STRICTFP.takeIf { hasModifier(JvmModifier.STRICTFP) }, - ExtraModifiers.TRANSIENT.takeIf { hasModifier(JvmModifier.TRANSIENT) }, - ExtraModifiers.VOLATILE.takeIf { hasModifier(JvmModifier.VOLATILE) }, - ExtraModifiers.TRANSITIVE.takeIf { hasModifier(JvmModifier.TRANSITIVE) } + 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() = this.content.map { - if (it.name != "STATIC") + if (it !is ExtraModifiers.JavaOnlyModifiers.Static) Annotations.Annotation(DRI("kotlin.jvm", it.name.toLowerCase().capitalize()), emptyMap()) else Annotations.Annotation(DRI("kotlin.jvm", "JvmStatic"), emptyMap()) |