From fb5b875fe3f9895675bc19ceaaec0577ed0d440f Mon Sep 17 00:00:00 2001 From: theEvilReaper Date: Tue, 16 Jan 2024 22:22:17 +0100 Subject: [PATCH] Update documentation --- .../dartpoet/clazz/ClassBuilder.kt | 8 +++++ .../theevilreaper/dartpoet/clazz/ClassSpec.kt | 1 + .../dartpoet/code/writer/AnnotationWriter.kt | 29 ++++++++++++++++--- .../code/writer/ConstantPropertyWriter.kt | 14 ++++++++- .../dartpoet/code/writer/PropertyWriter.kt | 3 +- 5 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/net/theevilreaper/dartpoet/clazz/ClassBuilder.kt b/src/main/kotlin/net/theevilreaper/dartpoet/clazz/ClassBuilder.kt index 4b150169..78fe8b41 100644 --- a/src/main/kotlin/net/theevilreaper/dartpoet/clazz/ClassBuilder.kt +++ b/src/main/kotlin/net/theevilreaper/dartpoet/clazz/ClassBuilder.kt @@ -59,10 +59,18 @@ class ClassBuilder internal constructor( this.constantStack += constants } + /** + * Add a [TypeDefSpec] to the spec. + * @param typeDefSpec the typedef to add + */ fun typedef(typeDefSpec: TypeDefSpec) = apply { this.typedefs += typeDefSpec } + /** + * Add an array of [TypeDefSpec] to the spec. + * @param typeDefSpec the typedefs to add + */ fun typedef(vararg typeDefSpec: TypeDefSpec) = apply { this.typedefs += typeDefSpec } diff --git a/src/main/kotlin/net/theevilreaper/dartpoet/clazz/ClassSpec.kt b/src/main/kotlin/net/theevilreaper/dartpoet/clazz/ClassSpec.kt index 251eb022..87848501 100644 --- a/src/main/kotlin/net/theevilreaper/dartpoet/clazz/ClassSpec.kt +++ b/src/main/kotlin/net/theevilreaper/dartpoet/clazz/ClassSpec.kt @@ -11,6 +11,7 @@ import net.theevilreaper.dartpoet.util.toImmutableSet * A [ClassBuilder] describes the actual content of the class. * The content includes functions, typedefs, const values etc. * Partly some things are also only allowed to be set on certain classes. + * @param builder the [ClassBuilder] instance to retrieve data from it * @since 1.0.0 * @author theEvilReaper */ diff --git a/src/main/kotlin/net/theevilreaper/dartpoet/code/writer/AnnotationWriter.kt b/src/main/kotlin/net/theevilreaper/dartpoet/code/writer/AnnotationWriter.kt index c89b3183..59350b4e 100644 --- a/src/main/kotlin/net/theevilreaper/dartpoet/code/writer/AnnotationWriter.kt +++ b/src/main/kotlin/net/theevilreaper/dartpoet/code/writer/AnnotationWriter.kt @@ -7,6 +7,8 @@ import net.theevilreaper.dartpoet.code.joinToCode import net.theevilreaper.dartpoet.util.ANNOTATION_CHAR import net.theevilreaper.dartpoet.util.EMPTY_STRING import net.theevilreaper.dartpoet.util.NEW_LINE +import net.theevilreaper.dartpoet.util.ROUND_CLOSE +import net.theevilreaper.dartpoet.util.ROUND_OPEN import net.theevilreaper.dartpoet.util.toImmutableList /** @@ -14,8 +16,14 @@ import net.theevilreaper.dartpoet.util.toImmutableList * @since 1.0.0 * @author theEvilReaper */ -class AnnotationWriter { +internal class AnnotationWriter { + /** + * Writes the data which are stored in a [AnnotationSpec] to a given instance from a [CodeWriter]. + * @param spec the spec to write + * @param writer the writer to write the spec to + * @param inline if the spec should be written inline + */ fun emit(spec: AnnotationSpec, writer: CodeWriter, inline: Boolean) { writer.emit(ANNOTATION_CHAR) writer.emitCode("%T", spec.typeName) @@ -26,17 +34,30 @@ class AnnotationWriter { val memberSeparator = if (inline) ", " else ",\n" val memberSuffix = if (!inline && spec.content.size > 1) "," else EMPTY_STRING - writer.emit("(") + writer.emit(ROUND_OPEN) if (spec.hasMultipleContentParts) writer.emit(whitespace).indent() writer.emitCode( codeBlock = mapCodeBlocks(spec, inline, memberSeparator, memberSuffix), isConstantContext = true, ) if (spec.hasMultipleContentParts) writer.unindent().emit(whitespace) - writer.emit(")") + writer.emit(ROUND_CLOSE) } - private fun mapCodeBlocks(spec: AnnotationSpec, inline: Boolean, memberSeparator: String, memberSuffix: String): CodeBlock { + /** + * Maps the content from an [AnnotationSpec] into a [CodeBlock] reference. + * @param spec the spec to map + * @param inline if the spec should be written inline + * @param memberSeparator the separator for the members + * @param memberSuffix the suffix for the members + * @return the created [CodeBlock] reference + */ + private fun mapCodeBlocks( + spec: AnnotationSpec, + inline: Boolean, + memberSeparator: String, + memberSuffix: String + ): CodeBlock { return spec.content.toImmutableList() .map { if (inline) it.replaceAll("[⇥|⇤]", EMPTY_STRING) else it } .joinToCode(separator = memberSeparator, suffix = memberSuffix) diff --git a/src/main/kotlin/net/theevilreaper/dartpoet/code/writer/ConstantPropertyWriter.kt b/src/main/kotlin/net/theevilreaper/dartpoet/code/writer/ConstantPropertyWriter.kt index cb40ac5e..d1decaa0 100644 --- a/src/main/kotlin/net/theevilreaper/dartpoet/code/writer/ConstantPropertyWriter.kt +++ b/src/main/kotlin/net/theevilreaper/dartpoet/code/writer/ConstantPropertyWriter.kt @@ -8,8 +8,20 @@ import net.theevilreaper.dartpoet.property.consts.ConstantPropertySpec import net.theevilreaper.dartpoet.util.SEMICOLON import net.theevilreaper.dartpoet.util.SPACE -internal class ConstantPropertyWriter : Writeable, InitializerAppender, VariableAppender { +/** + * The [ConstantPropertyWriter] is responsible for writing the data of the [ConstantPropertySpec] to a [CodeWriter]. + * @since 1.0.0 + * @author theEvilReaper + */ +internal class ConstantPropertyWriter : Writeable, InitializerAppender, + VariableAppender { + /** + * Writes the data from a provided [ConstantPropertySpec] to the given [CodeWriter] instance. + * + * @param spec the ConstantPropertySpec which should be written + * @param writer the instance from the [CodeWriter] to append the data + **/ override fun write(spec: ConstantPropertySpec, writer: CodeWriter) { val modifiersAsString = spec.modifiers.joinToString(separator = SPACE, postfix = SPACE) { it.identifier } diff --git a/src/main/kotlin/net/theevilreaper/dartpoet/code/writer/PropertyWriter.kt b/src/main/kotlin/net/theevilreaper/dartpoet/code/writer/PropertyWriter.kt index a04ee45a..f4aa341c 100644 --- a/src/main/kotlin/net/theevilreaper/dartpoet/code/writer/PropertyWriter.kt +++ b/src/main/kotlin/net/theevilreaper/dartpoet/code/writer/PropertyWriter.kt @@ -13,7 +13,8 @@ import net.theevilreaper.dartpoet.util.SPACE * @author theEvilReaper * @since 1.0.0 */ -internal class PropertyWriter : Writeable, VariableAppender, DocumentationAppender, InitializerAppender { +internal class PropertyWriter : Writeable, VariableAppender, DocumentationAppender, + InitializerAppender { /** * Writes the given [PropertySpec] into the [CodeWriter].