Package com.squareup.kotlinpoet

Types

Link copied to clipboard
class AnnotationSpec : Taggable

A generated annotation on a declaration.

Link copied to clipboard
class ClassName : TypeName, Comparable<ClassName>

A fully-qualified class name for top-level and member classes.

Link copied to clipboard
class CodeBlock

A fragment of a .kt file, potentially containing declarations, statements, and documentation. Code blocks are not necessarily well-formed Kotlin code, and are not validated. This class assumes kotlinc will check correctness later!

Link copied to clipboard
interface ContextReceivable

A KotlinPoet spec type that can have a context receiver.

Link copied to clipboard
annotation class DelicateKotlinPoetApi(val message: String)

Marks declarations in the KotlinPoet API that are delicate — they have limited use-case and shall be used with care in general code. Any use of a delicate declaration has to be carefully reviewed to make sure it is properly used and does not create problems like lossy Java -> Kotlin type parsing. Carefully read documentation and message of any declaration marked as DelicateKotlinPoetApi.

Link copied to clipboard
object Dynamic : TypeName
Link copied to clipboard

Indicates that a given API is experimental and subject to change.

Link copied to clipboard
class FileSpec : Taggable

A Kotlin file containing top level objects like classes, objects, functions, properties, and type aliases.

Link copied to clipboard
class FunSpec : Taggable, OriginatingElementsHolder, ContextReceivable

A generated function declaration.

Link copied to clipboard
data class Import : Comparable<Import>
Link copied to clipboard
enum KModifier : Enum<KModifier>
Link copied to clipboard
enum KOperator : Enum<KOperator>
Link copied to clipboard
class LambdaTypeName : TypeName
Link copied to clipboard
data class MemberName

Represents the name of a member (such as a function or a property).

Link copied to clipboard
class NameAllocator

Assigns Kotlin identifier names to avoid collisions, keywords, and invalid characters. To use, first create an instance and allocate all of the names that you need. Typically this is a mix of user-supplied names and constants:

Link copied to clipboard
interface OriginatingElementsHolder

A type that can have originating elements.

Link copied to clipboard
class ParameterizedTypeName : TypeName
Link copied to clipboard
class ParameterSpec : Taggable

A generated parameter declaration.

Link copied to clipboard

A generated property declaration.

Link copied to clipboard
interface Taggable

A type that can be tagged with extra metadata of the user's choice.

Link copied to clipboard
class TypeAliasSpec : Taggable

A generated typealias declaration

Link copied to clipboard
sealed class TypeName : Taggable

Any type in Kotlin's type system. This class identifies simple types like Int and String, nullable types like Int?, composite types like Array<String> and Set<String>, and unassignable types like Unit.

Link copied to clipboard
class TypeSpec : Taggable, OriginatingElementsHolder, ContextReceivable

A generated class, interface, or enum declaration.

Link copied to clipboard
class TypeVariableName : TypeName
Link copied to clipboard
class WildcardTypeName : TypeName

Functions

Link copied to clipboard
@DelicateKotlinPoetApi(message = "Java reflection APIs don't give complete information on Kotlin types. Consider using the kotlinpoet-metadata APIs instead.")
@JvmName(name = "get")
fun Class<*>.asClassName(): ClassName
@JvmName(name = "get")
fun KClass<*>.asClassName(): ClassName

@DelicateKotlinPoetApi(message = "Element APIs don't give complete information on Kotlin types. Consider using the kotlinpoet-metadata APIs instead.")
@JvmName(name = "get")
fun TypeElement.asClassName(): ClassName

Returns the class name for element.

Link copied to clipboard
@DelicateKotlinPoetApi(message = "Java reflection APIs don't give complete information on Kotlin types. Consider using the kotlinpoet-metadata APIs instead.")
@JvmName(name = "get")
fun ParameterizedType.asParameterizedTypeName(): ParameterizedTypeName

Returns a parameterized type equivalent to type.

Link copied to clipboard
@JvmName(name = "get")
fun Type.asTypeName(): TypeName

Returns a TypeName equivalent to this Type.

@DelicateKotlinPoetApi(message = "Mirror APIs don't give complete information on Kotlin types. Consider using the kotlinpoet-metadata APIs instead.")
@JvmName(name = "get")
fun TypeMirror.asTypeName(): TypeName

Returns a TypeName equivalent to this TypeMirror.

@JvmName(name = "get")
fun KClass<*>.asTypeName(): ClassName

Returns a TypeName equivalent to this KClass.

fun KType.asTypeName(): TypeName

Returns a TypeName equivalent to the given Kotlin KType using reflection, maybe using kotlin-reflect if required.

Link copied to clipboard
@DelicateKotlinPoetApi(message = "Element APIs don't give complete information on Kotlin types. Consider using the kotlinpoet-metadata APIs instead.")
@JvmName(name = "get")
fun TypeParameterElement.asTypeVariableName(): TypeVariableName

Returns type variable equivalent to element.

@DelicateKotlinPoetApi(message = "Java reflection APIs don't give complete information on Kotlin types. Consider using the kotlinpoet-metadata APIs instead.")
@JvmName(name = "get")
fun TypeVariable.asTypeVariableName(): TypeVariableName

Returns type variable equivalent to mirror.

