25 KiB
Change Log
Version 1.12.0
2022-06-13
Thanks to @WhosNickDoglio, @sullis, @DRSchlaubi, @martinbonnin, @seriouslyhypersonic, @ephemient, @dkilmer, @aksh1618, @zsqw123, @roihershberg for contributing to this release.
- New: Kotlin 1.7.0.
- New: Add support for context receivers.
- New: Add support for external property getter.
- New:
interop-kspAPI promoted to stable. - Fix: Resolve enum constants when emitting types.
- Fix: Fix type argument mapping when processing typealiases with KSP.
- Fix: Properly unwrap
KSTypeAliaswith an unused type parameter. - Fix: Unwrap nested
KSTypeAlias-es recursively. - Fix: Add support for context receivers
@PropertySpecand fix issues with annotations. - Fix: Treat
headerandimplas keywords (workaround for KT-52315). - Fix: Use
%Ninstead of%Lfor annotation arg names so keywords are handled. - Fix: Improve handling of long
returnexpressions.
Version 1.11.0
2022-03-24
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
UnitandCharSequenceconversions injavapoet-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
valproperty if its getter isinline. - Fix: Add
yieldto the list of reserved keywords. - Fix: Enforce only allowed parameter modifiers in
ParameterSpec(i.e.crossinline,vararg, andnoinline). - Fix: Fix
CodeBlocks in class delegation gettingtoString()'d instead of participating in code writing. - Fix: Error when attempting to convert KSP error types (i.e. if
KSType.isErroris true) toTypeName.
Version 1.10.2
2021-10-22
Thanks to @glureau and @goooler for contributing to this release.
- New: Switch
AnnotationSpec.get()to use thearrayOf()syntax instead of[]. - Fix: Don't wrap aliasing imports with long package names.
- Fix: Don't wrap type names inside line comments.
- Fix: Ignore Java's
@Deprecatedannotations on synthetic methods for annotations.
Version 1.10.1
2021-09-21
Thanks to @evant for contributing to this release.
- Fix: Correct generation of typealiases with type args in KSP interop.
- Fix: Add missing default
TypeParameterResolver.EMPTYargument tofun KSTypeArgument.toTypeNamein KSP interop.
Version 1.10.0
2021-09-20
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
ParameterizedTypeNamewith new type arguments via newcopy()overload. - kotlinx-metadata artifacts have been consolidated to a single
com.squareup:kotlinpoet-metadatamaven artifact. The previouskotlinpoet-metadata-*subartifacts are no longer published. - New:
TypeNameAliasTaghas been moved to KotlinPoet's main artifact underTypeAliasTag, for reuse with KSP interop. ImmutableKm*classes have been removed. They were deemed to be a needless abstraction over the basekotlinx-metadataKm 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-reflectusage. - Avoid using kotlin-reflect for looking up
Unittypes where possible. - Test all the way up to JDK 17.
- Update Kotlin to 1.5.31.
Version 1.9.0
2021-06-22
- New: Kotlin 1.5.10.
- New: Previously deprecated API to interop with Java reflection and Mirror API have been
un-deprecated and marked with
@DelicateKotlinPoetApiannotation. - New:
CodeBlock.Builder.withIndenthelper function. - New: Allow changing initializers and default values in
ParameterSpec.BuilderandPropertySpec.Builderafter they were set. - New:
MemberName.isExtensionproperty that instructs KotlinPoet to always import the member, even if conflicting declarations are present in the same scope. - Fix: Escape member names that only contain underscores.
- Fix: Always emit an empty primary constructor if it was set via
TypeSpec.primaryConstructor.
Version 1.8.0
2021-03-29
- New: Kotlin 1.4.31.
- New: Add
KModifier.VALUEto supportvalue classdeclarations. - New: Allow using a custom
ClassLoaderwithReflectiveClassInspector. - New: Update to kotlinx-metadata 0.2.0.
- Fix: Ensure
ImmutableKmProperty.toMutable()copiesfieldSignature. - Fix: Prevent name clashes between an imported
MemberNameand a member in current scope. - Fix: Prevent name clashes between a type and a supertype with the same name.
- Fix: Don't generate empty body for
expectandexternalfunctions. - Fix: Don't allow
expectorexternalclasses to initialize supertypes. - Fix: Disallow delegate constructor calls in
externalclasses. - Fix: Allow non-public primary constructors inside inline/value classes.
- Fix: Allow init blocks inside inline/value classes.
- Fix: Omit redundant
abstractmodifiers on members inside interfaces
Version 1.7.2
2020-10-20
- New: Detect expression bodies with
return·andthrow·prefixes. - Fix: Omit visibility modifiers on custom accessors.
Version 1.7.1
2020-10-15
- Fix: 1.7.0 was published using JDK 11 which set
"org.gradle.jvm.version"to"11"in Gradle metadata, making it impossible to use the library on earlier Java versions (see #999). 1.7.1 is published with JDK 8, which fixes the problem.
Version 1.7.0
2020-10-14
- New: Kotlin 1.4.10.
- New: Generated code is now compatible with the explicit API mode by default.
- New: Escape soft and modifier keywords, in addition to hard keywords.
- New: Improve enum constants generation for cleaner diffs.
- New: Disallow setters on immutable properties.
- New: Ensure trailing new lines in expression bodies.
- New: Ensure trailing new lines after parameterless custom setters.
- Fix: Don't auto-convert properties with custom accessors to primary constructor properties.
- Fix: Don't allow parameterless setters with body.
- Fix: Prevent auto-wrapping spaces inside escaped keywords.
Version 1.6.0
2020-05-28
-
New: Deprecate Mirror API integrations.
Mirror API integrations, such as
TypeElement.asClassName()andFunSpec.overriding(ExecutableElement), are being deprecated in this release. These KotlinPoet APIs are most often used in annotation processors. Since kapt runs annotation processors over stubs, which are Java files, a lot of the Kotlin-specific information gets lost in translation and cannot be accessed by KotlinPoet through the Mirror API integrations. Examples include:- Alias types, such as
kotlin.String, get converted to their JVM representations, such asjava.lang.String. - Type nullability information is not accessible.
suspendfunctions are seen as simple functions with an additionalContinuationparameter.
The correct solution is to switch to KotlinPoet-metadata or KotlinPoet-metadata-specs API, which fetches Kotlin-specific information from the
@Metadataannotation and produces correct KotlinPoet Specs. We may explore adding new metadata-based alternatives to the deprecated APIs in the future. - Alias types, such as
-
New: Kotlin 1.3.72.
-
New: Improve
MemberNameto support operator overloading. -
New: Support generics in
AnnotationSpec. -
New: Add support for functional interfaces.
-
New: Make more
FunSpec.Buildermembers public for easier mutation. -
Fix: Properly propagate implicit type and function modifiers in nested declarations.
-
Fix: Properly escape type names containing
$character. -
Fix: Don't emit
LambdaTypeNameannotations twice. -
Fix: Preserve tags in
TypeName.copy().
Version 1.5.0
2020-01-09
KotlinPoet now targets JDK8, which means that executing a build that includes KotlinPoet as a dependency on a machine with an older version of JDK installed won't work. This has no effect on the code that KotlinPoet produces: the code can still be compiled against JDK6, as long as it doesn't use any features that were introduced in newer releases.
- New: Kotlin 1.3.61.
- New: Add support for processing FileFacades in KotlinPoet-metadata.
- New: Add support for inner nested and companion objects on annotation classes.
- New: Improve error messages for mismatched open/close statement characters.
- New: Tag
AnnotationSpecs with the annotation mirror when available. - New: Include annotations on enum entries when creating
TypeSpecs from metadata. - Fix: Fix metadata parsing for types.
- Fix: Allow file names that are Kotlin keywords.
- Fix: Properly escape type alias names with backticks.
- Fix: Allow creating
TypeSpecs with names that can be escaped with backticks. - Fix: Properly escape enum constant names with backticks.
- Fix: Maintain proper ordering of properties and initializers when emitting a
TypeSpec. Note: with this change, any properties declared after any initializer blocks will not be added to the primary constructor and will instead be emitted inside theTypeSpecbody. - Fix: Don't emit a leading new line if type KDoc is empty but parameter KDocs are present.
- Fix: Ensure KotlinPoet-metadata resolves package names properly.
Version 1.4.4
2019-11-16
- Fix: Support reified inline types in KotlinPoet-metadata.
Version 1.4.3
2019-10-30
- Fix: Don't emit stubs for abstract functions in KotlinPoet-metadata.
Version 1.4.2
2019-10-28
- Fix: Properly handle abstract elements in KotlinPoet-metadata.
- Fix: Properly handle typealiases in KotlinPoet-metadata.
- Fix: Properly render % symbols at the end of KDocs.
Version 1.4.1
2019-10-18
- New: Add annotations support to
TypeAliasSpec. - New: Read type annotations from Kotlin
Metadata. - New: Introduce
ImmutableKmDeclarationContainer. - Fix: Use full package name for shading
auto-common. - Fix: Support reading self-type variables (e.g.
Asset<A : Asset<A>>) from KotlinMetadata.
Version 1.4.0
2019-09-24
-
New: This release introduces the new KotlinPoet-metadata API that makes it easy to introspect Kotlin types and build KotlinPoet Specs based on that data.
The strategy for type introspection is driven by
ClassInspector, which is a basic interface for looking up JVM information about a given Class. This optionally is used by thetoTypeSpec()/toFileSpec()APIs inkotlinpoet-metadata-specsartifact to inform about Classes with information that isn’t present in metadata (overrides, JVM modifiers, etc). There are two batteries-included implementations available inReflectiveClassInspector(for reflection) andElementsClassInspector(for the javax Elements API in annotation processing). These implementations are available through their respectivekotlinpoet-classinspector-*artifacts. For more information refer to the KotlinPoet-metadata-specs README.At the time of this release the API is in experimental mode and has to be opted into via the
KotlinPoetMetadataPreviewannotation. -
New: Kotlin 1.3.50.
-
New: A new constructor to simplify creation of
ParameterSpecinstances. -
New: New
ClassNameconstructors. -
New:
TypeNameand subclasses can now store tags. -
New: Optional parameters added to
toBuilder()methods of most Specs. -
New:
Listoverrides for Spec methods that acceptvarargs. -
New:
CodeBlock.Builder.clear()helper method. -
New:
FunSpec.Builder.clearBody()helper method. -
Fix: Properly escape enum constant names.
-
Fix: Ensure trailing newlines in KDoc and function bodies.
-
Fix:
TypeVariableNames with empty bounds will now default toAny?. -
Fix: Don't emit parens for primary constructors.
-
Fix:
ClassNames with empty simple names are not allowed anymore. -
Fix: Throw if names contain illegal characters that can't be escaped with backticks.
Version 1.3.0
2019-05-30
- New: Don't inline annotations in the primary constructor.
- New: Force new lines when emitting primary constructors.
- New: Support using MemberNames as arguments to %N.
- New: Add more ClassName constants: ClassName.STRING, ClassName.LIST, etc.
- New: Add ClassName.constructorReference() and MemberName.reference().
- New: Make %N accept MemberNames.
- New: Escape spaces in import aliases.
- New: Escape spaces in ClassNames.
- New: Escape spaces in MemberNames.
- New: Escape imports containing spaces.
- New: Escape package name containing spaces.
- New: Use 2-space indents.
- New: Only indent one level on annotation values.
- Fix: Pass only unique originating elements to Filer.
- Fix: Fix bug with MemberNames in same package nested inside a class.
Version 1.2.0
2019-03-28
- New: Add writeTo(Filer) and originating element API.
- New: Make *Spec types taggable.
- New: Make FunSpec.Builder#addCode take vararg Any?.
- Fix: Import members from default package.
- Fix: Add non-wrapping spaces in control flow creation methods.
- Fix: Named "value" argument being omitted in annotation array types.
Version 1.1.0
2019-02-28
- New: Kotlin 1.3.21.
- New: Support referencing members using
%MandMemberNametype. - New: Add extensions for getting a
MemberNamefrom aClassName,KClassandClass. - New: Allow passing
CodeBlocks as arguments to%P. - New: Allow interface delegation for objects.
- Fix: Don't emit visible whitespace in
toString(). - Fix: Prevent line wrapping in weird places inside function signature.
- Fix: No line wrapping between val and property name.
- Fix: Allow passing line prefix into
LineWrapperto enable proper line wrapping in KDoc. - Fix: Add newline for
TypeSpecKdoc with no tags. - Fix: Add newline for remaining Specs.
- Fix: Fix kdoc formatting for property getter/setters.
- Fix: Don't wrap single line comments inside
FunSpec. - Fix: Add non-wrapping package name.
- Fix: Remove n^2 algorithm in
CodeWriter.resolve()by precomputing all of the nested simple names of aTypeSpec. - Fix: Fix edge case with empty enum classes.
- Fix: Fix Nullable Type Parameter handling in
KType.asTypeName(). - Fix: Fix incorrect long comment wrapping in
FileSpec. - Fix: Attach primary constructor param/property KDoc to the element vs emitting it inside the type header.
Version 1.0.1
2019-01-02
- New: Allow enums without constants.
- New: Improved formatting of TypeSpec KDoc.
- New: Support @property and @param KDoc tags in TypeSpec.
- Fix: Use pre-formatted strings for arguments to %P.
Version 1.0.0
2018-12-10
- New: Kotlin 1.3.11.
- Fix: Prevent wrapping in import statements.
Version 1.0.0-RC3
2018-11-28
- New: Kotlin 1.3.10.
- New: Add
%Pplaceholder for string templates. - New: Add support for receiver kdoc.
- New: Avoid emitting
Unitas return type. - New: Add support for empty setters.
- New: Add checks for inline classes.
- New: Escape property and variable names if keywords.
- New: Replace
%>,%<,%[,%]placeholders with⇥,⇤,«,». - New: Replace
%Wwith space, and add·as a non-breaking space. - New: Change
TypeNameto sealed class. - New: Documentation improvements.
- New: Replace
TypeNamemodifier methods withcopy(). - New: Rename members of
WildcardTypeNameto match with the producer/consumer generics model. - New: Rename
TypeName.nullableintoTypeName.isNullable. - New: Rename
LambdaTypeName.suspendingintoLambdaTypeName.isSuspending. - New: Rename
TypeVariableName.reifiedintoTypeVariableName.isReified. - Fix: Emit star-projection only for types with
Any?upper bound. - Fix: Fold property with escaped name.
Version 1.0.0-RC2
2018-10-22
- New: Kotlin 1.2.71.
- New: README improvements.
- New: Allow opening braces and params in
beginControlFlow(). - New: Add KDoc to
ParameterSpec, collapse into parent KDoc. - New: Support
TypeVariables inPropertySpec. - New: Add parens for annotated types in
LambdaTypeName. - New: Improve error messaging and documentation for inline properties.
- New: Allow sealed classes to declare abstract properties.
- New: Added
buildCodeBlock()helper function. - New: Allow using
CodeBlocks with statements as property initializers and default parameter values. - New: Rename
NameAllocator.clone()into `NameAllocator.copy(). - New: Rename
TypeName.asNonNullable()toTypeName.asNonNull(). - New: Remove
PropertySpec.varBuilder()(usemutable()instead). - New: Allow importing top-level members in default package.
- New: Add overloads to add KDoc to return type.
- Fix: Distinguishing
IntArrayandArray<Int>when creatingTypeName. - Fix: Use
TypeNameinstead ofClassNameas parameter type ofplusParameter(). - Fix: Keep type-parameter variance when constructing
TypeNamefromKType. - Fix: Don't validate modifiers when merging properties with primary constructor parameters.
- Fix: Escape $ characters in formatted strings.
- Fix:
FileSpec.Builderblank package and subfolder fix. - Fix: Append new line at end of parameter KDoc.
- Fix: Add parameter KDoc in
toBuilder().
Version 1.0.0-RC1
2018-07-16
- New: Escape keywords in imports and canonical class names.
- New: Improve
externalsupport. - New: Extensions for
KTypeandKTypeParameter. - New: Add builder methods to simplify adding common kotlin.jvm annotations.
- New: Enums are able to have companion objects.
- New: Add missing primaryConstructor & companionObject to
TypeSpec#toBuilder(). - New: Make subtype checking vals inside Kind public.
- New: Escape (class/property/function/variable) names automatically if they contain space, hyphen, or other symbols.
- New: Improve
ParameterizedTypeNameAPI. - New: Add
WildcardTypeName.STARconstant. - New: Expose mutable builder properties and move their validations to build-time.
- Fix: Use regular indents for parameter lists.
- Fix: Inline annotations on properties defined in primary constructor.
- Fix: Use
Any?as the default type variable bounds. - Fix: Fix importing annotated
TypeName. - Fix: If any primary constructor property has KDoc, put properties on new lines.
- Fix: Properly emit where block in type signature.
- Fix: Avoid type name collisions in primary constructor.
- Fix: Remove implicit
TypeVariablebound when more bounds are added. - Fix: Combine annotations and modifiers from constructor params and properties.
- Fix: Replace delegate constructor args along with the constructor.
Version 0.7.0
2018-02-16
- New: Increase indent to 4 spaces.
- New: Delegate super interfaces as constructor parameters.
- New: Support
PropertySpecs asCodeBlockliterals. - New: Support KDoc for
TypeAliasSpec. - New: Allow for adding an initializer block inside a companion object.
- New: Escape name in
ParameterSpecwhich is also a keyword. - New: Escape names in statements.
- New: Set com.squareup.kotlinpoet as automatic module name.
- New: Support suspending lambda types.
- New: Support named
LambdaTypeNameparameters. - New: Support dynamic type.
- New: Disallow wildcard imports.
- New: Depend on Kotlin 1.2.21.
- Fix: Correct handling of super-classes/interfaces on anonymous classes.
- Fix: Fix boundary filtering to
Any?. - Fix: Wrap long property initializers.
- Fix: Fix formatting and indentation of parameter lists.
Version 0.6.0
2017-11-03
- New: Support lambda extensions.
- New: Support renames in imports like
import bar.Bar as bBar. - New: Support extension and inline properties.
- New: Support reified types.
- New: Expose enclosed types inside
LambdaTypeName. - New: Depend on Kotlin Kotlin 1.1.51.
- New: Improved API and formatting of annotations.
- New: Improved multiplatform support.
- Fix: Escape function and package names if they are a Kotlin keyword.
- Fix: Properly format WildcardTypeName's class declaration.
Version 0.5.0
2017-09-13
- New: Rename
addFun()toaddFunction(). - New: Rename
KotlinFiletoFileSpec. - New: Rename
KotlinFile.addFileAnnotation()toaddAnnotation(). - New: Rename
KotlinFile.addFileComment()toaddComment(). - New: Support cross-platform code, including
HEADERandIMPLmodifiers. - New: Support type variables for type aliases.
- New: Support constructor delegation.
- New: Support named companion objects.
- New: Depend on Kotlin 1.1.4-3.
- Fix: Format one parameter per line when there are more than two parameters.
- Fix: Don't emit braces when the constructor body is empty.
- Fix: Do not invoke superclass constructor when no primary constructor.
- Fix: Enforce the right modifiers on functions.
Version 0.4.0
2017-08-08
- New: Change KotlinPoet's extensions like
asClassName()to be top-level functions. - New: Add declaration-site variance support.
- New: Improve handling of single expression bodies.
- New: Support file annotations.
- New: Support imports from the top-level file.
- New: Accept superclass constructor parameters.
- New: Support primary constructors using the
constructorkeyword. - Fix: Don't emit setter parameter types.
- Fix: Support Kotlin keywords in
NameAllocator. - Fix: Emit the right default parameters for primary constructors.
- Fix: Format annotations properly when used as parameters.
- Fix: Recognize imports when emitting nullable types.
- Fix: Call through to the superclass constructor when superclass has a no-args constructor.
- Fix: Omit class braces if all properties are declared in primary constructor.
- Fix: Don't emit empty class bodies.
- Fix: Emit the right syntax for declaring multiple generic type constraints.
- Fix: Support properties on objects, companions and interfaces.
- Fix: Use
AnnotationSpecfor throws.
Version 0.3.0
2017-06-11
- New: Objects and companion objects.
- New:
TypeAliasSpecto create type aliases. - New:
LambdaTypeNameto create lambda types. - New: Collapse property declarations into constructor params.
- New: Extension and invoke functions for creating type names:
Runnable::class.asClassName(). - New: Basic support for expression bodies.
- New: Basic support for custom accessors.
- New: Remove
Filerwriting and originating elements concept. These stem fromjavacannotation processors. - Fix: Generate valid annotation classes.
- Fix: Use
KModifierfor varargs. - Fix: Use
ParameterizedTypeNamefor array types. - Fix: Extract Kotlin name from
KClassinstead of Java name. - Fix: Emit valid class literals:
Double::classinstead ofDouble.class. - Fix: Emit modifiers in the expected order.
- Fix: Emit the correct syntax for enum classes and overridden members.
Version 0.2.0
2017-05-21
- New: Flip API signatures to be (name, type) instead of (type, name).
- New: Support for nullable types.
- New: Support delegated properties.
- New: Extension functions.
- New: Support top-level properties.
- Fix: Inheritance should use
:instead ofextendsandimplements. - Fix: Make initializerBlock emit
init {}.
Version 0.1.0
2017-05-16
- Initial public release.