Skip to content

Commit

Permalink
Replace empty string definitions with the constant equivalent
Browse files Browse the repository at this point in the history
  • Loading branch information
theEvilReaper committed Jan 16, 2024
1 parent f90b453 commit 4cc6944
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/main/kotlin/net/theevilreaper/dartpoet/code/CodeBlock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package net.theevilreaper.dartpoet.code

import net.theevilreaper.dartpoet.type.TypeName
import net.theevilreaper.dartpoet.type.asTypeName
import net.theevilreaper.dartpoet.util.EMPTY_STRING
import net.theevilreaper.dartpoet.util.escapeIfNecessary
import net.theevilreaper.dartpoet.util.isOneOf
import net.theevilreaper.dartpoet.util.toImmutableList
Expand Down Expand Up @@ -342,7 +343,7 @@ class CodeBlock private constructor(
unused += "%" + (i + 1)
}
}
val s = if (unused.size == 1) "" else "s"
val s = if (unused.size == 1) EMPTY_STRING else "s"
require(unused.isEmpty()) { "unused argument$s: ${unused.joinToString(", ")}" }
}
}
Expand Down Expand Up @@ -492,8 +493,8 @@ class CodeBlock private constructor(
@JvmOverloads
fun Collection<CodeBlock>.joinToCode(
separator: CharSequence = ", ",
prefix: CharSequence = "",
suffix: CharSequence = "",
prefix: CharSequence = EMPTY_STRING,
suffix: CharSequence = EMPTY_STRING,
): CodeBlock {
val blocks = toTypedArray()
val placeholders = Array(blocks.size) { "%L" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ class LineWrapper(
* Segments of the current line to be joined by spaces or wraps. Never empty, but contains a lone
* empty string if no data has been emitted since the last newline.
*/
private val segments = mutableListOf("")
private val segments = mutableListOf(EMPTY_STRING)

/** Number of indents in wraps. -1 if the current line has no wraps. */
private var indentLevel = -1

/** Optional prefix that will be prepended to wrapped lines. */
private var linePrefix = ""
private var linePrefix = EMPTY_STRING

/** @return whether there are pending segments for the current line. */
val hasPendingSegments get() = segments.size != 1 || segments[0].isNotEmpty()

/** Emit `s` replacing its spaces with line wraps as necessary. */
fun append(string: String, indentLevel: Int = -1, linePrefix: String = "") {
fun append(string: String, indentLevel: Int = -1, linePrefix: String = EMPTY_STRING) {
check(!closed) { "closed" }

var pos = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import net.theevilreaper.dartpoet.DartModifier
import net.theevilreaper.dartpoet.code.*
import net.theevilreaper.dartpoet.code.emitAnnotations
import net.theevilreaper.dartpoet.parameter.ParameterSpec
import net.theevilreaper.dartpoet.util.EMPTY_STRING

/**
* The ParameterWriter is used to write each parameter.
Expand All @@ -28,7 +29,7 @@ internal class ParameterWriter : Writeable<ParameterSpec>, InitializerAppender<P
if (spec.type != null) {
writer.emitCode("%T", spec.type)
}
val emitNullable = if (spec.isNullable) "" else if (spec.type != null) "·" else ""
val emitNullable = if (spec.isNullable) "" else if (spec.type != null) "·" else EMPTY_STRING
writer.emit(emitNullable)
writer.emit(spec.name)
writeInitBlock(spec, writer)
Expand Down

0 comments on commit 4cc6944

Please sign in to comment.