fun KTypeParameter.asTypeVariableName(): TypeVariableName
Link copied to clipboard
@DelicateKotlinPoetApi(message = "Java reflection APIs don't give complete information on Kotlin types. Consider using the kotlinpoet-metadata APIs instead.")
@JvmName(name = "get")
fun WildcardType.asWildcardTypeName(): TypeName
@DelicateKotlinPoetApi(message = "Mirror APIs don't give complete information on Kotlin types. Consider using the kotlinpoet-metadata APIs instead.")
@JvmName(name = "get")
fun WildcardType.asWildcardTypeName(): TypeName
Link copied to clipboard
inline fun buildCodeBlock(builderAction: CodeBlock.Builder.() -> Unit): CodeBlock

Builds new CodeBlock by populating newly created CodeBlock.Builder using provided builderAction and then converting it to CodeBlock.

Link copied to clipboard
fun Collection<CodeBlock>.joinToCode(    separator: CharSequence = ", ",     prefix: CharSequence = "",     suffix: CharSequence = ""): CodeBlock
Link copied to clipboard
inline fun <T : Any> Taggable.tag(): T?

Returns the tag attached with T as a key, or null if no tag is attached with that key.

inline fun <T : Any> AnnotationSpec.Builder.tag(tag: T?): AnnotationSpec.Builder
inline fun <T : Any> FileSpec.Builder.tag(tag: T?): FileSpec.Builder
inline fun <T : Any> FunSpec.Builder.tag(tag: T?): FunSpec.Builder
inline fun <T : Any> ParameterSpec.Builder.tag(tag: T?): ParameterSpec.Builder
inline fun <T : Any> PropertySpec.Builder.tag(tag: T?): PropertySpec.Builder
inline fun <T : Any> TypeAliasSpec.Builder.tag(tag: T?): TypeAliasSpec.Builder
inline fun <T : Any> TypeSpec.Builder.tag(tag: T?): TypeSpec.Builder

Attaches tag to the request using T as a key. Tags can be read from a request using Taggable.tag. Use null to remove any existing tag assigned for T.

Link copied to clipboard
inline fun <T> typeNameOf(): TypeName

Returns a TypeName equivalent of the reified type parameter T using reflection, maybe using kotlin-reflect if required.

Link copied to clipboard
inline fun CodeBlock.Builder.withIndent(builderAction: CodeBlock.Builder.() -> Unit): CodeBlock.Builder

Calls CodeBlock.Builder.indent then executes the provided builderAction on the CodeBlock.Builder and then executes CodeBlock.Builder.unindent before returning the original CodeBlock.Builder.

Properties

Link copied to clipboard
val ANNOTATION: ClassName
Link copied to clipboard
val ANY: ClassName
Link copied to clipboard
val ARRAY: ClassName
Link copied to clipboard
val BOOLEAN: ClassName
Link copied to clipboard
val BOOLEAN_ARRAY: ClassName
Link copied to clipboard
val BYTE: ClassName
Link copied to clipboard
val BYTE_ARRAY: ClassName
Link copied to clipboard
val CHAR: ClassName
Link copied to clipboard
val CHAR_ARRAY: ClassName
Link copied to clipboard
val CHAR_SEQUENCE: ClassName
Link copied to clipboard
val COLLECTION: ClassName
Link copied to clipboard
val COMPARABLE: ClassName
Link copied to clipboard
val DOUBLE: ClassName
Link copied to clipboard
val DOUBLE_ARRAY: ClassName
Link copied to clipboard
val DYNAMIC: Dynamic

Dynamic is a singleton object type, so this is a shorthand for it in Java.

Link copied to clipboard
val ENUM: ClassName
Link copied to clipboard
val FLOAT: ClassName
Link copied to clipboard
val FLOAT_ARRAY: ClassName
Link copied to clipboard
val INT: ClassName
Link copied to clipboard
val INT_ARRAY: ClassName
Link copied to clipboard
val ITERABLE: ClassName
Link copied to clipboard
val LIST: ClassName
Link copied to clipboard
val LONG: ClassName
Link copied to clipboard
val LONG_ARRAY: ClassName
Link copied to clipboard
val MAP: ClassName
Link copied to clipboard
val MAP_ENTRY: ClassName
Link copied to clipboard
val MUTABLE_COLLECTION: ClassName
Link copied to clipboard
val MUTABLE_ITERABLE: ClassName
Link copied to clipboard
val MUTABLE_LIST: ClassName
Link copied to clipboard
val MUTABLE_MAP: ClassName
Link copied to clipboard
val MUTABLE_MAP_ENTRY: ClassName
Link copied to clipboard
val MUTABLE_SET: ClassName
Link copied to clipboard
val NOTHING: ClassName
Link copied to clipboard
val NUMBER: ClassName
Link copied to clipboard
val SET: ClassName
Link copied to clipboard
val SHORT: ClassName
Link copied to clipboard
val SHORT_ARRAY: ClassName
Link copied to clipboard
val STAR: WildcardTypeName

The wildcard type * which is shorthand for out Any?.

Link copied to clipboard
val STRING: ClassName
Link copied to clipboard
val THROWABLE: ClassName
Link copied to clipboard
val U_BYTE: ClassName
Link copied to clipboard
val U_BYTE_ARRAY: ClassName
Link copied to clipboard
val U_INT: ClassName
Link copied to clipboard
val U_INT_ARRAY: ClassName
Link copied to clipboard
val U_LONG: ClassName
Link copied to clipboard
val U_LONG_ARRAY: ClassName
Link copied to clipboard
val U_SHORT: ClassName
Link copied to clipboard
val U_SHORT_ARRAY: ClassName
Link copied to clipboard
val UNIT: ClassName