From 76d6d16533968792d7d7143f6db169c5f1d62678 Mon Sep 17 00:00:00 2001 From: steank Date: Sat, 18 Feb 2023 15:00:02 -0800 Subject: [PATCH] interpret Group annotations present on the enclosing package of elements, to avoid duplicating annotations + bump versions --- autodoc/build.gradle.kts | 2 +- .../steanky/element/gradle/plugin/autodoc/AutodocTask.kt | 9 ++++++--- .../src/main/kotlin/element.java-conventions.gradle.kts | 2 +- .../steanky/element/core/annotation/document/Group.java | 5 ++++- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/autodoc/build.gradle.kts b/autodoc/build.gradle.kts index c3cf1d2..6fada09 100644 --- a/autodoc/build.gradle.kts +++ b/autodoc/build.gradle.kts @@ -8,7 +8,7 @@ plugins { } group = "com.github.steanky" -version = "0.1.1" +version = "0.1.2" val functionalTest: SourceSet by sourceSets.creating diff --git a/autodoc/src/main/kotlin/com/github/steanky/element/gradle/plugin/autodoc/AutodocTask.kt b/autodoc/src/main/kotlin/com/github/steanky/element/gradle/plugin/autodoc/AutodocTask.kt index 6f13571..f792578 100644 --- a/autodoc/src/main/kotlin/com/github/steanky/element/gradle/plugin/autodoc/AutodocTask.kt +++ b/autodoc/src/main/kotlin/com/github/steanky/element/gradle/plugin/autodoc/AutodocTask.kt @@ -173,6 +173,10 @@ abstract class AutodocTask : SourceTask() { return group.value } + super.processingEnv.elementUtils.getPackageOf(this)?.getAnnotation(Group::class.java)?.let { group -> + return group.value + } + logger.error("Element $this missing Group annotation") return "" } @@ -410,10 +414,9 @@ abstract class AutodocTask : SourceTask() { return "any" } - collectionType("set", typeUtils, componentType, setType) ?: + return collectionType("set", typeUtils, componentType, setType) ?: collectionType("list", typeUtils, componentType, collectionType) ?: - mapType(typeUtils, componentType) ?: - return componentType.asElement().simpleName.toString() + mapType(typeUtils, componentType) ?: componentType.asElement().simpleName.toString() } TypeKind.TYPEVAR -> { componentType as TypeVariable diff --git a/buildSrc/src/main/kotlin/element.java-conventions.gradle.kts b/buildSrc/src/main/kotlin/element.java-conventions.gradle.kts index 0849ed2..369a9f0 100644 --- a/buildSrc/src/main/kotlin/element.java-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/element.java-conventions.gradle.kts @@ -3,7 +3,7 @@ plugins { } group = "com.github.steanky" -version = "0.14.0" +version = "0.14.1" java { toolchain.languageVersion.set(JavaLanguageVersion.of(17)) diff --git a/core/src/main/java/com/github/steanky/element/core/annotation/document/Group.java b/core/src/main/java/com/github/steanky/element/core/annotation/document/Group.java index 843e84f..cdbed67 100644 --- a/core/src/main/java/com/github/steanky/element/core/annotation/document/Group.java +++ b/core/src/main/java/com/github/steanky/element/core/annotation/document/Group.java @@ -7,10 +7,13 @@ /** * When applied to an element type, specifies a group string. This is a general category used for documentation * purposes. + *

+ * If applied to a package, the group name will be applied to all element objects present in the package, so long as + * they don't specify their own Group annotation. */ @Documented @Retention(RetentionPolicy.SOURCE) -@Target(ElementType.TYPE) +@Target({ElementType.TYPE, ElementType.PACKAGE}) public @interface Group { /** * The group string.