Skip to content

Commit

Permalink
Improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
theEvilReaper committed Jan 18, 2024
1 parent fb5b875 commit 566fd79
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package net.theevilreaper.dartpoet.code
fun interface Writeable<T> {

/**
* Emits the given [spec] to the [CodeWriter].
* Emits the content from the generic [T] object to a [CodeWriter] instance.
* @param spec the spec to emit
* @param writer the writer to write the spec to
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ class ParameterBuilder internal constructor(
this.specData.modifiers += modifier()
}

/**
* Add a given array of [DartModifier] to the builder instance.
* @param modifiers the array to add
* @return the given instance from the builder
*/
override fun modifiers(vararg modifiers: DartModifier) = apply {
this.specData.modifiers += modifiers
}
Expand Down
12 changes: 9 additions & 3 deletions src/main/kotlin/net/theevilreaper/dartpoet/type/ClassName.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ open class ClassName(
}
}

/**
* Converts a generic [KClass] instance to a [ClassName] instance.
* @return the created [ClassName] instance
*/
@JvmName("get")
fun KClass<*>.asClassName(): ClassName {
val simpleName = this.simpleName!!
Expand All @@ -58,15 +62,17 @@ fun KClass<*>.asClassName(): ClassName {
return ClassName(Void::class.simpleName!!.replaceFirstChar { it.lowercase() })
}
return ClassName(simpleName)

}

/**
* Converts a generic [Class] instance to a [ClassName] instance.
* @return the created [ClassName] instance
* @throws IllegalArgumentException if the class is a primitive type, a void type or an array
*/
@JvmName("get")
fun Class<*>.asClassName(): ClassName {
require(!isPrimitive) { "A primitive type can't be represented over a ClassName!" }
require(Void.TYPE != this) { "A void type can't be represented over a ClassName!" }
require(!isArray) { "An array can't be represented over a ClassName!" }
return ClassName(this.simpleName)
}


0 comments on commit 566fd79

Please sign in to comment.