Convert Scala source code to Kotlin source code. Optimized for unit test.
If you can use the usual git based package manager (dein, (vim-plug)[https://github.com/junegunn/vim-plug] etc) to install the converter. But you can also just load the converter into your current session:
:source …/autoload/scala2kotlin.vim<CR>"
:source …/plugin/scala2kotlin.vim<CR>"
This is especially useful if converting Scala to Kotlin is a one off effort and you don't want to use the converter all the time.
Note that Scala has a very extensive syntax with many quirks. It's not possible to create an one size fits all conversion. As such the conversion is done in steps.
function scala2kotlin#Convert()
The ScalaConvert
performs the main conversion part. It converts syntax, data type and some common methods.
function scala2kotlin#ConvertScript()
The ScalaConvertScript
performs the main conversion part for ScalaScript. It converts syntax, data type and some
common methods.
function scala2kotlin#Convert_Function_Test()
The ScalaConvertFunctionTest
converts unit test using the org.scalatest.funsuite.AnyFunSuite
unit test framework.
Each function test is converted into method using the back tick notation for the function name. Call `ScalaConvert'
first.
function scala2kotlin#Convert_BDD_Test()
The ScalaConvertBDDTest
converts unit test using the org.scalatest.featurespec.AnyFeatureSpec
and
org.scalatest.GivenWhenThen
unit test framework. Each feature is converted into a nested class and each scenario is
converted into a method. Again using the back tick notation. Call `ScalaConvert'
first.
function scala2kotlin#Replace_Illegal_Method_Character()
Even with …
notation there are few characters which are either forbidden or problematic on windows. The
ScalaReplaceIllegalCharacters
command replaces them with Unicode look alike which are not problematic.
function scala2kotlin#List_Litereal()
Scala lists use ::
and :::
as concatenate command and Nil
to represent literals of lists. The command replaces the
literal with a call to the listOf
method. Select the literal to convert before calling the command.
function scala2kotlin#Multi_Import()
Scala allows multiple imports with one import statement using {…}
notation. This command will replace them with
separate imports. Select the import to convert before calling the command.
Kotlin Script I used as the base for my converter. While I use KotlinScript was well VimScript is so much more powerful when it comes to transforming text.
Not compatible with «IntelliJ IDEA 2023.2.5» or «Android Studio 2022.3.1» and as such not very useful. You would need to install a very old IDEA to use it.
Commercial online converter. Won't convert Scala based DSL which includes most unit and instrumentations tests. For larger projects you will have to pay eventually.