diff options
author | vmishenev <vad-mishenev@yandex.ru> | 2021-08-09 12:51:59 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-09 11:51:59 +0200 |
commit | d197f0544b4cd1ade870ebde0d6a6a43a94daf9a (patch) | |
tree | 979d44a4e5b127956987f0d0d234b90594ce3152 | |
parent | ec2bf8a57c744008c30d03c4aec0921a091faa81 (diff) | |
download | dokka-d197f0544b4cd1ade870ebde0d6a6a43a94daf9a.tar.gz dokka-d197f0544b4cd1ade870ebde0d6a6a43a94daf9a.tar.bz2 dokka-d197f0544b4cd1ade870ebde0d6a6a43a94daf9a.zip |
Property annotation for getter and setter (#2049)
-rw-r--r-- | core/api/core.api | 2 | ||||
-rw-r--r-- | core/src/main/kotlin/model/additionalExtras.kt | 2 | ||||
-rw-r--r-- | plugins/base/api/base.api | 8 | ||||
-rw-r--r-- | plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt | 22 | ||||
-rw-r--r-- | plugins/base/src/test/kotlin/signatures/SignatureTest.kt | 34 | ||||
-rw-r--r-- | plugins/javadoc/api/javadoc.api | 2 | ||||
-rw-r--r-- | plugins/kotlin-as-java/api/kotlin-as-java.api | 4 |
7 files changed, 72 insertions, 2 deletions
diff --git a/core/api/core.api b/core/api/core.api index 91ea34d3..ca2b28f9 100644 --- a/core/api/core.api +++ b/core/api/core.api @@ -661,6 +661,8 @@ public final class org/jetbrains/dokka/model/Annotations$Annotation { public final class org/jetbrains/dokka/model/Annotations$AnnotationScope : java/lang/Enum { public static final field DIRECT Lorg/jetbrains/dokka/model/Annotations$AnnotationScope; public static final field FILE Lorg/jetbrains/dokka/model/Annotations$AnnotationScope; + public static final field GETTER Lorg/jetbrains/dokka/model/Annotations$AnnotationScope; + public static final field SETTER Lorg/jetbrains/dokka/model/Annotations$AnnotationScope; public static fun valueOf (Ljava/lang/String;)Lorg/jetbrains/dokka/model/Annotations$AnnotationScope; public static fun values ()[Lorg/jetbrains/dokka/model/Annotations$AnnotationScope; } diff --git a/core/src/main/kotlin/model/additionalExtras.kt b/core/src/main/kotlin/model/additionalExtras.kt index 4f78e7af..62e1fa2d 100644 --- a/core/src/main/kotlin/model/additionalExtras.kt +++ b/core/src/main/kotlin/model/additionalExtras.kt @@ -61,7 +61,7 @@ data class Annotations( }.toMap() enum class AnnotationScope { - DIRECT, FILE + DIRECT, FILE, GETTER, SETTER } } diff --git a/plugins/base/api/base.api b/plugins/base/api/base.api index 454fa4e0..e043029f 100644 --- a/plugins/base/api/base.api +++ b/plugins/base/api/base.api @@ -797,12 +797,14 @@ public abstract class org/jetbrains/dokka/base/signatures/AtStrategy { } public abstract interface class org/jetbrains/dokka/base/signatures/JvmSignatureUtils { + public abstract fun annotations (Lorg/jetbrains/dokka/model/DProperty;)Ljava/util/Map; public abstract fun annotations (Lorg/jetbrains/dokka/model/properties/WithExtraProperties;)Ljava/util/Map; public abstract fun annotationsBlock (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;)V public abstract fun annotationsBlockWithIgnored (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;Ljava/util/Set;Lorg/jetbrains/dokka/base/signatures/AtStrategy;Lkotlin/Pair;Ljava/lang/String;)V public abstract fun annotationsInline (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;)V public abstract fun annotationsInlineWithIgnored (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;Ljava/util/Set;Lorg/jetbrains/dokka/base/signatures/AtStrategy;Lkotlin/Pair;Ljava/lang/String;)V public abstract fun modifiers (Lorg/jetbrains/dokka/model/properties/WithExtraProperties;)Ljava/util/Map; + public abstract fun plus (Ljava/util/Map;Ljava/util/Map;)Ljava/util/Map; public abstract fun stylesIfDeprecated (Lorg/jetbrains/dokka/model/properties/WithExtraProperties;Lorg/jetbrains/dokka/DokkaConfiguration$DokkaSourceSet;)Ljava/util/Set; public abstract fun toSignatureString (Ljava/util/Collection;)Ljava/lang/String; public abstract fun toSignatureString (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/Annotations$Annotation;Lorg/jetbrains/dokka/base/signatures/AtStrategy;Lkotlin/Pair;Ljava/lang/String;)V @@ -810,9 +812,11 @@ public abstract interface class org/jetbrains/dokka/base/signatures/JvmSignature } public final class org/jetbrains/dokka/base/signatures/JvmSignatureUtils$DefaultImpls { + public static fun annotations (Lorg/jetbrains/dokka/base/signatures/JvmSignatureUtils;Lorg/jetbrains/dokka/model/DProperty;)Ljava/util/Map; public static fun annotations (Lorg/jetbrains/dokka/base/signatures/JvmSignatureUtils;Lorg/jetbrains/dokka/model/properties/WithExtraProperties;)Ljava/util/Map; public static fun annotationsBlockWithIgnored (Lorg/jetbrains/dokka/base/signatures/JvmSignatureUtils;Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;Ljava/util/Set;Lorg/jetbrains/dokka/base/signatures/AtStrategy;Lkotlin/Pair;Ljava/lang/String;)V public static fun annotationsInlineWithIgnored (Lorg/jetbrains/dokka/base/signatures/JvmSignatureUtils;Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;Ljava/util/Set;Lorg/jetbrains/dokka/base/signatures/AtStrategy;Lkotlin/Pair;Ljava/lang/String;)V + public static fun plus (Lorg/jetbrains/dokka/base/signatures/JvmSignatureUtils;Ljava/util/Map;Ljava/util/Map;)Ljava/util/Map; public static fun stylesIfDeprecated (Lorg/jetbrains/dokka/base/signatures/JvmSignatureUtils;Lorg/jetbrains/dokka/model/properties/WithExtraProperties;Lorg/jetbrains/dokka/DokkaConfiguration$DokkaSourceSet;)Ljava/util/Set; public static fun toSignatureString (Lorg/jetbrains/dokka/base/signatures/JvmSignatureUtils;Ljava/util/Collection;)Ljava/lang/String; public static fun toSignatureString (Lorg/jetbrains/dokka/base/signatures/JvmSignatureUtils;Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/Annotations$Annotation;Lorg/jetbrains/dokka/base/signatures/AtStrategy;Lkotlin/Pair;Ljava/lang/String;)V @@ -822,12 +826,14 @@ public final class org/jetbrains/dokka/base/signatures/JvmSignatureUtils$Default public final class org/jetbrains/dokka/base/signatures/KotlinSignatureProvider : org/jetbrains/dokka/base/signatures/JvmSignatureUtils, org/jetbrains/dokka/base/signatures/SignatureProvider { public fun <init> (Lorg/jetbrains/dokka/base/transformers/pages/comments/CommentsToContentConverter;Lorg/jetbrains/dokka/utilities/DokkaLogger;)V public fun <init> (Lorg/jetbrains/dokka/plugability/DokkaContext;)V + public fun annotations (Lorg/jetbrains/dokka/model/DProperty;)Ljava/util/Map; public fun annotations (Lorg/jetbrains/dokka/model/properties/WithExtraProperties;)Ljava/util/Map; public fun annotationsBlock (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;)V public fun annotationsBlockWithIgnored (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;Ljava/util/Set;Lorg/jetbrains/dokka/base/signatures/AtStrategy;Lkotlin/Pair;Ljava/lang/String;)V public fun annotationsInline (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;)V public fun annotationsInlineWithIgnored (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;Ljava/util/Set;Lorg/jetbrains/dokka/base/signatures/AtStrategy;Lkotlin/Pair;Ljava/lang/String;)V public fun modifiers (Lorg/jetbrains/dokka/model/properties/WithExtraProperties;)Ljava/util/Map; + public fun plus (Ljava/util/Map;Ljava/util/Map;)Ljava/util/Map; public fun signature (Lorg/jetbrains/dokka/model/Documentable;)Ljava/util/List; public fun stylesIfDeprecated (Lorg/jetbrains/dokka/model/properties/WithExtraProperties;Lorg/jetbrains/dokka/DokkaConfiguration$DokkaSourceSet;)Ljava/util/Set; public fun toSignatureString (Ljava/util/Collection;)Ljava/lang/String; @@ -837,6 +843,7 @@ public final class org/jetbrains/dokka/base/signatures/KotlinSignatureProvider : public final class org/jetbrains/dokka/base/signatures/KotlinSignatureUtils : org/jetbrains/dokka/base/signatures/JvmSignatureUtils { public static final field INSTANCE Lorg/jetbrains/dokka/base/signatures/KotlinSignatureUtils; + public fun annotations (Lorg/jetbrains/dokka/model/DProperty;)Ljava/util/Map; public fun annotations (Lorg/jetbrains/dokka/model/properties/WithExtraProperties;)Ljava/util/Map; public fun annotationsBlock (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;)V public fun annotationsBlockWithIgnored (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;Ljava/util/Set;Lorg/jetbrains/dokka/base/signatures/AtStrategy;Lkotlin/Pair;Ljava/lang/String;)V @@ -846,6 +853,7 @@ public final class org/jetbrains/dokka/base/signatures/KotlinSignatureUtils : or public final fun getDriOrNull (Lorg/jetbrains/dokka/model/Bound;)Lorg/jetbrains/dokka/links/DRI; public final fun getDrisOfAllNestedBounds (Lorg/jetbrains/dokka/model/Projection;)Ljava/util/List; public fun modifiers (Lorg/jetbrains/dokka/model/properties/WithExtraProperties;)Ljava/util/Map; + public fun plus (Ljava/util/Map;Ljava/util/Map;)Ljava/util/Map; public fun stylesIfDeprecated (Lorg/jetbrains/dokka/model/properties/WithExtraProperties;Lorg/jetbrains/dokka/DokkaConfiguration$DokkaSourceSet;)Ljava/util/Set; public fun toSignatureString (Ljava/util/Collection;)Ljava/lang/String; public fun toSignatureString (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/Annotations$Annotation;Lorg/jetbrains/dokka/base/signatures/AtStrategy;Lkotlin/Pair;Ljava/lang/String;)V diff --git a/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt b/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt index a2624da0..d17fa276 100644 --- a/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt +++ b/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt @@ -8,6 +8,7 @@ import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet import org.jetbrains.dokka.base.signatures.KotlinSignatureUtils.drisOfAllNestedBounds import org.jetbrains.dokka.model.AnnotationTarget +import org.jetbrains.dokka.model.doc.DocumentationNode interface JvmSignatureUtils { @@ -23,6 +24,19 @@ interface JvmSignatureUtils { fun <T : AnnotationTarget> WithExtraProperties<T>.annotations(): SourceSetDependent<List<Annotations.Annotation>> = extra[Annotations]?.directAnnotations ?: emptyMap() + @Suppress("UNCHECKED_CAST") + operator fun <T : Iterable<*>> SourceSetDependent<T>.plus(other: SourceSetDependent<T>): SourceSetDependent<T> = + LinkedHashMap(this).apply { + for ((k, v) in other) { + put(k, get(k).let { if (it != null) (it + v) as T else v }) + } + } + + fun DProperty.annotations(): SourceSetDependent<List<Annotations.Annotation>> = + (extra[Annotations]?.directAnnotations ?: emptyMap()) + + (getter?.annotations() ?: emptyMap()).mapValues { it.value.map { it.copy( scope = Annotations.AnnotationScope.GETTER) } } + + (setter?.annotations() ?: emptyMap()).mapValues { it.value.map { it.copy( scope = Annotations.AnnotationScope.SETTER) } } + private fun PageContentBuilder.DocumentableContentBuilder.annotations( d: AnnotationTarget, ignored: Set<Annotations.Annotation>, @@ -65,7 +79,13 @@ interface JvmSignatureUtils { ) { when (renderAtStrategy) { - is All, is OnlyOnce -> text("@") + is All, is OnlyOnce -> { + text("@") + when(a.scope) { + Annotations.AnnotationScope.GETTER -> text("get:") + Annotations.AnnotationScope.SETTER -> text("set:") + } + } is Never -> Unit } link(a.dri.classNames!!, a.dri) diff --git a/plugins/base/src/test/kotlin/signatures/SignatureTest.kt b/plugins/base/src/test/kotlin/signatures/SignatureTest.kt index 35590d52..a56c408b 100644 --- a/plugins/base/src/test/kotlin/signatures/SignatureTest.kt +++ b/plugins/base/src/test/kotlin/signatures/SignatureTest.kt @@ -280,6 +280,40 @@ class SignatureTest : BaseAbstractTest() { } @Test + fun `property with annotation`() { + val source = """ + |/src/main/kotlin/test/Test.kt + |package example + | + | @MustBeDocumented() + | @Target(AnnotationTarget.FUNCTION) + | annotation class Marking + | + | @get:Marking() + | @set:Marking() + | var str: String + """.trimIndent() + val writerPlugin = TestOutputWriterPlugin() + + testInline( + source, + configuration, + pluginOverrides = listOf(writerPlugin) + ) { + renderingStage = { _, _ -> + writerPlugin.writer.renderedContent("root/example/str.html").firstSignature().match( + Div( + Div("@get:", A("Marking")), + Div("@set:", A("Marking")) + ), + "var ", A("str"), + ": ", A("String"), Span() + ) + } + } + } + + @Test fun `fun with two annotations`() { val source = """ |/src/main/kotlin/test/Test.kt diff --git a/plugins/javadoc/api/javadoc.api b/plugins/javadoc/api/javadoc.api index 2bd13b70..e2f3750d 100644 --- a/plugins/javadoc/api/javadoc.api +++ b/plugins/javadoc/api/javadoc.api @@ -637,12 +637,14 @@ public final class org/jetbrains/dokka/javadoc/renderer/SearchScriptsCreator { public final class org/jetbrains/dokka/javadoc/signatures/JavadocSignatureProvider : org/jetbrains/dokka/base/signatures/JvmSignatureUtils, org/jetbrains/dokka/base/signatures/SignatureProvider { public fun <init> (Lorg/jetbrains/dokka/base/transformers/pages/comments/CommentsToContentConverter;Lorg/jetbrains/dokka/utilities/DokkaLogger;)V public fun <init> (Lorg/jetbrains/dokka/plugability/DokkaContext;)V + public fun annotations (Lorg/jetbrains/dokka/model/DProperty;)Ljava/util/Map; public fun annotations (Lorg/jetbrains/dokka/model/properties/WithExtraProperties;)Ljava/util/Map; public fun annotationsBlock (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;)V public fun annotationsBlockWithIgnored (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;Ljava/util/Set;Lorg/jetbrains/dokka/base/signatures/AtStrategy;Lkotlin/Pair;Ljava/lang/String;)V public fun annotationsInline (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;)V public fun annotationsInlineWithIgnored (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;Ljava/util/Set;Lorg/jetbrains/dokka/base/signatures/AtStrategy;Lkotlin/Pair;Ljava/lang/String;)V public fun modifiers (Lorg/jetbrains/dokka/model/properties/WithExtraProperties;)Ljava/util/Map; + public fun plus (Ljava/util/Map;Ljava/util/Map;)Ljava/util/Map; public fun signature (Lorg/jetbrains/dokka/model/Documentable;)Ljava/util/List; public fun stylesIfDeprecated (Lorg/jetbrains/dokka/model/properties/WithExtraProperties;Lorg/jetbrains/dokka/DokkaConfiguration$DokkaSourceSet;)Ljava/util/Set; public fun toSignatureString (Ljava/util/Collection;)Ljava/lang/String; diff --git a/plugins/kotlin-as-java/api/kotlin-as-java.api b/plugins/kotlin-as-java/api/kotlin-as-java.api index d80cdb8f..4dd8b33a 100644 --- a/plugins/kotlin-as-java/api/kotlin-as-java.api +++ b/plugins/kotlin-as-java/api/kotlin-as-java.api @@ -12,12 +12,14 @@ public final class org/jetbrains/dokka/kotlinAsJava/converters/KotlinToJavaConve public final class org/jetbrains/dokka/kotlinAsJava/signatures/JavaSignatureProvider : org/jetbrains/dokka/base/signatures/JvmSignatureUtils, org/jetbrains/dokka/base/signatures/SignatureProvider { public fun <init> (Lorg/jetbrains/dokka/plugability/DokkaContext;)V + public fun annotations (Lorg/jetbrains/dokka/model/DProperty;)Ljava/util/Map; public fun annotations (Lorg/jetbrains/dokka/model/properties/WithExtraProperties;)Ljava/util/Map; public fun annotationsBlock (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;)V public fun annotationsBlockWithIgnored (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;Ljava/util/Set;Lorg/jetbrains/dokka/base/signatures/AtStrategy;Lkotlin/Pair;Ljava/lang/String;)V public fun annotationsInline (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;)V public fun annotationsInlineWithIgnored (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;Ljava/util/Set;Lorg/jetbrains/dokka/base/signatures/AtStrategy;Lkotlin/Pair;Ljava/lang/String;)V public fun modifiers (Lorg/jetbrains/dokka/model/properties/WithExtraProperties;)Ljava/util/Map; + public fun plus (Ljava/util/Map;Ljava/util/Map;)Ljava/util/Map; public fun signature (Lorg/jetbrains/dokka/model/Documentable;)Ljava/util/List; public fun stylesIfDeprecated (Lorg/jetbrains/dokka/model/properties/WithExtraProperties;Lorg/jetbrains/dokka/DokkaConfiguration$DokkaSourceSet;)Ljava/util/Set; public fun toSignatureString (Ljava/util/Collection;)Ljava/lang/String; @@ -27,12 +29,14 @@ public final class org/jetbrains/dokka/kotlinAsJava/signatures/JavaSignatureProv public final class org/jetbrains/dokka/kotlinAsJava/signatures/JavaSignatureUtils : org/jetbrains/dokka/base/signatures/JvmSignatureUtils { public static final field INSTANCE Lorg/jetbrains/dokka/kotlinAsJava/signatures/JavaSignatureUtils; + public fun annotations (Lorg/jetbrains/dokka/model/DProperty;)Ljava/util/Map; public fun annotations (Lorg/jetbrains/dokka/model/properties/WithExtraProperties;)Ljava/util/Map; public fun annotationsBlock (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;)V public fun annotationsBlockWithIgnored (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;Ljava/util/Set;Lorg/jetbrains/dokka/base/signatures/AtStrategy;Lkotlin/Pair;Ljava/lang/String;)V public fun annotationsInline (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;)V public fun annotationsInlineWithIgnored (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/AnnotationTarget;Ljava/util/Set;Lorg/jetbrains/dokka/base/signatures/AtStrategy;Lkotlin/Pair;Ljava/lang/String;)V public fun modifiers (Lorg/jetbrains/dokka/model/properties/WithExtraProperties;)Ljava/util/Map; + public fun plus (Ljava/util/Map;Ljava/util/Map;)Ljava/util/Map; public fun stylesIfDeprecated (Lorg/jetbrains/dokka/model/properties/WithExtraProperties;Lorg/jetbrains/dokka/DokkaConfiguration$DokkaSourceSet;)Ljava/util/Set; public fun toSignatureString (Ljava/util/Collection;)Ljava/lang/String; public fun toSignatureString (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/Annotations$Annotation;Lorg/jetbrains/dokka/base/signatures/AtStrategy;Lkotlin/Pair;Ljava/lang/String;)V |