Add Kotlin extension functions
mihakrajnc opened this issue · comments
This is a suggestion, it would be handy to have Kotlin extension functions for all Converters.register*
functions.
For example, Converters.registerDateTime(GsonBuilder)
would become:
fun GsonBuilder.registerDateTime(): GsonBuilder {
registerTypeAdapter(DATE_TIME_TYPE, DateTimeConverter())
return this
}
And consequentially, Converters.registerDateTime(new GsonBuilder()).create();
would become:
GsonBuilder().registerDateTime().create()
@mihakrajnc great idea!
Are you able to create a PR that adds Kotlin compilation and these extension functions?
@gkopff Sure thing, I'll try to put it together by the end of the week.
Do you do anything special to compile it now? mvn compile
/ mvn package
? It's been a while since I did Maven :)
It gets published to Maven central via mvn release:prepare
mvn release:perform
, which I assume must do a mvn package
to build the artefacts to upload.
I've used this previously to compile Kotlin:
<build>
<sourceDirectory>src/main/kotlin</sourceDirectory>
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</build>
... But this was in a multi-module Maven project where modules were either Java sources only or Kotlin sources only - never mixed within one module. Note sure if that's significant.
@mihakrajnc Oh, and for the Kotlin source formatting, could we please follow the official Kotlin style guide.
@gkopff Perfect, I think IntelliJ set up something similar when it added Kotlin support automatically, with mixed java / kotlin files. I'll figure out what's needed and what's not, thanks!
For formatting, of course, official style guide. I'm not a monster :)
And I'll just route the extension calls through the Converters class so we don't duplicate the code, and add a test for it that basically does the same thing you do for the Converters class test testRegisterAll
.
P.S. For a moment I thought of naming the Kotlin converters file Konverters.kt
.... but thought better of it :)