Skip to content

Commit

Permalink
Documentation update
Browse files Browse the repository at this point in the history
  • Loading branch information
theEvilReaper committed Dec 15, 2024
1 parent 728cb52 commit a1abd13
Showing 1 changed file with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import net.theevilreaper.dartpoet.util.toImmutableSet
import java.util.concurrent.Future

/**
* The [FunctionWriter] contains the logic to write a [FunctionSpec] to a [Appendable].
* It tries to recreate the structure of a method in the programming language Dart.
*
* **Note**: It is possible that the layout can contain a wrong format sometimes.
* @version 1.0.0
* @since 1.0.0
* @author theEvilReaper
Expand All @@ -41,10 +45,7 @@ internal class FunctionWriter : Writeable<FunctionSpec>, DocumentationAppender {
}

val writeableModifiers = spec.modifiers.filter { it != PRIVATE && it != PUBLIC }.toImmutableSet()
val postFix: String = when (writeableModifiers.isNotEmpty()) {
true -> SPACE
else -> EMPTY_STRING
}
val postFix: String = getPostFix { writeableModifiers.isNotEmpty() }
val modifierString = writeableModifiers.joinToString(separator = SPACE, postfix = postFix) { it.identifier }

writer.emit(modifierString)
Expand All @@ -71,6 +72,21 @@ internal class FunctionWriter : Writeable<FunctionSpec>, DocumentationAppender {
writeBody(spec, writer)
}

/**
* Returns the postfix [String] based on a given boolean predicate.
* If the predicate returns true it will return [SPACE] otherwise an [EMPTY_STRING].
* **Note** This method is a internal method which is only used in this class
* @param predicate the predicate which is used to determine the postfix
* @return the determined postfix [String]
*/
private inline fun getPostFix(crossinline predicate: () -> Boolean): String {
return when (predicate()) {
true -> SPACE
else -> EMPTY_STRING
}

}

/**
* Returns a [ParameterizedTypeName] if the spec is async otherwise null.
* This is required because the return value of an async function must be wrapped in a [Future].
Expand Down Expand Up @@ -128,6 +144,11 @@ internal class FunctionWriter : Writeable<FunctionSpec>, DocumentationAppender {
}
}

/**
* Writes the body of a given [FunctionSpec] to a [CodeWriter].
* @param spec the spec to write
* @param writer the writer to write the body
*/
private fun writeBody(spec: FunctionSpec, writer: CodeWriter) {
if (spec.body.isEmpty()) {
writer.emit(SEMICOLON)
Expand All @@ -153,6 +174,11 @@ internal class FunctionWriter : Writeable<FunctionSpec>, DocumentationAppender {
}
}

/**
* Triggers the method body write for a given [FunctionSpec].
* @param spec the spec to write
* @param writer the writer to write the body
*/
private fun writeMethodBody(spec: FunctionSpec, writer: CodeWriter) {
writer.emitCode(spec.body, ensureTrailingNewline = false)
}
Expand Down

0 comments on commit a1abd13

Please sign in to comment.