Releases: square/kotlinpoet
2.3.0
Thanks to @haruue, @hfhbd, @yz4230, @mina-jaff, @BoD, @RaoPrashanth for contributing to this release.
- New: Kotlin 2.3.20.
- New: KSP 2.3.6.
- New: Support for defining type aliases inside other types. (#2167)
- New: Add
TypeName.annotated()convenience API for adding annotations to types. (#2281) - New: Add
FileSpec.addImport(MemberName)to explicitly import a member. (#2198) - New: Add
NameAllocator.containsto check if a given tag is already allocated. (#2160) - New:
:interop:javapoetmodule has been discontinued and is not published starting with this release. (#2292) - New: In-development snapshots are now published to the Central Portal Snapshots repository at https://central.sonatype.com/repository/maven-snapshots/. (#2135)
- Fix: Annotation array parameters with annotation elements now correctly handled. (#2142)
- Fix:
KType.asTypeNamenow correctly handles recursively bound generics (e.g.T : Comparable<T>). (#2162) - Fix: Don't convert multi-statement function to expression body. (#2163)
- Fix:
FunSpec.beginControlFlownow accepts nullable arguments for consistency withCodeBlock.beginControlFlow. (#2174) - Fix: Ignore illegal characters inside escaped identifiers. (#2204)
- Fix:
emitNullablecorrectly when deferring type inCodeWriter. (#2217) - Fix: Escape
/*and*/when emitting Kdoc. (#2258) - Fix: Generate imports for extension members used via
%Min KDocs. (#2266)
2.2.0
2.1.0
Thanks to @ForteScarlet, @TrevorSStone, @RaoPrashanth, @damianw, @ansehoon1999, @TheMrMilchmann for contributing to this release.
- New: Kotlin 2.1.10.
- New: KSP 2.1.10-1.0.30.
- Fix: Support delegates on anonymous classes. (#2034)
- Fix: Prevent aliased imports from colliding with existing imports. (#2052)
- Fix:
TypeName.MUTABLE_MAP_ENTRYnow correctly uses theMutableEntrynested class name. (#2061) - Fix: Use the same aliased import for both the nullable and non-nullable versions of a type. (#2068)
- Fix: Allow zero methods in a functional interface if it has a superinterface. (#2075)
2.0.0
Thanks to @brokenhappy, @tajobe, @niyajali, @ForteScarlet for contributing to this release.
This release is source- and binary-compatible with KotlinPoet 1.x.
The most important behavior change in this release is that spaces in generated code don't wrap by default anymore.
KotlinPoet 1.x used to replace space characters with newline characters whenever a given line of code exceeded the length limit. This usually led to better code formatting, but could also lead to compilation errors in generated code. Non-breaking spaces could be marked by the Β· character, but the discoverability of this feature wasn't great.
KotlinPoet 2.0 does not wrap spaces, even if the line of code they occur in exceeds the length limit. The newly introduced β’ character can be used to mark spaces that are safe to wrap, which can improve code formatting. The Β· character has been preserved for compatibility, but its behavior is now equivalent to a regular space character.
- New: Kotlin 2.0.10.
- New: Spaces don't break by default.
- New: New
β’placeholder representing a space that is safe to wrap. - New: Add
KSTypeAlias.toClassName(). (#1956) - New: Add
KSType.toClassNameOrNull(). (#1956) - Fix: Enum classes that only have an init block now also generate the required semicolon. (#1953)
- Fix: Preserve typealiases in
KSAnnotation.toAnnotationSpec(). (#1956) - Fix: Preserve nullability in
KSType.toClassName(). (#1956)
1.18.1
Thanks to @mitasov-ra for contributing to this release.
// before, doesn't compile due to KT-18706
import com.example.one.`$Foo` as `One$Foo`
import com.example.two.`$Foo` as `Two$Foo`
// now, compiles
import com.example.one.`$Foo` as One__Foo
import com.example.two.`$Foo` as Two__Foo1.18.0
Thanks to @DanielGronau for contributing to this release.
- New: Kotlin 2.0.0.
- New: KSP 2.0.0-1.0.22.
- New: Promote
kotlinpoet-metadataout of preview to stable. - New: Migrate
kotlinpoet-metadatato stableorg.jetbrains.kotlin:kotlin-metadata-jvmartifact for Metadata parsing. - New: Make enum entry references in
KSAnnotation.toAnnotationSpec()andKSClassDeclaration.toClassName()more robust. - Fix: Don't expand typealiases of function types to
LambdaTypeNames inKSTypeReference.toTypeName(). - Fix: Avoid rounding small double and float values in
%Ltranslation (#1927). - Fix: Fix typealias type argument resolution in KSP2 (#1929).
1.17.0
Thanks to @jisungbin, @hfhbd, @evant, @sgjesse, @sebek64 for contributing to this release.
- Change: kotlinx-metadata 0.9.0. Note that the
KotlinClassMetadata.readis deprecated in 0.9.0 and replaced withreadStrict(#1830).- Note: we now also provide
lenientparameters to map to the underlyingreadStrict()andreadLenient()calls (#1766). - We have also removed various
Class/TypeElement/Metadata-to-KmClassAPIs from the public API, as these are trivial to write now with kotlinx-metadata's newer APIs and allows us to focus the API surface area of this artifact better (#1891).
- Note: we now also provide
- New: Supertype list wraps to one-per-line if the primary constructor spans multiple lines (#1866).
- New: Extract
MemberSpecHolderinterface for constructs that can holdPropertySpecs andFunSpecs and their builders (#1877). - New:
joinToCodevariant which operates on any type, but requires a transform lambda to convert each element into aCodeBlock(#1874). - New: Support annotation type arguments in
KSAnnotation.toAnnotationSpec()(#1889). - Fix: Prevent name clashes between a function in class and a function call in current scope (#1850).
- Fix: Fix extension function imports (#1814).
- Fix: Omit implicit modifiers on
FileSpec.scriptBuilder(#1813). - Fix: Fix trailing newline in
PropertySpec(#1827). - Fix:
KSAnnotation.toAnnotationSpecwrites varargs in place instead of making them an array to work around a Kotlin issue with OptIn annotations (#1833). - Fix:
MemberNames without a package are now correctly imported (#1841) - Fix: Throw if primary constructor delegates to other constructors (#1859).
- Fix: Aliased imports with nested class (#1876).
- Fix: Check for error types in
KSType.toClassName()(#1890). - Fix: Support generating a single import for overloaded
MemberNames (#1909).
1.16.0
Thanks to @drawers, @rickclephas for contributing to this release.
- New: Kotlin 1.9.22.
- New: KSP 1.9.22-1.0.16.
- New: Add
NameAllocatorAPI to control keyword pre-allocation (#1803). - Fix: Fix issue with missing suspend modifier in
KSTypeReference.toTypeName(#1793). - Fix: Honour same-package import aliases (#1794).
- Fix: Always include parameter docs in the type header (#1800).