Skip to content

Commit

Permalink
Fix some typos
Browse files Browse the repository at this point in the history
  • Loading branch information
theEvilReaper committed Jan 10, 2024
1 parent 57238fe commit 9c6e067
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal class ConstantPropertyWriter : Writeable<ConstantPropertySpec>, Initial
writer.emitCode("%T·", spec.typeName)
}

writer.emitCode("%L", ensureVariableNameWithPrivateModifier(spec.isPrivat, spec.name))
writer.emitCode("%L", ensureVariableNameWithPrivateModifier(spec.isPrivate, spec.name))
writeInitBlock(spec.initializer.build(), writer)
writer.emit(SEMICOLON)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package net.theevilreaper.dartpoet.property.consts

import net.theevilreaper.dartpoet.DartFileBuilder
import net.theevilreaper.dartpoet.DartModifier
import net.theevilreaper.dartpoet.code.CodeBlock
import net.theevilreaper.dartpoet.property.PropertySpec
import net.theevilreaper.dartpoet.type.TypeName

/**
* The [ConstantPropertyBuilder] can be used to construct new [ConstantPropertySpec] object reference which can be set
* into a [DartFileBuilder].
* into a [ConstantPropertySpec].
* @author theEvilReaper
* @since 1.0.0
*/
Expand All @@ -18,7 +17,7 @@ class ConstantPropertyBuilder internal constructor(
val modifiers: Set<DartModifier>
) {
internal var initializer: CodeBlock.Builder = CodeBlock.Builder()
internal var isPrivat: Boolean = false
internal var isPrivate: Boolean = false

/**
* Apply a given format which contains the parts for the init block of the [PropertySpec].
Expand All @@ -37,8 +36,14 @@ class ConstantPropertyBuilder internal constructor(
this.initializer = codeFragment
}

fun asPrivat(boolean: Boolean) = apply {
this.isPrivat = boolean
/**
* Indicates if the property should be private.
* The option is only allowed when to property is no file level constant property.
* @param boolean True for a private property otherwise false
* @return the current [ConstantPropertyBuilder] instance
*/
fun private(boolean: Boolean) = apply {
this.isPrivate = boolean
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ class ConstantPropertySpec(
internal val name = builder.name
internal val typeName = builder.typeName
internal val initializer = builder.initializer
internal val isPrivat = builder.isPrivat
internal val isPrivate = builder.isPrivate
internal val modifiers = builder.modifiers.toImmutableSet()

init {
require(name.trim().isNotEmpty()) { "The name of a file constant can't be empty" }
require(initializer.isNotEmpty()) { "The initializer can't be empty" }

if (this.modifiers.size == 1 && this.modifiers.first() == DartModifier.CONST && isPrivat) {
if (this.modifiers.size == 1 && this.modifiers.first() == DartModifier.CONST && isPrivate) {
throw IllegalArgumentException("A file constant can't be private")
}
}
Expand All @@ -61,10 +61,13 @@ class ConstantPropertySpec(
fun toBuilder(): ConstantPropertyBuilder {
val builder = ConstantPropertyBuilder(name, typeName, modifiers)
builder.initializer = initializer
builder.isPrivat = isPrivat
builder.isPrivate = isPrivate
return builder
}

/**
* The companion object contains some helper methods to create a new instance from the [ConstantPropertyBuilder].
*/
companion object {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class ConstantPropertyWriterTest {
{
ConstantPropertySpec.classConst("test", Int::class)
.initWith("%L", "1")
.asPrivat(true)
.private(true)
.build()
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ConstantPropertySpecTest {
),
Arguments.of(
"A file constant can't be private",
{ ConstantPropertySpec.fileConst("test").initWith("%S", "test").asPrivat(true).build() }
{ ConstantPropertySpec.fileConst("test").initWith("%S", "test").private(true).build() }
)
)
}
Expand All @@ -48,6 +48,6 @@ class ConstantPropertySpecTest {
assertEquals(builder.name, newBuilder.name)
assertEquals(builder.typeName, newBuilder.typeName)
assertEquals(builder.initializer, newBuilder.initializer)
assertFalse { newBuilder.isPrivat }
assertFalse { newBuilder.isPrivate }
}
}

0 comments on commit 9c6e067

Please sign in to comment.