Package com.squareup.kotlinpoet.ksp

Types

KotlinPoetKspPreview
Link copied to clipboard
annotation class KotlinPoetKspPreview

Indicates that a given API is part of the experimental KotlinPoet KSP support. This exists because KotlinPoet support of KSP is in preview and subject to change.

OriginatingKSFiles
Link copied to clipboard
interface OriginatingKSFiles

A simple holder class for containing originating KSFiles, which are used by KSP to inform its incremental processing.

TypeParameterResolver
Link copied to clipboard
interface TypeParameterResolver

A resolver for enclosing declarations' type parameters. Parent declarations can be anything with generics that child nodes declare as defined by KSType.arguments.

Functions

addOriginatingKSFile
Link copied to clipboard
fun FunSpec.Builder.addOriginatingKSFile(ksFile: KSFile): FunSpec.Builder
fun PropertySpec.Builder.addOriginatingKSFile(ksFile: KSFile): PropertySpec.Builder
fun TypeAliasSpec.Builder.addOriginatingKSFile(ksFile: KSFile): TypeAliasSpec.Builder
fun TypeSpec.Builder.addOriginatingKSFile(ksFile: KSFile): TypeSpec.Builder

Adds the given ksFile to this builder's tags for use with originatingKSFiles.

kspDependencies
Link copied to clipboard
fun FileSpec.kspDependencies(aggregating: Boolean, originatingKSFiles: Iterable<KSFile> = originatingKSFiles()): Dependencies

Returns a KSP Dependencies component of this FileSpec with the given originatingKSFiles, intended to be used in tandem with writeTo.

originatingKSFiles
Link copied to clipboard
fun FileSpec.originatingKSFiles(): List<KSFile>

Returns the list of all files added to the contained TypeSpecs, PropertySpecs, FunSpecs, or TypeAliasSpecs contained in this spec.

fun FunSpec.originatingKSFiles(): List<KSFile>
fun PropertySpec.originatingKSFiles(): List<KSFile>
fun TypeAliasSpec.originatingKSFiles(): List<KSFile>
fun TypeSpec.originatingKSFiles(): List<KSFile>

Returns this spec's originating KSFiles for use with incremental processing.

toClassName
Link copied to clipboard
fun KSClassDeclaration.toClassName(): ClassName

Returns the ClassName representation of this KSClassDeclaration.

fun KSType.toClassName(): ClassName

Returns the ClassName representation of this KSType IFF it's a KSClassDeclaration.

toKModifier
Link copied to clipboard
fun Modifier.toKModifier(): KModifier?

Returns the KModifier representation of this Modifier or null if this is a Java-only modifier (i.e. prefixed with JAVA_), which do not have obvious KModifier analogues.

fun Visibility.toKModifier(): KModifier?

Returns the KModifier representation of this visibility or null if this is JAVA_PACKAGE or LOCAL (which do not have obvious KModifier alternatives).

toTypeName
Link copied to clipboard
fun KSType.toTypeName(typeParamResolver: TypeParameterResolver = TypeParameterResolver.EMPTY): TypeName

Returns the TypeName representation of this KSType.

fun KSTypeArgument.toTypeName(typeParamResolver: TypeParameterResolver = TypeParameterResolver.EMPTY): TypeName

Returns a TypeName representation of this KSTypeArgument.

fun KSTypeReference.toTypeName(typeParamResolver: TypeParameterResolver = TypeParameterResolver.EMPTY): TypeName

Returns a TypeName representation of this KSTypeReference.

toTypeParameterResolver
Link copied to clipboard
fun List<KSTypeParameter>.toTypeParameterResolver(parent: TypeParameterResolver? = null, sourceTypeHint: String = "<unknown>"): TypeParameterResolver

Returns a TypeParameterResolver for this list of KSTypeParameters for use with enclosed declarations.

toTypeVariableName
Link copied to clipboard
fun KSTypeParameter.toTypeVariableName(typeParamResolver: TypeParameterResolver = TypeParameterResolver.EMPTY): TypeVariableName

Returns a TypeVariableName representation of this KSTypeParameter.

writeTo
Link copied to clipboard
fun FileSpec.writeTo(codeGenerator: CodeGenerator, dependencies: Dependencies)

Writes this FileSpec to a given codeGenerator with the given dependencies.

fun FileSpec.writeTo(codeGenerator: CodeGenerator, aggregating: Boolean, originatingKSFiles: Iterable<KSFile> = originatingKSFiles())

Writes this FileSpec to a given codeGenerator with the given originatingKSFiles.