Skip to content

Releases: square/kotlinpoet

1.14.1

29 May 15:33
Compare
Choose a tag to compare
  • Fix: Restore ABI stability for annotatable and documentable builders (#1580).

1.14.0

29 May 10:42
Compare
Choose a tag to compare

Thanks to @Omico, @drawers, @RBusarow for contributing to this release.

  • New: Kotlin 1.8.21.

  • New: KSP 1.8.21-1.0.11.

  • New: Enable default methods in Java bytecode (#1561).

  • New: Group Kotlin and Renovate updates together in Renovate (#1562).

  • New: Extract trait interface for annotatable constructs and their builders (#1564).

  • New: Extract trait interface for documentable constructs and their builders (#1571).

  • New: Document the usage of STAR (#1572).

  • New: Add builder for FunSpec which accepts a MemberName (#1574).

  • Fix: Omit public modifier on override function or constructor parameters (#1550).

  • Fix: Correct handling of members in various types (#1558).

  • Fix: Function return types now default to Unit unless explicitly set (#1559).

    Previously the default was null which behaved like Unit for block bodies. When an expression body was produced,
    however, no return type would be emitted. This meant that the return type was implicit based on the contents of
    the body.

    With this change, when no return type is specified and an expression body is produced, the return type will be
    explicitly Unit. Specify the actual return type explicitly to correct the output.

    Old versions:

    val funSpec = FunSpec.builder("foo")
      .addStatement("return 1")
      .build()
    public fun foo() = 1

    This version, incorrect:

    val funSpec = FunSpec.builder("foo")
      .addStatement("return 1")
      .build()
    public fun foo(): Unit = 1 // ❌

    This version, correct:

     val funSpec = FunSpec.builder("foo")
    +  .returns(INT)
       .addStatement("return 1")
       .build()
    public fun foo(): Int = 1 // βœ…

    Additionally, as part of this change, FunSpec.returnType has changed to be non-nullable. This is a source- and
    binary-compatible change, although if you were performing null-checks then new warnings may appear after upgrade.

  • Fix: Append nested class names to alias during name lookup (#1568).

  • Fix: Allow PropertySpec with context receivers and without getter or setter (#1575).

1.13.2

05 May 09:13
Compare
Choose a tag to compare

What's Changed

  • KSType.toTypeName fixed to work with aliased types by @Squiry in #1534

New Contributors

Full Changelog: 1.13.1...1.13.2

1.13.1

28 Apr 11:30
Compare
Choose a tag to compare

What's Changed

  • Fix: Look at canonical names instead of just package names when generating import aliases by @Egorand in #1519
  • Fix: Ignore KSP annotation arguments without a value by @rickclephas in #1523
  • Fix: Fix arguments handling in KSType.toTypeName() by @ZacSweers in #1529

New Contributors

Full Changelog: 1.13.0...1.13.1

1.13.0

06 Apr 07:11
Compare
Choose a tag to compare

What's Changed

  • New: Kotlin 1.8.0.
  • New: KSP 1.8.0-1.0.9.
  • New: Support context receivers on TypeSpecs + extract ContextReceivable API (#1269).
  • New: Optimize OriginatingElements and TagMap implementations (#1270).
  • New: Auto-generate import aliases for types and members (#1355).
  • New: Insert underscores into large decimal literals (#1384).
  • New: New factory function FileSpec.builder(ClassName) (#1397).
  • Fix: Fix StackOverflowError when calling KSTypeArgument.toTypeName() for a wildcard in a recursive type bound (#1272).
  • Fix: Fix transitive aliases (#1306).
  • Fix: Fix Aliases as TypeArgument (#1321).
  • Fix: Don't escape special characters inside raw strings (#1331).
  • Fix: Fix KSP interop's output of the annotation parameter value of type Char (#1338).
  • Fix: Fix KSP interop's output for primitive arrays (#1340).
  • Fix: Avoid emitting public if shouldEmitPublicModifier returns false (#1342).
  • Fix: Fix context receivers being rendered in an incorrect position when on a nullable/suspending LambdaTypeName (#1454).
  • Fix: Do not use bestGuess for KClass.asClassName (#1469).
  • Fix: Handle fake nested types with platform mapped parents (#1472).
  • Fix: Fix TypeName equals (#1477).
  • Fix: Make equals consistent with compareTo for ClassName (#1506).

New Contributors

Full Changelog: 1.12.0...1.13.0

1.12.0

13 Jun 20:09
Compare
Choose a tag to compare

What's Changed

New Contributors

Full Changelog: 1.11.0...1.12.0

1.11.0

24 Mar 18:17
Compare
Choose a tag to compare

Thanks to @liujingxing and @BoD for contributing to this release.

  • New: Kotlin scripting support in FileSpec.

    val spec = FileSpec.scriptBuilder("Taco")
      .addStatement("println(%S)", "hello world!")
      .addKotlinDefaultImports()
      .build()

    Generates a Taco.kts file with the following contents:

    println("hello world!")
  • New: Emit trailing commas for multi-line parameters and annotations.

  • New: Add KSAnnotation.toAnnotationSpec().

  • New: Add Unit and CharSequence conversions in javapoet-interop.

  • New: Add support for default imports in FileSpec.

    • This is particularly oriented at scripting support, but can also be used in non-script files.
  • New: Update to Kotlin 1.6.10.

  • Fix: Fail compilation if you only pass one string to ClassName.

  • Fix: Inline val property if its getter is inline.

  • Fix: Add yield to the list of reserved keywords.

  • Fix: Enforce only allowed parameter modifiers in ParameterSpec (i.e. crossinline, vararg, and noinline).

  • Fix: Fix CodeBlocks in class delegation getting toString()'d instead of participating in code writing.

  • Fix: Error when attempting to convert KSP error types (i.e. if KSType.isError is true) to TypeName.

1.10.2

22 Oct 16:40
Compare
Choose a tag to compare

Thanks to @glureau and @goooler for contributing to this release.

  • [#1175] New: Switch AnnotationSpec.get() to use the arrayOf() syntax instead of [].
  • [#1170] Fix: Don't wrap aliasing imports with long package names.
  • [#1174] Fix: Don't wrap type names inside line comments.
  • [#1167] Fix: Ignore Java's @Deprecated annotations on synthetic methods for annotations.

1.10.1

21 Sep 16:10
Compare
Choose a tag to compare

Thanks to @evant for contributing to this release.

  • Fix: Correct generation of typealiases with type args in KSP interop.
  • Fix: Add missing default TypeParameterResolver.EMPTY argument to fun KSTypeArgument.toTypeName in KSP interop.

1.10.0

20 Sep 17:51
Compare
Choose a tag to compare

Thanks to @martinbonnin, @idanakav, @goooler, and @anandwana001 for contributing to this release.

  • New: Add a new KSP interop artifact. See docs for more details.
  • New: Add a new JavaPoet interop artifact. See docs for more details.
  • New: Allow copying a ParameterizedTypeName with new type arguments via new copy() overload.
  • kotlinx-metadata artifacts have been consolidated to a single com.squareup:kotlinpoet-metadata maven artifact. The previous kotlinpoet-metadata-* subartifacts are no longer published.
  • New: TypeNameAliasTag has been moved to KotlinPoet's main artifact under TypeAliasTag, for reuse with KSP interop.
  • ImmutableKm* classes have been removed. They were deemed to be a needless abstraction over the base kotlinx-metadata Km types. All usages of these should be substituted with their non-immutable base types.
  • Fix: Fix self-referencing type variables in metadata parsing.
  • Fix: Use delicate APIs rather than noisy logging ones when converting annotation mirrors in AnnotationSpec.get.
  • Fix: Update error message when metadata cannot be read to a more actionable one.
  • Fix: Avoid escaping already escaped strings.
  • Add docs about kotlin-reflect usage.
  • Avoid using kotlin-reflect for looking up Unit types where possible.
  • Test all the way up to JDK 17.
  • Update Kotlin to 1.5.31.